For this programming assignment, you are going to create a Ticket class that rep
ID: 3703395 • Letter: F
Question
For this programming assignment, you are going to create a Ticket class that represents a Ticket for train travels from Chicago’s Union Station to other cities. You will also create a Reservation class that will contain an array or collection of Ticket objects. Lastly, you will create a ReservationApp that manages train ticket sold.
Import the files:
Your first step will be to import the class file DataReader.java into your program 4 solution folder. You will also import the input data file, TicketData.txt, that have been provided for your programming assignment.
DataReader class
This class will be used to read an input file that has information for tickets already sold. The methods in this class are all static methods and should therefore be called in a static way. The ticketCount field stores the number of tickets already sold, and it also represents the number of Ticket objects stored in the Ticket array after the input file has been read.
Input data format (FYI only):
<reservation number>
<first name>
<last name>
<destination city>
<price> <credit card number> <credit card expiration date> <credit card security code>
NOTE: Look at this class and see what it does.
Ticket class
Keeps track of the information for a ticket sold. This class should include the following:
Instance or class level fields
A field for first name
A field for last name
A field for reservation number
A field for destination city. Valid values for this field: Peoria, Normal, Joliet, Indianapolis, and St. Louis.
A field for credit card number
A field for credit card expiration date (format for date is mm/yyyy)
A field for credit card security code (number in the back of credit card number)
A field for price of the ticket
Methods
Constructor that accepts values for all instance fields
Getters for all instance fields
Setter for destination city and price
toString that formats ticket data as follows:
Klaus III, Mitchell Reservation number: 25532
Destination: INDIANAPOLIS Cost: $27.00
Credit card: xxxx-xxxx-xxxx-7777
Reservation class (will use aggregation)
The Reservation class will contain an array or collection of Ticket objects.
Instance or class level fields
An array of Ticket objects
A field for number of Ticket objects in the array
MethodsA default constructor.
DataReader class will be called from the default constructor.
Ticket array will get a reference to a partially filled array from method in DataReader that reads the input file into Ticket objects.
Set the count field with the value returned from the getter of the ticket count field in DataReader.
Getters for ticket count
A method to add a Ticket object to the array. This method accepts a Ticket object that will be added to the array.
A method that checks if there are still seats left on the plane by checking if there is room in the array to add another Ticket object. (Hint: which field and which attribute do you need to compare?)
A method to update a Ticket object. This method accepts reservation number and destination city (the only field that can be updated). The destination will be updated and the price will be updated using the value returned by the method that returns the price. If the reservation number is not found, display a message “Reservation number entered is not found.” Display the ticket information after a successful update.
A method that accepts the destination city and returns the price of the ticket. City and prices are as follows:
Peoria = $8.50
Normal = $12.75
Joliet = $9.77
Indianapolis = $24.25
St. Louis = $34
A method that accepts the reservation number and displays the information for the ticket with reservation number. If the reservation number is not found, display a message “Reservation number entered is not found.”
A method that displays the information for all the tickets in the array.
A private method that accepts the reservation number and searches the array for the Ticket object with the reservation number. This method returns the index of the Ticket object with the reservation number. Otherwise, it returns a -1.
ReservationApp class
This is the starting point for the application, which is the only class to contain a main method.
This will drive the menu driven application with the following menu options:
1 – Buy a ticket
2 – Update a ticket
3 – Display ticket information
4 – Display all ticket information
5 – Quit
Options
Option 1 – ask all the information needed for buying a ticket and add the Ticket object to the array. For reservation number, use the Random class to generate a random number with 5 digits and add ‘C’ in front, ex. C12333.
Option 2 – ask the user for the destination and the reservation number. Update the appropriate Ticket object in the array.
Option 3 – Ask the user for the reservation number and display the information for the ticket with the reservation number
Option 4 – display the information for all the tickets
Option 5 – terminate
Display the menu every time a menu selection has been processed, whether valid or invalid menu choice is selected.
Required validation to be done
Validate the menu option entered. Display the message “Invalid menu choice. Please select again.” Re-display the menu and ask the user again to select an option.
Validate the credit card number entered and make sure that there are 16 digits. If not 16 digits, display message “Invalid credit card number.” and ask the user to enter another credit card number. Keep asking the user for new credit card number as long as entered value is invalid.
Here is DataReader.java
Here is TicketData.txt
Explanation / Answer
i have provide better solution of your question.it is easy to understand
Ticket Class :contation info of ticket ;
DataProvide :provide info of sold ticket ;
reserve class :its reserve the ticket
Reservation class contains main method.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
class Ticket
{
String first_name;
String last_name;
double reservation_number;
String destination_city;
double credit_card_number;
Date expiration_date;
int security__code;
double price;
/**
* @param first_name
* @param last_name
* @param reservation_number
* @param destination_city
* @param credit_card_number
* @param expiration_date
* @param security__code
* @param price
*/
public Ticket()
{
}
public Ticket(String first_name, String last_name, double reservation_number, String destination_city,
double credit_card_number, Date expiration_date, int security__code, double price) {
super();
this.first_name = first_name;
this.last_name = last_name;
this.reservation_number = reservation_number;
this.destination_city = destination_city;
this.credit_card_number = credit_card_number;
this.expiration_date = expiration_date;
this.security__code = security__code;
this.price = price;
}
void DisplayTicket()
{
System.out.println(""+first_name+""+last_name+""+reservation_number+""+destination_city);
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public double getReservation_number() {
return reservation_number;
}
public void setReservation_number(double reservation_number) {
this.reservation_number = reservation_number;
}
public String getDestination_city() {
return destination_city;
}
public void setDestination_city(String destination_city) {
this.destination_city = destination_city;
}
public double getCredit_card_number() {
return credit_card_number;
}
public void setCredit_card_number(double credit_card_number) {
this.credit_card_number = credit_card_number;
}
public Date getExpiration_date() {
return expiration_date;
}
public void setExpiration_date(Date expiration_date) {
this.expiration_date = expiration_date;
}
public int getSecurity__code() {
return security__code;
}
public void setSecurity__code(int security__code) {
this.security__code = security__code;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class DataReader
{
double reservation_number;
String first_name;
String last_name;
String destination_city;
double price;
double card_number;
Date expiration_date;
int security_code;
ArrayList<Double> NumTicket=new ArrayList<Double>();
public int TicketCount()
{
int size=this.NumTicket.size();
return size;
}
public void addTicket(double PNR)
{
NumTicket.add(PNR);
}
}
class Reservation
{
Ticket ticket[];
DataReader datareader;
public void addTicket(double PNR)
{
datareader.NumTicket.add(PNR);
}
}
public class ReservationApp{
Ticket ticket2;
Ticket ticket;
public ReservationApp()
{
// TODO Auto-generated constructor stub
}
public static void main(String[] args)throws IOException
{
Ticket ticket2;
Ticket ticket;
System.out.println("1 – Buy a ticket " +
" " +
"2 – Update a ticket " +
" " +
"3 – Display ticket information " +
" " +
"4 – Display all ticket information " +
" " +
"5 – Quit");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int option =Integer.parseInt(br.readLine());
switch(option)
{
case 1:
ticket=new Ticket();
System.out.println("Enter First name ");
ticket.setFirst_name(br.readLine());
System.out.println("Enter data last name ");
ticket.setLast_name(br.readLine());
System.out.println("Enter credit card num ");
ticket.setCredit_card_number(Double.parseDouble(br.readLine()));
System.out.println("Enter security code ");
ticket.setSecurity__code(Integer.parseInt(br.readLine()));
break;
case 2:
ticket2=new Ticket();
System.out.println("Enter First name ");
ticket2.setFirst_name(br.readLine());
System.out.println("Enter data last name ");
ticket2.setLast_name(br.readLine());
System.out.println("Enter credit card num ");
ticket2.setCredit_card_number(Double.parseDouble(br.readLine()));
System.out.println("Enter security code ");
ticket2.setSecurity__code(Integer.parseInt(br.readLine()));
break;
case 3 :
System.out.println("enter the ticket number");
int number=Integer.parseInt(br.readLine());
}
// TODO Auto-generated method stub
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.