Question

In this assignment, we will be making a program that reads in customers' information, and create...

In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre.

1. First, you need to add one additional constructor method into Customer.java file.

Method
Description of the Method
public Customer (String customerInfo)
Constructs a Customer object using the string containing customer's info. Use the split method of the String class to extract first name, last name, id, the number of matinee tickets, and the number of normal tickets and assign them to each instance variable of the Customer class. An example of the input string is:
David/Johnson/666888999/16/5

2. You will be creating a class called MovieSeating. This class should be defined in a file named "MovieSeating.java".
The class MovieSeating will contain a 2 dimensional array called "seating" of Customer objects at its instance variable.
The class MovieSeating must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.)

Method
Description of the Method
public MovieSeating(int rowNum, int columnNum)
It instantiates a two dimensional array of the size "rowNum" by "columnNum" specified by the parameters. Then it initializes each customer element of this array using the constructor of the class Customer without any parameter. So each customer will have default values for its instance variables.
private Customer getCustomerAt(int row, int col)
It returns a customer at the indexes row and col (specified by the parameters of this method) of the array "seating".
public boolean assignCustomerAt(int row, int col, Customer tempCustomer)
The method attempts to assign the "tempCustomer" to the seat at "row" and "col" (specified by the parameters of this method). If the seat has a default customer, i.e., a customer with the last name "???" and the first name "???", then we can assign the new customer "tempCustomer" to that seat and the method returns true. Otherwise, this seat is considered to be taken by someone else, the method does not assign the customer and returns false.
public boolean checkBoundaries(int row, int col)
The method checks if the parameters row and col are valid. If at least one of the parameters "row" or "col" is less than 0 or larger than the last index of the array (note that the number of rows and columns can be different), then it returns false. Otherwise it returns true.
public String toString( )
Returns a String containing information of the "seating". It should show the list of customers assigned to the seating using the toString method of the class Customer (it shows initials of each customer) and the following format:

The current seating
--------------------
C.B. ?.?. E.P.
?.?. ?.?. B.O.
B.C. H.C. ?.?.


Please see the sample output listed below.


After compiling Customer.java, MovieSeating.java, and Assignment7.java files, you need to execute Assignment7 class.
Sample Output: (the inputs entered by a user are shown in bold)
(Make sure that your program works at least with this scenario.)
C:\MyJava\applications>java Assignment7

Please enter a number of rows for a movie theatre seating.
3
Please enter a number of columns for a movie theatre seating.
3
Please enter a customer information or enter "Q" to quit.
Barack/Obama/111111111/3/4

A customer information is read.
Barack/Obama/111111111/3/4
Please enter a row number where the customer wants to sit.
1
Please enter a column number where the customer wants to sit.
2

The seat at row 1 and column 2 is assigned to the customer B.O.

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. B.O.
?.?. ?.?. ?.?.

Please enter a customer information or enter "Q" to quit.
Bill/Clinton/222222222/6/5

A customer information is read.
Bill/Clinton/222222222/6/5
Please enter a row number where the customer wants to sit.
2
Please enter a column number where the customer wants to sit.
0

The seat at row 2 and column 0 is assigned to the customer B.C.

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. B.O.
B.C. ?.?. ?.?.

Please enter a customer information or enter "Q" to quit.
Hilary/Clinton/444444444/5/3

A customer information is read.
Hilary/Clinton/444444444/5/3
Please enter a row number where the customer wants to sit.
2
Please enter a column number where the customer wants to sit.
1

The seat at row 2 and column 1 is assigned to the customer H.C.

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. B.O.
B.C. H.C. ?.?.

Please enter a customer information or enter "Q" to quit.
Charlie/Brown/333333333/4/3

A customer information is read.
Charlie/Brown/333333333/4/3
Please enter a row number where the customer wants to sit.
0
Please enter a column number where the customer wants to sit.
0

The seat at row 0 and column 0 is assigned to the customer C.B.

The current seating
--------------------
C.B. ?.?. ?.?.
?.?. ?.?. B.O.
B.C. H.C. ?.?.

Please enter a customer information or enter "Q" to quit.
David/Beckham/555666777/4/5

A customer information is read.
David/Beckham/555666777/4/5
Please enter a row number where the customer wants to sit.
5
Please enter a column number where the customer wants to sit.
1

