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

Save all files in the same folder. 1. First, you need to create Guest.java file

ID: 3814275 • Letter: S

Question

Save all files in the same folder.

1. First, you need to create Guest.java file by defining Guest class.
It should have two instance variables, lastName (String) and firstName (String).
In addition, the following methods should be defined.

Method

Description of the Method

public Guest ( )

Constructs a Guest object by assigning the default string " ??? " to both instance variables, lastName and firstName.

guestInfo

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 each instance variable of the Guest class. An example of the input string is:

               David/Johnson

public String getLastName ( )

It should return the instance variable lastName.

public String getFirstName ( )

It should return the instance variable firstName.

public String toString ( )

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.
An example of such string for the guest David Johnson is:
               D.J.

2. You will be creating a class called AuditoriumSeating. This class should be defined in a file named "AuditoriumSeating.java".
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.)

Method

Description of the Method

public AuditoriumSeating(int rowNum, int columnNum)

It instantiates a two dimensional array of the size "rowNum" by "columnNum" specified by the parameters. Then it initializes each guest element of this array using the constructor of the class Guest without any parameter. So each guest will have default values for its instance variables.

private Guest getGuestAt(int row, intcol)

It returns a guest at the indexes row and col (specified by the parameters of this method) of the array "seating".

public boolean assignGuestAt(int row, int col, Guest tempGuest)

The method attempts to assign the "tempGuest" to the seat at "row" and "col" (specified by the parameters of this method). If the seat has a default guest, i.e., a guest with the last name "???" and the first name "???", then we can assign the new guest "tempGuest" 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 guest 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 guests assigned to the seating using the toString method of the class Guest (it shows initials of each guest) and the following format:

The current seating
--------------------
D.J. ?.?. E.T..
?.?. ?.?. S.W.
T.C. A.T. ?.?.


Please see the sample output listed below.

After compiling Guest.java, AuditoriumSeating.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:MyJavapplications>java Assignment7  

Please enter a number of rows for an auditorium seating.
3
Please enter a number of columns for an auditorium seating.
3
Please enter a guest information or enter "Q" to quit.
Mickey/Mouse

A guest information is read.
Mickey/Mouse
Please enter a row number where the guest wants to sit.
1
Please enter a column number where the guest wants to sit.
2

The seat at row 1 and column 2 is assigned to the guest M.M.

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. M.M.
?.?. ?.?. ?.?.

Please enter a guest information or enter "Q" to quit.
Daisy/Duck

A guest information is read.
Daisy/Duck
Please enter a row number where the guest wants to sit.
2
Please enter a column number where the guest wants to sit.
0

The seat at row 2 and column 0 is assigned to the guest D.D.

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. M.M.
D.D. ?.?. ?.?.

Please enter a guest information or enter "Q" to quit.
Clarabelle/Cow

A guest information is read.
Clarabelle/Cow
Please enter a row number where the guest wants to sit.
2
Please enter a column number where the guest wants to sit.
1

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

The current seating
--------------------
?.?. ?.?. ?.?.
?.?. ?.?. M.M.
D.D. C.C. ?.?.

Please enter a guest information or enter "Q" to quit.
Max/Goof
A guest information is read.
Max/Goof
Please enter a row number where the guest wants to sit.
0
Please enter a column number where the guest wants to sit.
0

The seat at row 0 and column 0 is assigned to the guest M.G.

The current seating
--------------------
M.G. ?.?. ?.?.
?.?. ?.?. M.M.
D.D. C.C. ?.?.

Please enter a guest information or enter "Q" to quit.
Horace/Horsecollar
A guest information is read.
Horace/Horsecollar
Please enter a row number where the guest wants to sit.
5
Please enter a column number where the guest wants to sit.
1

row or column number is not valid.
A guest Horace Horsecollar is not assigned a seat.
Please enter a guest information or enter "Q" to quit.
Sylvester/Shyster

A guest information is read.
Sylvester/Shyster
Please enter a row number where the guest wants to sit.
2
Please enter a column number where the guest wants to sit.
0

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

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

row or column number is not valid.
A guest Snow White is not assigned a seat.
Please enter a guest information or enter "Q" to quit.
Jiminy/Criket

