Java please help I am very confused on how to complete this

Java please help, I am very confused on how to complete this assignment since our professor barely covered it and I lack prior coding experience.

In order to receive full credit for this assignment, you must use the appropriate Java API classes and methods to trim the input string, to do the extraction of the category character, extraction of the substrings, conversion of substrings of digits to numeric values as appropriate, and formatting. These include the String methods trim, charAt, and substring, as well as wrapper class method Double.parseDouble which can be used to convert a String of digits into a numeric value. The dollar amounts should be formatted so that both small and large amounts are displayed properly, and the prize number should be formatted so that six digits are displayed including leading zeroes, if needed, as shown in the examples above. It is recommended as a practice that you not modify input values once they are stored. While not a requirement, you should consider making the student discount and child discount constants. For example, the following statements could be placed above the main method. static final double STUDENT_DISCOUNT = .25; static final double CHILD_DISCOUNT = .35;

SpaceTicket java Requirements: The purpose of this program is to accept coded space ticket information as input that includes the ticket price, category, time, date, and seat, followed by the description ofthe travel. Note that the eight digits for price have an implied decimal point. The program should then print the ticket infomation including the actual cost, which is the price with discount applied as appropriate: 25% for a student ticket (e), 35% for child ticket (c), and none for regular tickets The last line ofthe ticket should contain a \"prize number between and 999999 inclusive that should always be printed as 6 digits (e.g11 should be primted as 00000 The coded input is formatted as follows: 12579500 a1530070120981. 7DSpaceX-001 Earth to Mara ticket description (goes through last character in the code) category c, or anything else is are ticket with no discount, store this as type char] gular price [12511500 has an implied decimal point for 125795.00] Whitespace (e.g., spaces or tabs) before or after the coded imfommation should be disregarded. Hint. After the ticket code has been read in as a String, it should be trimmed- our program will need to print the ticket description, the date and time, seat, the ticket price, the ticket category, the actual cost, and a random prize number in the range l to 999999. If the user enters a code that does not have atleast 25 characters, then an error message should be printed. [The 25 character of the code is part ofthe ticket description.] Design: Several examples of input/output for the program are shown below. Line Program output Note that the ticket code below results in the indicated output except for the prize number which is random. When more than one item is showm on the same line (e.g., date, time, and seat on line 4), there are three ages between them (do not use the tab escape sequence Line Program output DSpace -001 Earth Ticket: Spscek-001. 07/0 $125 Category $125. Page 3 of 5 Project: Using Java API Classes Page 4 of 5 Line Program output Dsp spa Ticket: Spscek-001. 07/0 $125.79! Category N,346-2! Note that the ticket code below has five leading spaces (be sure you are trimming the input code). Line Program output spa Ticket: Spscek-001. 07/0 $125.79! Category $81,756

Solution

Hi buddy, please find the below java program. I\'ve added comments for your better understanding

import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

/**
*
* @author PrudhviNIT
*/
public class SpaceTicket {

/**
* @param args the command line arguments
*/
static final double STUDENT_DISCOUNT = .25d;
static final double CHILD_DISCOUNT = .35d;

public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine().trim();
//If the length is less than 25, print \"Invalid ticket code\"
if (str.length() < 25) {
System.out.println(\"*** Invalid Ticket Code ***\");
System.out.println(\"Ticket code must have atleast 25 characters\");
return;
}
//This loop is finding the position of the \'.\'
int pos = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= \'a\' && str.charAt(i) <= \'z\') {
pos = i;
break;
}
}
//Parsing the price. The string that is to the left of the dot
String price = str.substring(0, pos);
//Parsing the category. The character at the dot
String cat = str.charAt(pos) + \"\";
//Initializing the cost with price. Later discount will be substracted from cost , if any
String cost = price;
//adjusting the decimal point.
cost = Double.toString(Double.parseDouble(cost) / 100d);
//Applying the discount.
if (cat.equals(\"s\")) {
cost = Double.toString(Double.parseDouble(price) / 100d * (1 - STUDENT_DISCOUNT));
} else if (cat.equals(\"c\")) {
cost = Double.toString(Double.parseDouble(price) / 100d * (1 - CHILD_DISCOUNT));
}
//Parsing time,date, seat and desc
String time = str.substring(pos + 1, pos + 5);
String date = str.substring(pos + 5, pos + 13);
String seat = str.substring(pos + 13, pos + 16);
String desc = str.substring(pos + 16);
System.out.println(\"Space Ticket: \" + desc);
System.out.println(\"Date \" + date.substring(0, 2) + \"/\" + date.substring(2, 4) + \"/\" + date.substring(4) + \" Time \" + time.substring(0, 2) + \":\" + time.substring(2) + \" Seat \" + seat);
//Creating the format
DecimalFormat p = new DecimalFormat(\"###,###.00##\");
System.out.println(\"Price : $\" + p.format(Double.parseDouble(price) / 100) + \" Category : \" + cat + \" Cost : $\" + p.format(Double.parseDouble(cost)));
//Creating the random number
int random = new Random().nextInt(999999) + 1;
String r = random + \"\";
//Appending zeros in the beginning
while (r.length() < 6) {
r = \"0\" + r;
}
System.out.println(\"Prize number \" + r);
}
}

Java please help, I am very confused on how to complete this assignment since our professor barely covered it and I lack prior coding experience. In order to re
Java please help, I am very confused on how to complete this assignment since our professor barely covered it and I lack prior coding experience. In order to re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site