Question: I need help with my code in Java. I am not good with arrays and just need a base step to understand. I know what
I need help with my code in Java. I am not good with arrays and just need a base step to understand. I know what I am supposed to do but the problem is writing it correctly.
exception with trying and catch blocks and taking a data file reading it storing the information and testing exceptions.
I have bolded the area that I need a little bit of help on and understanding
/**
* Reads in ticket sales data and provides a summary of the sales data
*
* @author TODO
*/
public class TicketProcessing {
private ArrayList
private double totalRevenue; // Total money earned from tickets sold
// add other fields as necessary
// constants for minimum and maximum values for
// zones and boxes.
// Just in case we build a bigger theater later
private final int MIN_ZONE = 10;
private final int MAX_ZONE = 20;
private final int MIN_BOX = 1;
private final int MAX_BOX = 8;
/**
* Constructor - reads data from filename
* Stores ticket data
* @param filename - file of ticket sale data to process
*/
public TicketProcessing(String filename) throws FileNotFoundException{
// Initialize all attributes
tickets = new ArrayList
totalRevenue = 0;
// call readTicketData to populate tickets
readTicketData(filename);
// Do not catch any exceptions here
}
/**
* Reads a new ticket sales file. If data has already been read
* in, calling this method will clear all previous ticket and
* revenue data
*
* @param filename - file of ticket sale data to process
* @throws InvalidDateException, NoSuchLocationException, FileNotFoundException, IllegalArgumentException
*/
public void readTicketData(String filename) throws FileNotFoundException{
// TODO
// use a Scanner to read the ticket data
Scanner fileScan = new Scanner(new File(filename));
// Clear tickets and reset revenue values
tickets.clear();
totalRevenue = 0;
// Process file
// while(fileScan.hasNext(){ ...
// parse event date
// read name
try{
// parse zone/box number
}catch(parseException e){
throw new InvalidDateException("unable to parse date");
}
// Create a ticket object and add it to tickets How do you
// know whether to create a VIPTicket or a FloorTicket?
// Check the zone/box number
// Update revenue
// Close the file
fileScan.close();
// If file was empty, throw IllegalArgumentException
if(tickets.size() == 0)
throw new IllegalArgumentException("Datafile is missing information");
}
/**
* Return number tickets sold
*/
public int totalTicketsSold(){
return tickets.size();
}
/**
* Return total revenue
*/
public double getTotalRevenue(){
return totalRevenue;
}
/**
* Return total revenue for specific type of event
*
* Example: if whichEventType is TicketInterface.Event.SPORT,
* return the revenue generated by only the SPORT tickets
*
* @param whichEventType - the type of event for which to calculate the revenue
*/
public double getRevenue(TicketInterface.Event whichEventType){
// TODO
// note using the enum cuts down on errors - parameter has to
// be one of the correct Event types because the compiler
// enforces that you use a correct Event type
return 0;
}
/**
* Return a string with sales data in the following format
* (zeroes to be replaced with actual values)
*
* Total number of tickets sold: $0.00
* Total Revenue: $0.00
* Total Sports Revenue: $0.00
* Total Performance Revenue: $0.00
* Total Concert Revenue: $0.00
*/
public String toString(){
DecimalFormat fmt = new DecimalFormat("0.00");
String res = "Total number of tickets sold: " + tickets.size();
res += " Total Revenue: $" + fmt.format(totalRevenue);
res += " Total Sports Revenue: $" + fmt.format(getRevenue(TicketInterface.Event.SPORT));
res += " Total Performance Revenue: $" + fmt.format(getRevenue(TicketInterface.Event.PERFORMANCE));
res += " Total Concert Revenue: $" + fmt.format(getRevenue(TicketInterface.Event.CONCERT));
return res;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