row or column number is not valid.
A customer David Beckham is not assigned a seat.
Please enter a customer information or enter "Q" to quit.
George/Bush/666888999/16/5

A customer information is read.
George/Bush/666888999/16/5
Please enter a row number where the customer wants to sit.
2
Please enter a column number where the customer wants to sit.
0

The seat at row 2 and column 0 is taken.
Please enter a customer information or enter "Q" to quit.
Snow/White/777777777/43/23

A customer information is read.
Snow/White/777777777/43/23
Please enter a row number where the customer wants to sit.
-1
Please enter a column number where the customer wants to sit.
0

row or column number is not valid.
A customer Snow White is not assigned a seat.
Please enter a customer information or enter "Q" to quit.
Elvis/Presley/888888888/2/4

A customer information is read.
Elvis/Presley/888888888/2/4
Please enter a row number where the customer wants to sit.
0
Please enter a column number where the customer wants to sit.
2

The seat at row 0 and column 2 is assigned to the customer E.P.

The current seating
--------------------
C.B. ?.?. E.P.
?.?. ?.?. B.O.
B.C. H.C. ?.?.

Please enter a customer information or enter "Q" to quit.
Q

/*-------------------------------------------------------------------------
// AUTHOR: CSE110 instructor
// FILENAME: Assignnment7.java
// SPECIFICATION: This program will read a series of customers' information.
// A user will specify the size the number of rows and columns for a movie
// theatre. Then the program will try to assign each customer to a seat.
//----------------------------------------------------------------------*/


import java.util.Scanner;

public class Assignment7
{
public static void main(String[] args)
{

MovieSeating theatreSeating;
Customer tempCustomer;
int row, col, rowNum, columnNum;
String custInfo;


Scanner scan = new Scanner(System.in);


// Ask a user to enter a number of rows for a movie theatre seating
System.out.println("Please enter a number of rows for a movie theatre seating.");
rowNum = scan.nextInt();


// Ask a user to enter a number of columns for a movie theatre seating
System.out.println("Please enter a number of columns for a movie theatre seating.");
columnNum = scan.nextInt();

// instantiate a MovieSeating object
theatreSeating = new MovieSeating(rowNum, columnNum);


System.out.println("Please enter a customer information or enter \"Q\" to quit.");
/*** reading a customer's information ***/
custInfo = scan.next();

/*** we will read line by line until we read the end of a given file ***/
while (!custInfo.equalsIgnoreCase("Q"))
{
System.out.println("\nA customer information is read.");
// printing information read from a file.
System.out.println(custInfo);

// creating a customer object using the customer information from a user
tempCustomer = new Customer(custInfo);

// Ask a user to decide where to seat a customer by asking for row and column of a seat
System.out.println("Please enter a row number where the customer wants to sit.");
row = scan.nextInt();

System.out.println("Please enter a column number where the customer wants to sit.");
col = scan.nextInt();

// Checking if the row number and column number are valid (exist in the theatre that we created.)
if (theatreSeating.checkBoundaries(row, col) == false)
{
System.out.println("\nrow or column number is not valid.");
System.out.println("A customer " + tempCustomer.getFirstName() + " " + tempCustomer.getLastName() + " is not assigned a seat.");
}
else
{
// Assigning a seat for a customer
if (theatreSeating.assignCustomerAt(row, col, tempCustomer) == true)
{
System.out.println("\nThe seat at row " + row + " and column " + col + " is assigned to the customer " + tempCustomer.toString());
System.out.println(theatreSeating);
}
else
{
System.out.println("\nThe seat at row " + row + " and column " + col + " is taken.");
}
}

// Read the next custInfo
System.out.println("Please enter a customer information or enter \"Q\" to quit.");
/*** reading a customer's information ***/
custInfo = scan.next();

}
}

}


/*-------------------------------------------------------------------------
// AUTHOR:
// FILENAME: Customer.java
// SPECIFICATION: The class Customer describes information on a customer
// and has a first name (a String), last name (String), ID number (integer),
// number of matinee tickets (integer), number of normal tickets (integer),
// and total cost (double).
//----------------------------------------------------------------------*/