A guest information is read.
Jiminy/Criket
Please enter a row number where the guest wants to sit.
0
Please enter a column number where the guest wants to sit.
2

The seat at row 0 and column 2 is assigned to the guest J.C.

The current seating
--------------------
M.G. ?.?. J.C.
?.?. ?.?. M.M.
D.D. C.C. ?.?.

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

*********************************************************************************

Helpful hints for doing this assignment:

        work on it in steps. Write one method, test it with a test driver and make sure it works before going on to the next method

        always make sure your code compiles before you add another method

        your methods should be able to be called in any order

*********************************************************************************

For this and all subsequent assignments, provide a heading (in comments) which includes:

The assignment number.

Its author (your name).

Your Lab Letter.

A description of what this program is doing.

Grading Criteria for the part 2:

1 pt: Every file contains header information

3 pts: adequate comment to explain every method

1 pt: consistent indentation and spacing

1 pt: it compiles

2 pts: Two constructors of Guest are correct

1 pt: Accessor methods for lastName and firstName of Guest are correct

1 pt: toString method of Guest is correct

2 pts: Constructor, AuditoriumSeating(int,int) is correct

2 pts: getGuestAt(int,int) method is correct

2 pts: assignGuestAt(int,int,Guest) method is correct

2 pts: checkBoundaries(int,int) method is correct

2 pts: toString method is correct

Method

Description of the Method

public Guest ( )

Constructs a Guest object by assigning the default string " ??? " to both instance variables, lastName and firstName.

guestInfo

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 each instance variable of the Guest class. An example of the input string is:

               David/Johnson

public String getLastName ( )

It should return the instance variable lastName.

public String getFirstName ( )

It should return the instance variable firstName.

public String toString ( )

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.
An example of such string for the guest David Johnson is:
               D.J.

Explanation / Answer

guest.java

---------------------------------------------------------------------------------------

package somePackage;

public class Guest {

   String lastName;
   String firstName;
  
   public Guest()
   {
       this.lastName = new String("???");
       this.firstName = new String("???");
   }
   public Guest(String guestInfo) {

       String[] tokens = guestInfo.split("/");
       this.lastName = tokens[1];
       this.firstName = tokens[0];
   }
   public String getLastName() {
       return lastName;
   }
  
   public String getFirstName() {
       return firstName;
   }
  
   @Override
   public String toString() {
       return this.firstName.substring(0,1) + "." + this.lastName.substring(0,1)+".";
   }
}


-------------------------------------------------------------------------------------------------------------------

AuditoriumSeating.java

---------------------------------------------------------------------------------------------------------------------

package somePackage;

import java.util.Arrays;

public class AuditoriumSeating {

   Guest[][] seating;
  
  
  
   public AuditoriumSeating(int rowNum, int columnNum) {
       this.seating = new Guest[rowNum][columnNum];
       for(int i= 0;i<rowNum;i++)
       {
           for(int j= 0;j<columnNum;j++)
           {
               seating[i][j] = new Guest();
               //System.out.print(i+","+j+" ");
           }
           //System.out.print(" ");
       }      
      
   }

   private Guest getGuestAt(int row, int col)
   {
       return seating[row][col];
   }
  
   public boolean assignGuestAt(int row, int col, Guest tempGuest)
   {
       Guest currentGuest = getGuestAt(row,col);
      
       if(currentGuest.getFirstName().equals("???") && currentGuest.getLastName().equals("???") )
       {
           seating[row][col]=tempGuest;
           return true;
          
       }  
      
       else
           return false;
   }

   public boolean checkBoundaries(int row, int col) {
       if(row<0 || col<0 || row>=seating.length || col>=seating[0].length)
           return false;
       else
           return true;
   }

   @Override
   public String toString() {
       StringBuilder result = new StringBuilder();
       for(int i= 0;i<seating.length;i++)
       {
           for(int j= 0;j<seating[0].length;j++)
           {
               result.append(seating[i][j].toString()+ " ");
           }
           result.append(" ");
       }      
       return result.toString();
   }
  
  
}


---------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote