SlideShare a Scribd company logo
1 of 9
Download to read offline
Objectives: Create a Java program using programming fundamentals (file I/O, loops, conditional
statements, arrays, functions) Problem: In preparation for the release of Guardians of the Galaxy
2, you have been hired by the owner of a small movie theater to develop the backend for an
online ticket reservation system. Patrons will be able to reserve seats in one of three auditoriums.
Once the patron has selected an auditorium, the program should display the current seating
arrangement and allow the patron to select seats. A report should be generated at the end of the
program to specify for each individual auditorium and overall for all auditoriums how many
seats were sold/unsold and how much money was earned.
Details
The seating arrangement for each auditorium will be stored in separate files. These files will be
named A1.txt, A2.txt, and A3.txt for auditorium 1, 2 and 3 respectively.
Each line in the file will represent a row in the auditorium. The number of rows in each
auditorium is unknown to you.
The number of seats in each row of a single auditorium will be the same. For example, if the
first line of the file has 15 seats, then every subsequent row in the theater will also have 15 seats.
This does not mean that each auditorium has the same number of seats in each row. One
auditorium may have 15 seats per row and another may have 20 seats.
Each auditorium will be held in a two-dimensional array.
Empty seats are represented by a pound sign (#).
Reserved seats are represented by a period (.).
Tickets can only be reserved the day of the screening and all screenings are at 7 PM that night.
There is no need to worry about multiple screenings or reserving seats on a specific day.
All tickets are $7 regardless of patron age or auditorium. User Interface and Input: Present a
user-friendly menu system for the user to select the auditorium. First, ask for the auditorium:
1. Auditorium 1
2. Auditorium 2
3. Auditorium 3
4. Exit
Although in reality the user would likely only make one purchase, for testing purposes, assume
the user will repeat the ticket buying process until they decide to quit.
Once the auditorium has been selected, display the current seating availability for that
auditorium. An example seating chart is provided below for an auditorium with 5 rows and 20
seats per row.
The seats are numbered sequentially from left to right and only the one's digit is displayed above
each column to make it easier to display the chart. It is understood that the second set of digits
from 1-0 are for the numbers 11- 20 in the above example. After the user has selected the
auditorium and the seating chart has been displayed, prompt the user for the following
information in the order below:
Row number
Starting seat number
Number of tickets
Assume that the user wants to reserve sequential seats to the right of the first seat entered. If the
desired seats are not available, offer the user the best available seats that meet their criteria on
that row only. The best available seats are the seats closest to the middle of the row.
Prompt the user to enter a Y to reserve the best available or N to refuse the best available. Once
the selection has been processed, return to the main menu. All input will be of the valid data
type. You do not have to worry about the user entering a letter when a number is expected or a
floating point number when an integer is expected. You are responsible for validating that the
data falls within the proper range and that a user does not try to reserve a seat that is already
reserved. Output: At the end of the program, write the current status of each auditorium to the
respective file. Also, display a formatted report to the console. The report should consist of 4
columns:
Column 1 – labels
o Auditorium 1
o Auditorium 2
o Auditorium 3
o Total
Column 2 - number of seats reserved for each label
Column 3 - the number of open seats for each label
Column 4 - the total of the ticket sales for each label
Here is the Pseudocode I have made and verified by the professor.
Read Auditorium
Arguments: auditorium array
Returns: auditorium array
Open file
While not EOF
o Read line
o For 0 to line length
Copy character in string to array
Close file
Display Auditorium
Arguments: auditorium array
Returns: nothing
Display column header
For each row
o Display row number
o For each column
Display array[row][col]
o Display newline
Reserve Seats
Arguments: auditorium array, row, seat, quantity
Returns: nothing
For 1 to quantity
o Array[row][seat+i] = #
Check Availability
Arguments: auditorium array, row, seat, quantity
Returns: Boolean
For 1 to quantity
o If array[row][seat+i] is a period
Return false
Return true
Count Seats
Arguments: auditorium array
Returns: open seats and reserved seats
Open file based on auditorium
For each row o For each column
If array[row][col] = #
Increment open seats
Else increment reserved seats
Print Report
Arguments: none
Returns: none
For 1 to 3
o Call Get Seat Info function
o Print out open seats, reserved seats, money earned
o Increment total open seats, total reserved seats, total money earned
Print out total open seats, total reserved seats, total money earned
Best Available
Arguments: auditorium array, row, quantity
Returns: left endpoint of best available section
Determine middle of row
From mid to 1 (i) o If array[row][i] = #
For 1 to quantity (j)
Check if array[row][i-j] = #
If all available
Left side = Hold i
From mid to last column (i) o If array[row][i] = #
For 1 to quantity (j)
Check if array[row][i+j] = #
If all available
Right side = Hold i
Return min (right side, left side - quantity)
Main
Loop (do…while not exit)
o Print main menu
o Get user input
o If user does not want to exit
Print auditorium
Get auditorium number
If user wants to reserve seats
Ask user for row, seat, and quantity
Check if seats are available
If available reserve seats
If not available search for best available
o If best available, offer to user
If user wants to see auditorium
Call display auditorium function
Print report
9 *# *## 5 .# .# 4 .# --# 3 .# -## 2# ---# # -### 0# -# -# 8## . .# 7 .# -## 6 -# --# 5## -## 4## . .#
3 .# -## 2 -# --# 1 .# -## 12345
Solution
Here is the full solution to the problem. Note that it has two classes: Audotorium and
AuditoriumTester(class with main method). Create two different classes in eclipse with the same
name as mentioned here.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Auditorium {
public static final String path = "D:Chegg";
//audiName should be same as the text file name.
public String[][] readAuditorium(String audiName){
String[][] auditorium = null;
BufferedReader br = null;
FileReader fr = null;
try{
fr = new FileReader(path+""+audiName);
br = new BufferedReader(fr);
String currentLine;
List rowList = new ArrayList();
while((currentLine=br.readLine())!=null){
char[] row = currentLine.toCharArray();
rowList.add(row);
}
int col = rowList.get(0).length;
auditorium = new String[rowList.size()][col];
for(int i=0;i9){
String num = i+"";
System.out.print(num.charAt(num.length()-1));
}
else{
System.out.print(i);
}
}
System.out.println();
for(int i=0;i countSeats(String[][] auditorium){
List countOpenReserve = new ArrayList();
int open =0;
int reserve =0;
for(int i=0;i seatsAudi1 = countSeats(audi1);
List seatsAudi2 = countSeats(audi2);
List seatsAudi3 = countSeats(audi3);
int totalOpenSeats = seatsAudi1.get(0)+seatsAudi2.get(0)+seatsAudi3.get(0);
int totalReserveSeats = seatsAudi1.get(1)+seatsAudi2.get(1)+seatsAudi3.get(1);
int totalSale = totalReserveSeats*7;
System.out.println("Auditorium1"+"tt"+seatsAudi1.get(1)+"tt"+seatsAudi1.get(0)+"t
"+"$"+seatsAudi1.get(1)*7);
System.out.println("Auditorium2"+"tt"+seatsAudi2.get(1)+"tt"+seatsAudi2.get(0)+"t
"+"$"+seatsAudi2.get(1)*7);
System.out.println("Auditorium3"+"tt"+seatsAudi3.get(1)+"tt"+seatsAudi3.get(0)+"t
"+"$"+seatsAudi3.get(1)*7);
System.out.println("Total"+"ttt"+totalReserveSeats+"tt"+totalOpenSeats+"t"+"$"
+totalSale);
}
}
Main Class
import java.util.Scanner;
public class AuditoriumTester {
public static void main(String[] args) {
String ch = "";
String audiName;
Scanner sc = new Scanner(System.in);;
String[][] audi =null;
Auditorium auditorium = new Auditorium();
do{
System.out.println("*******Select an Auditorium**********");
System.out.println("Auditorium 1: Enter 1");
System.out.println("Auditorium 2: Enter 2");
System.out.println("Auditorium 3: Enter 3");
System.out.println("Exit: Enter 4");
System.out.println("**************************************");
System.out.print("Your Input: ");
String choice = sc.next();
if(choice.equals("1")){
audi = auditorium.readAuditorium("audi1.txt");
audiName="audi1.txt";
}
else if(choice.equals("2")){
audi = auditorium.readAuditorium("audi2.txt");
audiName="audi2.txt";
}else if(choice.equals("3")){
audi = auditorium.readAuditorium("audi3.txt");
audiName="audi3.txt";
}else
break;
//Display the selected auditorium.
auditorium.displayAuditorium(audi);
System.out.println("Select your seats");
System.out.print("Row Number: ");
int row = sc.nextInt();
System.out.println();
System.out.print("Starting Seat Number: ");
int seat = sc.nextInt();
System.out.println();
System.out.print("Number of tickets: ");
int quantity = sc.nextInt();
if(auditorium.checkAvailability(audi, row, seat, quantity)){
System.out.println("Do you want to reserve seat(Y/N):");
String reserve = sc.next();
if(reserve.equalsIgnoreCase("y")){
auditorium.reserveSeats(audi, row, seat, quantity);
}else{
continue;
}
}else{
int bestSeat = auditorium.bestAvailable(audi, row, quantity);
if(bestSeat==0){
System.out.println("No seat available for your selection in this row. Please try
another row or change auditorium");
System.out.println("Do you want to continue(Y/N):");
String reserve = sc.next();
if(reserve.equalsIgnoreCase("y")){
continue;
}else{
break;
}
}
System.out.println("Your current choice is not available. However, you can choose
seat: "+bestSeat);
System.out.print("Do you want to reserve seat(Y/N):");
String reserve = sc.next();
if(reserve.equalsIgnoreCase("y")){
auditorium.reserveSeats(audi, row, bestSeat, quantity);
}else{
continue;
}
}
auditorium.printReport(audi, audiName);
System.out.print("Do you want to continue(y/n): ");
ch = sc.next();
}while(ch.equalsIgnoreCase("y"));
sc.close();
}
}

More Related Content

Similar to Objectives Create a Java program using programming fundamentals (fi.pdf

Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfleventhalbrad49439
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docxECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docxjack60216
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMSkoolkampus
 
computer operating system:Greedy algorithm
computer operating system:Greedy algorithmcomputer operating system:Greedy algorithm
computer operating system:Greedy algorithmRitaThakkar1
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxstilliegeorgiana
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
Software development slides
Software development slidesSoftware development slides
Software development slidesiarthur
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoreambikavenkatesh2
 

Similar to Objectives Create a Java program using programming fundamentals (fi.pdf (20)

Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docxECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
F# Console class
F# Console classF# Console class
F# Console class
 
3.5
3.53.5
3.5
 
computer operating system:Greedy algorithm
computer operating system:Greedy algorithmcomputer operating system:Greedy algorithm
computer operating system:Greedy algorithm
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Sam python pro_points_slide
Sam python pro_points_slideSam python pro_points_slide
Sam python pro_points_slide
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
 
algorithm Unit 5
algorithm Unit 5 algorithm Unit 5
algorithm Unit 5
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
Software development slides
Software development slidesSoftware development slides
Software development slides
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Python l3
Python l3Python l3
Python l3
 

More from feroz544

Case studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdfCase studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdfferoz544
 
I appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdfI appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdfferoz544
 
How do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdfHow do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdfferoz544
 
Government Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdfGovernment Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdfferoz544
 
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdfGiven L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdfferoz544
 
Explain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdfExplain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdfferoz544
 
Explain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdfExplain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdfferoz544
 
Company management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdfCompany management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdfferoz544
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfferoz544
 
As people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdfAs people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdfferoz544
 
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdfConsider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdfferoz544
 
Click to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdfClick to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdfferoz544
 
Based on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdfBased on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdfferoz544
 
who are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdfwho are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdfferoz544
 
Why is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdfWhy is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdfferoz544
 
Why do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdfWhy do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdfferoz544
 
Which of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdfWhich of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdfferoz544
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfferoz544
 
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdfA 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdfferoz544
 
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern  GibbonsSol.pdfWhat was the first primate to have Y-5 molar pattern  GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern GibbonsSol.pdfferoz544
 

More from feroz544 (20)

Case studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdfCase studyInitial history27-year-old female comlaining of sympto.pdf
Case studyInitial history27-year-old female comlaining of sympto.pdf
 
I appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdfI appreciate any help with the following questions.(1)    What typ.pdf
I appreciate any help with the following questions.(1)    What typ.pdf
 
How do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdfHow do the IPv6 autoconfiguration and numbering features work What .pdf
How do the IPv6 autoconfiguration and numbering features work What .pdf
 
Government Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdfGovernment Audits & Fraud Reporting For discussion During an audit .pdf
Government Audits & Fraud Reporting For discussion During an audit .pdf
 
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdfGiven L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
Given L1 and Prove a llb are supplementary. 3 2 Proof It is given .pdf
 
Explain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdfExplain viewing the nonprofit organization as an economic entity and.pdf
Explain viewing the nonprofit organization as an economic entity and.pdf
 
Explain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdfExplain the concept and cause of freezing point depression. Elaborat.pdf
Explain the concept and cause of freezing point depression. Elaborat.pdf
 
Company management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdfCompany management has asked that you compare the OSSTMM and the PTE.pdf
Company management has asked that you compare the OSSTMM and the PTE.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
As people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdfAs people engage in more international travel and become more famili.pdf
As people engage in more international travel and become more famili.pdf
 
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdfConsider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
Consider a l-D elastic bar problem defined on [0, 4]. The domain .pdf
 
Click to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdfClick to add title 2. Explain the nature of the social structurecast.pdf
Click to add title 2. Explain the nature of the social structurecast.pdf
 
Based on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdfBased on the following data, what is the working capital Accounts p.pdf
Based on the following data, what is the working capital Accounts p.pdf
 
who are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdfwho are the people that steal cashSolutionPeople that steal c.pdf
who are the people that steal cashSolutionPeople that steal c.pdf
 
Why is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdfWhy is nucleotide synthesis an important pathway for medical interve.pdf
Why is nucleotide synthesis an important pathway for medical interve.pdf
 
Why do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdfWhy do some argue that the Fed made the Great Depression worse S.pdf
Why do some argue that the Fed made the Great Depression worse S.pdf
 
Which of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdfWhich of the following is a characteristic of TQMI. A focus on th.pdf
Which of the following is a characteristic of TQMI. A focus on th.pdf
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
 
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdfA 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
A 0.28 mol sample of a weak acid with an unknown pKa was combined wi.pdf
 
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern  GibbonsSol.pdfWhat was the first primate to have Y-5 molar pattern  GibbonsSol.pdf
What was the first primate to have Y-5 molar pattern GibbonsSol.pdf
 

Recently uploaded

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 

Objectives Create a Java program using programming fundamentals (fi.pdf

  • 1. Objectives: Create a Java program using programming fundamentals (file I/O, loops, conditional statements, arrays, functions) Problem: In preparation for the release of Guardians of the Galaxy 2, you have been hired by the owner of a small movie theater to develop the backend for an online ticket reservation system. Patrons will be able to reserve seats in one of three auditoriums. Once the patron has selected an auditorium, the program should display the current seating arrangement and allow the patron to select seats. A report should be generated at the end of the program to specify for each individual auditorium and overall for all auditoriums how many seats were sold/unsold and how much money was earned. Details The seating arrangement for each auditorium will be stored in separate files. These files will be named A1.txt, A2.txt, and A3.txt for auditorium 1, 2 and 3 respectively. Each line in the file will represent a row in the auditorium. The number of rows in each auditorium is unknown to you. The number of seats in each row of a single auditorium will be the same. For example, if the first line of the file has 15 seats, then every subsequent row in the theater will also have 15 seats. This does not mean that each auditorium has the same number of seats in each row. One auditorium may have 15 seats per row and another may have 20 seats. Each auditorium will be held in a two-dimensional array. Empty seats are represented by a pound sign (#). Reserved seats are represented by a period (.). Tickets can only be reserved the day of the screening and all screenings are at 7 PM that night. There is no need to worry about multiple screenings or reserving seats on a specific day. All tickets are $7 regardless of patron age or auditorium. User Interface and Input: Present a user-friendly menu system for the user to select the auditorium. First, ask for the auditorium: 1. Auditorium 1 2. Auditorium 2 3. Auditorium 3 4. Exit Although in reality the user would likely only make one purchase, for testing purposes, assume the user will repeat the ticket buying process until they decide to quit. Once the auditorium has been selected, display the current seating availability for that auditorium. An example seating chart is provided below for an auditorium with 5 rows and 20 seats per row. The seats are numbered sequentially from left to right and only the one's digit is displayed above each column to make it easier to display the chart. It is understood that the second set of digits
  • 2. from 1-0 are for the numbers 11- 20 in the above example. After the user has selected the auditorium and the seating chart has been displayed, prompt the user for the following information in the order below: Row number Starting seat number Number of tickets Assume that the user wants to reserve sequential seats to the right of the first seat entered. If the desired seats are not available, offer the user the best available seats that meet their criteria on that row only. The best available seats are the seats closest to the middle of the row. Prompt the user to enter a Y to reserve the best available or N to refuse the best available. Once the selection has been processed, return to the main menu. All input will be of the valid data type. You do not have to worry about the user entering a letter when a number is expected or a floating point number when an integer is expected. You are responsible for validating that the data falls within the proper range and that a user does not try to reserve a seat that is already reserved. Output: At the end of the program, write the current status of each auditorium to the respective file. Also, display a formatted report to the console. The report should consist of 4 columns: Column 1 – labels o Auditorium 1 o Auditorium 2 o Auditorium 3 o Total Column 2 - number of seats reserved for each label Column 3 - the number of open seats for each label Column 4 - the total of the ticket sales for each label Here is the Pseudocode I have made and verified by the professor. Read Auditorium Arguments: auditorium array Returns: auditorium array Open file While not EOF o Read line o For 0 to line length Copy character in string to array Close file Display Auditorium
  • 3. Arguments: auditorium array Returns: nothing Display column header For each row o Display row number o For each column Display array[row][col] o Display newline Reserve Seats Arguments: auditorium array, row, seat, quantity Returns: nothing For 1 to quantity o Array[row][seat+i] = # Check Availability Arguments: auditorium array, row, seat, quantity Returns: Boolean For 1 to quantity o If array[row][seat+i] is a period Return false Return true Count Seats Arguments: auditorium array Returns: open seats and reserved seats Open file based on auditorium For each row o For each column If array[row][col] = # Increment open seats Else increment reserved seats Print Report Arguments: none Returns: none For 1 to 3 o Call Get Seat Info function o Print out open seats, reserved seats, money earned o Increment total open seats, total reserved seats, total money earned Print out total open seats, total reserved seats, total money earned
  • 4. Best Available Arguments: auditorium array, row, quantity Returns: left endpoint of best available section Determine middle of row From mid to 1 (i) o If array[row][i] = # For 1 to quantity (j) Check if array[row][i-j] = # If all available Left side = Hold i From mid to last column (i) o If array[row][i] = # For 1 to quantity (j) Check if array[row][i+j] = # If all available Right side = Hold i Return min (right side, left side - quantity) Main Loop (do…while not exit) o Print main menu o Get user input o If user does not want to exit Print auditorium Get auditorium number If user wants to reserve seats Ask user for row, seat, and quantity Check if seats are available If available reserve seats If not available search for best available o If best available, offer to user If user wants to see auditorium Call display auditorium function Print report 9 *# *## 5 .# .# 4 .# --# 3 .# -## 2# ---# # -### 0# -# -# 8## . .# 7 .# -## 6 -# --# 5## -## 4## . .# 3 .# -## 2 -# --# 1 .# -## 12345 Solution
  • 5. Here is the full solution to the problem. Note that it has two classes: Audotorium and AuditoriumTester(class with main method). Create two different classes in eclipse with the same name as mentioned here. import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Auditorium { public static final String path = "D:Chegg"; //audiName should be same as the text file name. public String[][] readAuditorium(String audiName){ String[][] auditorium = null; BufferedReader br = null; FileReader fr = null; try{ fr = new FileReader(path+""+audiName); br = new BufferedReader(fr); String currentLine; List rowList = new ArrayList(); while((currentLine=br.readLine())!=null){ char[] row = currentLine.toCharArray(); rowList.add(row); } int col = rowList.get(0).length; auditorium = new String[rowList.size()][col]; for(int i=0;i9){ String num = i+""; System.out.print(num.charAt(num.length()-1)); }
  • 6. else{ System.out.print(i); } } System.out.println(); for(int i=0;i countSeats(String[][] auditorium){ List countOpenReserve = new ArrayList(); int open =0; int reserve =0; for(int i=0;i seatsAudi1 = countSeats(audi1); List seatsAudi2 = countSeats(audi2); List seatsAudi3 = countSeats(audi3); int totalOpenSeats = seatsAudi1.get(0)+seatsAudi2.get(0)+seatsAudi3.get(0); int totalReserveSeats = seatsAudi1.get(1)+seatsAudi2.get(1)+seatsAudi3.get(1); int totalSale = totalReserveSeats*7; System.out.println("Auditorium1"+"tt"+seatsAudi1.get(1)+"tt"+seatsAudi1.get(0)+"t "+"$"+seatsAudi1.get(1)*7); System.out.println("Auditorium2"+"tt"+seatsAudi2.get(1)+"tt"+seatsAudi2.get(0)+"t "+"$"+seatsAudi2.get(1)*7); System.out.println("Auditorium3"+"tt"+seatsAudi3.get(1)+"tt"+seatsAudi3.get(0)+"t "+"$"+seatsAudi3.get(1)*7); System.out.println("Total"+"ttt"+totalReserveSeats+"tt"+totalOpenSeats+"t"+"$" +totalSale); } } Main Class import java.util.Scanner; public class AuditoriumTester { public static void main(String[] args) { String ch = ""; String audiName;
  • 7. Scanner sc = new Scanner(System.in);; String[][] audi =null; Auditorium auditorium = new Auditorium(); do{ System.out.println("*******Select an Auditorium**********"); System.out.println("Auditorium 1: Enter 1"); System.out.println("Auditorium 2: Enter 2"); System.out.println("Auditorium 3: Enter 3"); System.out.println("Exit: Enter 4"); System.out.println("**************************************"); System.out.print("Your Input: "); String choice = sc.next(); if(choice.equals("1")){ audi = auditorium.readAuditorium("audi1.txt"); audiName="audi1.txt"; } else if(choice.equals("2")){ audi = auditorium.readAuditorium("audi2.txt"); audiName="audi2.txt"; }else if(choice.equals("3")){ audi = auditorium.readAuditorium("audi3.txt"); audiName="audi3.txt"; }else break; //Display the selected auditorium. auditorium.displayAuditorium(audi); System.out.println("Select your seats"); System.out.print("Row Number: "); int row = sc.nextInt(); System.out.println(); System.out.print("Starting Seat Number: "); int seat = sc.nextInt(); System.out.println(); System.out.print("Number of tickets: ");
  • 8. int quantity = sc.nextInt(); if(auditorium.checkAvailability(audi, row, seat, quantity)){ System.out.println("Do you want to reserve seat(Y/N):"); String reserve = sc.next(); if(reserve.equalsIgnoreCase("y")){ auditorium.reserveSeats(audi, row, seat, quantity); }else{ continue; } }else{ int bestSeat = auditorium.bestAvailable(audi, row, quantity); if(bestSeat==0){ System.out.println("No seat available for your selection in this row. Please try another row or change auditorium"); System.out.println("Do you want to continue(Y/N):"); String reserve = sc.next(); if(reserve.equalsIgnoreCase("y")){ continue; }else{ break; } } System.out.println("Your current choice is not available. However, you can choose seat: "+bestSeat); System.out.print("Do you want to reserve seat(Y/N):"); String reserve = sc.next(); if(reserve.equalsIgnoreCase("y")){ auditorium.reserveSeats(audi, row, bestSeat, quantity); }else{ continue; } } auditorium.printReport(audi, audiName); System.out.print("Do you want to continue(y/n): "); ch = sc.next();