public class Customer
{
private String lastName;
private String firstName;
private int customerID;
private int matineeTickets;
private int normalTickets;
private double totalCost;

// This constructor sets the first name and last name to "???", customer ID,
// the number of matinee tickets, and the number of normal tickets to 0,
// and the total cost to 0.0.
public Customer()
{
lastName = "???";
firstName = "???";
customerID = 0;
matineeTickets = 0;
normalTickets = 0;
totalCost = 0.0;
}
// This constructor constructs a Customer object given the last name,
// first name, customer id, the number of matinee tickets, the number
// of normal tickets.
public Customer(String customerInfo)
{

/****** COMPLETE THIS METHOD *******/

}

// This constructor cConstructs a Customer object using the string containing customer's info.
// It uses the StringTokenizer to extract first name, last name, id, the number of matinee tickets,
// and the number of normal tickets.
public Customer(String lName, String fName, int id, int matineeNum, int normalNum)
{
lastName = lName;
firstName = fName;
customerID = id;
matineeTickets = matineeNum;
normalTickets = normalNum;
totalCost = 0.0;
computeTotalCost();
}

// This method sets the last name.
public void setLastName(String lName)
{
lastName = lName;
}
// This method sets the first name.
public void setFirstName(String fName)
{
firstName = fName;
}
// This method sets the customer ID.
public void setCustomerID(int id)
{
customerID = id;
}

// This method set the value of number of matineeTickets to have its parameter value.
// And it re-computes total cost.
public void setMatineeTickets(int matinee)
{
matineeTickets = matinee;
computeTotalCost();
}

// This method set the value of number of notmalTickets to have its parameter value.
// And it re-computes total cost.
public void setNormalTickets(int normal)
{
normalTickets = normal;
computeTotalCost();
}


// This method returns the last name.
public String getLastName()
{
return lastName;
}
// This method returns the first name.
public String getFirstName()
{
return firstName;
}

// This method returns the customer ID.
public int getCustomerID()
{
return customerID;
}

// This method returns the number of matinee tickets.
public int getMatineeTickets()
{
return matineeTickets;
}

// This method returns the number of normal tickets.
public int getNormalTickets()
{
return normalTickets;
}

// This method returns the total cost.
public double getTotalCost()
{
return totalCost;
}

// This method compute the total cost based on the number of matinee tickets and normal tickets.
private void computeTotalCost()
{
totalCost = (5.00)*matineeTickets + (7.50)*normalTickets;
}

// This method checks if a customer object passed as a parameter and itself (customer object)
// are same using their last names, first names, and customerIDs.
public boolean equals(Customer other)
{
if (lastName.equals(other.lastName) && firstName.equals(other.firstName)
&& (customerID == other.customerID) )
return true;
else
return false;
}
// This method compares a customer object passed as a parameter to itself (customer object)
// are same using their total costs.
public Customer hasMore(Customer other)
{
if (totalCost >= other.totalCost)
return this;
else
return other;
}

// This method returns a string containing a customer's initials
// (first characters of firstName and lastName.)
public String toString()
{
String result = firstName.charAt(0) + "." + lastName.charAt(0) + ".";
return result;
}
} // end of the class Customer
0 0
Add a comment Improve this question Transcribed image text
Answer #1
// Customer.java
public class Customer {
private String lastName;
private String firstName;
private int customerID;
private int matineeTickets;
private int normalTickets;
private double totalCost;

// This constructor sets the first name and last name to "???", customer ID,
// the number of matinee tickets, and the number of normal tickets to 0,
// and the total cost to 0.0.
public Customer() {
lastName = "???";
firstName = "???";
customerID = 0;
matineeTickets = 0;
normalTickets = 0;
totalCost = 0.0;
}

// This constructor constructs a Customer object given the last name,
// first name, customer id, the number of matinee tickets, the number
// of normal tickets.
public Customer(String customerInfo) {
// splits the customer info based on / character
String token[] = customerInfo.split("/");
// assigns the appropriate value to the data fields
firstName = token[0];
lastName = token[1];
customerID = Integer.parseInt(token[2]);
matineeTickets = Integer.parseInt(token[3]);
normalTickets = Integer.parseInt(token[4]);
totalCost = 0;
computeTotalCost();
}

// This constructor cConstructs a Customer object using the string
// containing customer's info.
// It uses the StringTokenizer to extract first name, last name, id, the
// number of matinee tickets,
// and the number of normal tickets.
public Customer(String lName, String fName, int id, int matineeNum,
int normalNum) {
lastName = lName;
firstName = fName;
customerID = id;
matineeTickets = matineeNum;
normalTickets = normalNum;
totalCost = 0.0;
computeTotalCost();
}

// This method sets the last name.
public void setLastName(String lName) {
lastName = lName;
}

// This method sets the first name.
public void setFirstName(String fName) {
firstName = fName;
}

// This method sets the customer ID.
public void setCustomerID(int id) {
customerID = id;
}

// This method set the value of number of matineeTickets to have its
// parameter value.
// And it re-computes total cost.
public void setMatineeTickets(int matinee) {
matineeTickets = matinee;
computeTotalCost();
}

// This method set the value of number of notmalTickets to have its
// parameter value.
// And it re-computes total cost.
public void setNormalTickets(int normal) {
normalTickets = normal;
computeTotalCost();
}

// This method returns the last name.
public String getLastName() {
return lastName;
}

// This method returns the first name.
public String getFirstName() {
return firstName;
}

// This method returns the customer ID.
public int getCustomerID() {
return customerID;
}

// This method returns the number of matinee tickets.
public int getMatineeTickets() {
return matineeTickets;
}

// This method returns the number of normal tickets.
public int getNormalTickets() {
return normalTickets;
}

// This method returns the total cost.
public double getTotalCost() {
return totalCost;
}

// This method compute the total cost based on the number of matinee tickets
// and normal tickets.
private void computeTotalCost() {
totalCost = (5.00) * matineeTickets + (7.50) * normalTickets;
}

// This method checks if a customer object passed as a parameter and itself
// (customer object)
// are same using their last names, first names, and customerIDs.
public boolean equals(Customer other) {
if (lastName.equals(other.lastName)
&& firstName.equals(other.firstName)
&& (customerID == other.customerID))
return true;
else
return false;
}

// This method compares a customer object passed as a parameter to itself
// (customer object)
// are same using their total costs.
public Customer hasMore(Customer other) {
if (totalCost >= other.totalCost)
return this;
else
return other;
}

// This method returns a string containing a customer's initials
// (first characters of firstName and lastName.)
public String toString() {
String result = firstName.charAt(0) + "." + lastName.charAt(0) + ".";
return result;
}
} // end of the class Customer

