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

Does this Java Program look correct? First, let me paste the question: Five frie

ID: 674504 • Letter: D

Question

Does this Java Program look correct? First, let me paste the question:

Five friends are going to the theater. They have purchased a row of five seats with an aisle on either end.

James doesn't want to sit next to Jill

Betty and Herb are dating and want to sit next to each other

Bob must sit on an aisle

Provide a seating order that conforms to the above rules. An example of an invalid seating order is:

James, Betty, Herb, Bob, Jill

The above arrangement is invalid because: Bob is not sitting on an aisle.

Specify the seating order as the names separated by commas (as in the above example). Please be sure to spell the names correctly, including capitalization.

My Program:

public class Seating{
   public static void main (String [] args){
       String James;
       String Jill;
       String Betty;
       String Herb;
       String Bob;
       system.output.println(Bob + "," + Jill + "," + Herb + "," + Betty + "," + James + ".";
   }
}

Explanation / Answer

// The code is wrong because the string variables hold garbage value when defined.
//You can also directly print the names instead of keeping them in string variable.
//It's not system.output.println it is System.out.println.
//Also there are also possible seating arrangements.I'm printing them,you can remove those lines if you don't want them.
public class Seating
{
   public static void main (String [] args)
   {
       String James="James";
       String Jill="Jill";
       String Betty="Betty";
       String Herb="Herb";
       String Bob="Bob";
       System.out.println(Bob + "," + Jill + "," + Herb + "," + Betty + "," + James);
       System.out.println(Bob + "," + Jill + "," + Betty + "," + Herb + "," + James);
       System.out.println(Bob + "," + James + "," + Herb + "," + Betty + "," + Jill);
       System.out.println(Bob + "," + James + "," + Betty + "," + Herb + "," + Jill);
      
       System.out.println(Jill + "," + Herb + "," + Betty + "," + James + "," + Bob);
       System.out.println(James + "," + Herb + "," + Betty + "," + Jill + "," + Bob);
       System.out.println(Jill + "," + Betty + "," + Herb + "," + James + "," + Bob);
       System.out.println(James + "," + Betty + "," + Herb + "," + Jill + "," + Bob);
   }
}

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