C++ only, I will not award points if the code is given in Java, C++ only. All cl
ID: 644089 • Letter: C
Question
C++ only, I will not award points if the code is given in Java, C++ only.
All classes must go into a separate header file with includes guards. You may write the functions inline or in a separate source file.
Part 1: Open a Theater
Write a class, Theater, that has 3 public methods:void setMovies(char ** movies, int size)
This method will allow you to set the movies field for the class
void setShowings(double * showtimes, in size)
This method will allow you to set the showtimes field of the class
void printShowtimes()
This method will print out the theater name showtime listing and the movies
Your class must also have the following private attributes:
char ** movies
double * showtimes
int num_movies
int num_showtimes
Part 2: Creating and Initializing Objects
In your main(), you will need to create two seperate Theater objects, amc and regal.
You will set movie and showtime fields for each object with different movies and times (your choice of movies and times).
Then print the showtimes by calling the object's printShowtimes method
Explanation / Answer
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; import java.util.StringTokenizer; public class TicketSales { /** * @param theatres * */ public ArrayList theatres = new ArrayList(); /** * @param movies * */ public ArrayList movies = new ArrayList(); /** * @param shows * */ public ArrayList shows = new ArrayList(); /** * @param prices * */ public ArrayList prices = new ArrayList(); /** * @param possibleOrders * */ public ArrayList possibleOrders = new ArrayList(); /** * @param orders * */ public ArrayList orders = new ArrayList(); /** * @param mReport * */ public ArrayList mReport = new ArrayList(); /** * currentMovie */ public String currentMovie = ""; /** * salePrice */ public int salePrice = 0; /** * currentShow */ public int currentShow = 0; /** * * @param args String[] */ public static void main(String[] args) { TicketSales ts = new TicketSales(); ts.console(); } /** * console */ public void console() { BufferedReader userInput = new BufferedReader(new InputStreamReader( System.in)); String s = "temp"; try { while (((s != null) && (s.length() > 0)) && (!s.equals("no"))) { System.out.println(" Welcome To Cinema Management Home " + "Please type a valid command and hit [Enter] " + "init - Initialize the Cinema " + "order - Create an order " + "manage - Print the manager report " + "sales - Report sales " + "log - Print log " + "report"); s = userInput.readLine().toLowerCase(); if (s.equals("init")) { while ((s != null) && (s.length() > 0)) { System.out .println(" You've chosen to initialize the cinema " + "Please type your desired method of entry " + "and hit [Enter] " + "hand - Initialize the Theatre manually " + "file - Initialize the Theatre from a file"); s = userInput.readLine().toLowerCase(); if (s.equals("hand")) { initCinema(); console(); } else if (s.equals("file")) { System.out .println(" Type the name of the file " + "you want to input"); s = userInput.readLine(); initCinema(s); console(); } } } else if (s.equals("order")) { while ((s != null) && (s.length() > 0)) { System.out .println(" Type desired order entry method and " + "hit [Enter] " + "hand - Create the order manually " + "file - Create the order from a file"); s = userInput.readLine().toLowerCase(); if (s.equals("hand")) { processOrders(); break; } else if (s.equals("file")) { System.out .println(" Type the name of the file you " + "want to input"); s = userInput.readLine(); processOrders(s); console(); } } } else if (s.equals("sales")) { System.out.println(reportSales()); console(); } } } catch (IOException e) { System.out.println("Error"); } } /** * initCinema * * @param filename * String * */ void initCinema(String filename) { try { File doc = new File(filename); Scanner s = new Scanner(doc); if (s.hasNext("Movies")) { s.nextLine(); while (!s.hasNext("Theaters")) { movieHelper(s.nextLine()); } // create all of the theatres } if (s.hasNext("Theaters")) { s.nextLine(); while (!s.hasNext("Shows")) { theatreHelper(s.nextLine()); } // create all of the shows } if (s.hasNext("Shows")) { s.nextLine(); while (!s.hasNext("Prices")) { showHelper(s.nextLine()); } // create all of the prices } if (s.hasNext("Prices")) { s.nextLine(); while (!s.hasNext("End")) { priceHelper(s.nextLine()); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * initCinema */ public void initCinema() { BufferedReader userInput = new BufferedReader(new InputStreamReader( System.in)); String s = "temp"; String d = "temp"; try { while (((s != null) && (s.length() > 0)) && (!s.equals("no"))) { System.out.println(" Welcome To Cinema Initializer " + "Please type a valid command and hit [Enter] " + "movie - Create a movie " + "theatre - Create a new theatre " + "show - Create a new show " + "price - Create prices " + "return - Return to Cinema Management Home"); s = userInput.readLine().toLowerCase(); if (s.equals("movie")) { while ((s != null) && (s.length() > 0)) { System.out.println(" Please enter the movie name"); s = userInput.readLine(); if ((s != null) && (s.length() > 0)) { System.out .println(" Please enter the movie duration"); d = userInput.readLine(); int di = Integer.parseInt(d); if ((s != null) && (s.length() > 0)) { System.out .println(" Movie Successfully added"); manuallyMakeMovie(s, di); initCinema(); } } } } if (s.equals("theatre")) { while ((s != null) && (s.length() > 0)) { System.out.println(" Please enter the theatre name"); s = userInput.readLine(); if ((s != null) && (s.length() > 0)) { System.out .println(" Please enter the theatre capacity"); d = userInput.readLine(); int di = Integer.parseInt(d); if ((s != null) && (s.length() > 0)) { System.out .println(" Theatre Successfully added"); manuallyMakeTheatre(s, di); initCinema(); } } } } if (s.equals("show")) { initShow(); initCinema(); } if (s.equals("price")) { while ((s != null) && (s.length() > 0)) { System.out.println(" Please enter the adult price"); s = userInput.readLine(); int ai = Integer.parseInt(s); if ((s != null) && (s.length() > 0)) { System.out .println(" Please enter the child price"); s = userInput.readLine(); int ci = Integer.parseInt(s); if ((s != null) && (s.length() > 0)) { System.out .println(" Please enter the senior price"); s = userInput.readLine(); int si = Integer.parseInt(s); if ((s != null) && (s.length() > 0)) { if (this.prices.size() != 0) { this.prices.get(0).amount = ai; this.prices.get(1).amount = ci; this.prices.get(2).amount = si; System.out .println(" Prices successfully " + "updated"); initCinema(); } else { manuallyAddPrices(ai, ci, si); System.out .println(" Prices successfully " + "updated"); initCinema(); } } } } } } if (s.equals("return")) { console(); } } } catch (IOException e) { System.out.println("Error"); } } // ////////////////////////////////////////////////////////////////// // helpers for manually initializing cinema /** * initCinema */ public void initShow() { BufferedReader userInput = new BufferedReader(new InputStreamReader( System.in)); String s = "temp"; Movie m = new Movie("", 0); Theatre t = new Theatre("", 0, 0); try { while ((s != null) && (s.length() > 0)) { System.out.println(" Please enter the name of the movie"); s = userInput.readLine(); if ((s != null) && (s.length() > 0)) { m.name = s; m.duration = findDuration(s); } if ((s != null) && (s.length() > 0)) { System.out .println(" Please enter the name of the theatre"); s = userInput.readLine(); t.name = s; t.capacity = findCapacity(s); } if ((s != null) && (s.length() > 0)) { System.out.println(" Please enter the showtime"); s = userInput.readLine(); int i = Integer.parseInt(s); if ((s != null) && (s.length() > 0)) { if (validShowtime(i)) { this.shows.add(new Show(m, t, i)); } else { // updateLog System.out.println("invalid Showtime"); initShow(); } } } System.out.println("Showtime Successfully added"); initCinema(); } } catch (IOException e) { System.out.println("Error"); } } /** * manually add prices * * @param ai * int * @param ci * int * @param si * int */ public void manuallyAddPrices(int ai, int ci, int si) { prices.add(new Price("adult", ai)); prices.add(new Price("child", ci)); prices.add(new Price("senior", si)); } /** * * @param i * int * @return boolean */ public boolean validShowtime(int i) { return true; } /** * * @param s * String * @return int */ public int findCapacity(String s) { int temp = 0; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.