// MovieSeating.java
public class MovieSeating {

// two dimensional array of customer objects
Customer seating[][];

// 2-argument constructor takes rows and columns to initialize
// the two dimensional seating array
public MovieSeating(int rowNum, int columnNum) {

seating = new Customer[rowNum][columnNum];

for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < columnNum; j++)
seating[i][j] = new Customer();
}
}

// returns customer at given row and column position
private Customer getCustomerAt(int row, int col) {
return seating[row][col];
}

//assigns the seat specified by row and column to the tempCustomer
//if the seat is available
public boolean assignCustomerAt(int row, int col, Customer tempCustomer) {
Customer cur = seating[row][col];
if (cur.getLastName().equals("???") && cur.getFirstName().equals("???")) {
seating[row][col] = tempCustomer;
return true;
} else
return false;
}

//checks the boundaries of given row and column against the
//array dimensions
public boolean checkBoundaries(int row, int col) {
if (row < 0 || col < 0 || row >= seating.length
|| col >= seating[0].length)
return false;
else
return true;
}

//returns current seating
public String toString() {
String seats = "The current seating\n";
seats += "-------------------\n";

for (int i = 0; i < seating.length; i++) {
for (int j = 0; j < seating[i].length; j++)
seats += seating[i][j].getFirstName().charAt(0) + "."
+ seating[i][j].getLastName().charAt(0) + "." + " ";
seats += "\n";
}
return seats;
}
}

Output:
Add a comment
Know the answer?
Add Answer to:
In this assignment, we will be making a program that reads in customers' information, and create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • Implement a class CSVReader that reads a CSV file, and provide methods: int numbOfRows() int numberOfFields(int...

    Implement a class CSVReader that reads a CSV file, and provide methods: int numbOfRows() int numberOfFields(int row) String field(int row, int column) Please use the CSVReader and CSVReaderTester class to complete the code. I have my own CSV files and cannot copy them to here. So if possible, just use a random CSV file. CSVReader.java import java.util.ArrayList; import java.util.Scanner; import java.io.*; /**    Class to read and process the contents of a standard CSV file */ public class CSVReader {...

  • This is for Java. Create ONE method/function that will return an array containing the row and...

    This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...

  • Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right...

    Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()"                                         public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

  • //please help I can’t figure out how to print and can’t get the random numbers to...

    //please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the...

    Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT