Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

his a nt In this assignment, we will be making a program that reads in guests\'

ID: 3816600 • Letter: H

Question

his a nt In this assignment, we will be making a program that reads in guests' information, and create a graduation ceremony seating with a number of rows and columns specified by a user. Then it will attempt to assign each guest to a seat in an auditorium Download the following files and use them for this assignment. Assignment Ijava Do not change the content of this file.) ave all files in the same folder l. First, you need to create Guestjava file by defining Guest class It should have two instance variables, lastName (String) and firstName (String) In addition, the following methods should be defined. Description of the Method Method Constructs a Guest object by assigning the default string to both instance public Guest variables, lastName and firstName. Constructs a Guest object using the string containing guest's info. Use the split method of the String class to extract first name and last name, then assign them to public Guest (String guestInfo) each instance variable of the Guest class. An example of the input string is David Johnson public string getLastName O It should return the instance variable lastName. public string getFirstName O It should return the instance variable firstName. It should constructor a string containing the initial character of the first name, a period, the initial character of the last name, and a period, then it returns it. public String toString An example of such string for the guest David Johnson is: DJ 2. You will be creating a class called Auditoriumseating. This class should be defined in a file named "AuditoriumSeatingjava" The class AuditoriumSeating will contain a 2 dimensional array called "seating" of Guest objects at its instance variable The class AuditoriumSeating must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted. Description of the Method Method It instantiates a two dimensional array of the size "rowNum" by "columnNum public Auditoriumseating(int rowNum, specified by the parameters. Then it initializes each guest element ofthis array int column Num) using the constructor ofthe class Guest without any parameter. So each guest will have default valu es for its instance variables. private Guest getGuestAt(int row, int It returns a guest at the indexes row and col (specified by the parameters of this method) of the array "seating col) The method attempts to assign the "tempGuest" to the seat at "row" and "col"

Explanation / Answer

//Guest.java

public class Guest {

   //Attributes
   String firstName,lastName;
  
   //Constructor
   public Guest(){
       firstName = "???";
       lastName = "???";
   }
   //Constructor with Name
   public Guest(String guestInfo){
       String name[] = guestInfo.split("/");
       this.setFirstName(name[0]);
       this.setLastName(name[1]);
   }

   //Setters and getters
   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
  
   //toString Method
   public String toString(){
       StringBuffer sb = new StringBuffer();
       char fc = this.getFirstName().charAt(0);
       char lc = this.getLastName().charAt(0);
       return sb.append(fc).append(".").append(lc).append(".").toString();
   }
}

// AuditoriumSeating.java


public class AuditoriumSeating {

   //Attributes
   int rowNum;
   int columnNum;
   Guest seating[][];
  
   //Constructor takes row, column
   public AuditoriumSeating(int rowNum,int columnNum){
       this.rowNum = rowNum;
       this.columnNum = columnNum;
       //Creating array
       seating = new Guest[rowNum][columnNum];
       //Assigning Array default values
       for(int i=0;i<rowNum;i++){
           for(int j=0;j<columnNum;j++){
               seating[i][j] = new Guest();
           }
       }
   }
  
   //Getting Guest At
   private Guest getGuestAt(int row,int col){
       return seating[row][col];
   }
  
   //Assigning Guest at position
   public boolean assignGuestAt(int row,int col,Guest tempGuest){
       int count=0;
       for(int i=0;i<rowNum;i++){
           for(int j=0;j<columnNum;j++){
               if(i==row && j==col){
                   if(seating[row][col].getFirstName().equals("???") && seating[row][col].getLastName().equals("???")){
                       seating[row][col] = tempGuest;
                       count++;
                   }
               }
           }
       }
      
       if(count>0){
           return true;
       }else{
           return false;
       }
   }
  
   //Checking indexes of array row and column
   public boolean checkBoundaries(int row,int col){
       if(row<0 ||row>rowNum || col<0 || col>columnNum)
           return false;
       else
           return true;
   }
  
   //Printing Seating plans and assignments
   public String toString(){
       StringBuffer sb = new StringBuffer();
       for(int i=0;i<rowNum;i++){
           for(int j=0;j<columnNum;j++){
               char fc = seating[i][j].getFirstName().charAt(0);
               char lc = seating[i][j].getLastName().charAt(0);
               sb.append(fc).append(".").append(lc).append(".").append(" ");
           }
           sb.append(" ");
       }  
       return sb.toString();
   }
}

//Assignment7.java

import java.util.Scanner;


public class Assignment7 {
   public static void main(String[] args) {
       //Scanner for input
       Scanner s = new Scanner(System.in);
       //Reading rows and columns for auditorium
       System.out.println("Enter number of rows for an auditorium seating:");
       int rows = s.nextInt();
      
       System.out.println("Enter number of columns for an auditorium seating:");
       int cols = s.nextInt();
       //Calling constructor to set row and column
       AuditoriumSeating as = new AuditoriumSeating(rows, cols);
       //While is true until Q is Typed as input
       while(true){
           System.out.println("Please Enter Guest Information or Enter Q to Quit");
           //Reading Guest Info
           String g = s.next();
           if(g.equals("Q"))
               break;
           //Calling Guest to create instance
           Guest guest = new Guest(g);
          
           System.out.println("Guest Information is read.");
           System.out.println(g);
          
           System.out.println("Please enter the row number where the guest want to sit:");
           int grow = s.nextInt();
          
           System.out.println("Please enter the column number where the guest want to sit:");
           int gcol = s.nextInt();
          
           //Checking boundaries of array row and col
           boolean res = as.checkBoundaries(grow, gcol);
          
           //Condition if true
           if(res){
               boolean bb = as.assignGuestAt(grow, gcol, guest);
               //Condition for Assignment of Guest
               if(bb){
                   System.out.println("The seat at row "+grow+" and column "+gcol+" is assigned to the guest "+g);
                   System.out.println("The Current Seating is:");
                   System.out.println("--------------------------------");
                   System.out.println(as.toString());
               }else{
                   System.out.println("The seat at row "+grow+" and Column "+gcol+" is taken");
               }
           }else{
               System.out.println("Row Or Column number is invalid");
               System.out.println("A Guest "+g+" is not assigned a seat");
           }
      
       }//end of while
   }

}

Output:

javac Assignment7.java

java Assignment7

Enter number of rows for an auditorium seating:
3
Enter number of columns for an auditorium seating:
3
Please Enter Guest Information or Enter Q to Quit
John/Parker
Guest Information is read.
John/Parker
Please enter the row number where the guest want to sit:
2
Please enter the column number where the guest want to sit:
2
The seat at row 2 and column 2 is assigned to the guest John/Parker
The Current Seating is:
--------------------------------
?.?. ?.?. ?.?.
?.?. ?.?. ?.?.
?.?. ?.?. J.P.

Please Enter Guest Information or Enter Q to Quit
Peter/Siddle
Guest Information is read.
Peter/Siddle
Please enter the row number where the guest want to sit:
1
Please enter the column number where the guest want to sit:
2
The seat at row 1 and column 2 is assigned to the guest Peter/Siddle
The Current Seating is:
--------------------------------
?.?. ?.?. ?.?.
?.?. ?.?. P.S.
?.?. ?.?. J.P.

Please Enter Guest Information or Enter Q to Quit
Mickey/Mouse
Guest Information is read.
Mickey/Mouse
Please enter the row number where the guest want to sit:
0
Please enter the column number where the guest want to sit:
1
The seat at row 0 and column 1 is assigned to the guest Mickey/Mouse
The Current Seating is:
--------------------------------
?.?. M.M. ?.?.
?.?. ?.?. P.S.
?.?. ?.?. J.P.

Please Enter Guest Information or Enter Q to Quit
Kartheek/Patnaik
Guest Information is read.
Kartheek/Patnaik
Please enter the row number where the guest want to sit:
1
Please enter the column number where the guest want to sit:
1
The seat at row 1 and column 1 is assigned to the guest Kartheek/Patnaik
The Current Seating is:
--------------------------------
?.?. M.M. ?.?.
?.?. K.P. P.S.
?.?. ?.?. J.P.

Please Enter Guest Information or Enter Q to Quit
James/Cameroon
Guest Information is read.
James/Cameroon
Please enter the row number where the guest want to sit:
-1
Please enter the column number where the guest want to sit:
2
Row Or Column number is invalid
A Guest James/Cameroon is not assigned a seat
Please Enter Guest Information or Enter Q to Quit
AB/Devillers
Guest Information is read.
AB/Devillers
Please enter the row number where the guest want to sit:
2
Please enter the column number where the guest want to sit:
2
The seat at row 2 and Column 2 is taken
Please Enter Guest Information or Enter Q to Quit
Sachin/Tendulkar
Guest Information is read.
Sachin/Tendulkar
Please enter the row number where the guest want to sit:
0
Please enter the column number where the guest want to sit:
2
The seat at row 0 and column 2 is assigned to the guest Sachin/Tendulkar
The Current Seating is:
--------------------------------
?.?. M.M. S.T.
?.?. K.P. P.S.
?.?. ?.?. J.P.

Please Enter Guest Information or Enter Q to Quit
Q