Question
Hey guys, could use some help on a Java ArrayList Assignment, a good bulk of the code is done, but need some help as to
Hey guys, could use some help on a Java ArrayList Assignment, a good bulk of the code is done, but need some help as to flushing out the methods, and the rest of my code shouldnt be altered. A requirement is that no static attributes are to be created in the classes, but local variables can be created in the methods. The requirements are in the comments before each method as well. My code is a follows. Thanks
--------TheatreMain Class----------
package theatre;
import java.util.ArrayList; import java.util.Scanner;
/** * This program will track ticket sales for a Theatre. */ public class TheatreMain {
private static final String MENU = "------------------------- " + "- Theatre " + "- A-Purchase a ticket " + "- B-Show all regular tickets " + "- C-Show all premium tickets " + "- D-Find a ticket by name and show ticket details " + "- E-Show summary " + "- X-eXit " + "------------------------- " + "Option-->";
public static void main(String[] args) { ArrayList
//Data for testing. addTestData(tickets);
String option; do { option = getMenuOption(MENU); processMenuOption(option, tickets); } while (!option.equalsIgnoreCase("X")); }
/** * This method will process the menu option specified in the input * parameter. It will call appropriate functionality based on its value. */ public static void processMenuOption(String option, ArrayList
switch (option) { case "A": purchaseATicket(tickets); break; case "B": showAllRegularTickets(tickets); break; case "C": showAllPremiumTickets(tickets); break; case "D": findTicketByName(tickets); break; case "E": showSummary(tickets); break; case "X": break; default: System.out.println("Invalid entry"); } }
/** * This method will add a ticket to the tickets ArrayList. */ private static void purchaseATicket(ArrayList
}
/** * This method will show any regular tickets in the input tickets ArrayList. */ private static void showAllRegularTickets(ArrayList
/** * This method will show any premium tickets in the input tickets ArrayList. */ private static void showAllPremiumTickets(ArrayList
/** * This method will ask the user for the name and find any tickets in the * list that match that name. */ private static void findTicketByName(ArrayList
/** * This method will show a summary. It must show the following details: * Regular tickets: # <-- # of regular tickets sold Premium tickets: # <-- # * of premium tickets sold Total Revenue: $ <-- Total revenue of regular and * premium tickets Names: ... <-- List of names of ticket holders. Note that * one name could buy more than one ticket. Do not expect to see the name * twice! So only show the distinct set of ticket names! */ private static void showSummary(ArrayList
/** * This method will prompt the user based on the string passed in and return * their option */ public static String getMenuOption(String menu) { System.out.print(MENU); Scanner input = new Scanner(System.in); String option = input.nextLine(); option = option.toUpperCase(); return option; }
//Test data private static void addTestData(ArrayList
------------Ticket Class-----------
package theatre;
import java.util.Scanner;
/** * This class will represent tickets sold by the theatre. */ public class Ticket {
public static final double[] PRICES = {10.0, 15.5}; public static final String[] CATEGORIES = {"REGULAR", "PREMIUM"}; public static final int CATEGORY_REGULAR = 1; public static final int CATEGORY_PREMIUM = 2; private static int max;
private int type; private String name; private int ticketNumber;
private static Scanner input = new Scanner(System.in);
public Ticket() { this.ticketNumber = max++; System.out.print("Name-->"); this.name = input.nextLine(); System.out.println("Type (1=Regular 2=Premium)"); this.type = input.nextInt(); input.nextLine(); }
public Ticket(int type, String name) { this.type = type; this.name = name; this.ticketNumber = max++; }
public int getType() { return type; }
public void setType(int type) { this.type = type; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
/** * This will return the cost associated with this ticket's type. */ public double getCost() { return PRICES[type - 1]; }
@Override public String toString() { return "Ticket#" + ticketNumber + " Name: " + name + " Type: " + CATEGORIES[type - 1]; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started