77.3k views
4 votes
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 + ".";}}

1 Answer

5 votes

Answer:

Your code does indeed look correct.

Step-by-step explanation:

Declaring the variables seems pretty straightforward as well as the println statement. In terms of the ordering, it seems pretty good. Since Bob wants to sit on an aisle and it's not specified, he can go first. Since Jill wants to be away from James who is on the other aisle, she goes 2nd. Since Betty and Herb are dating, putting them before James seems like the most logical choice.

You could also set it up so that Bob goes Last, James goes First with Betty, James and Jill switching places (the order being James, Betty, Herb, Jill and Bob), but again your code is correct so it shouldn't matter.

Thanks, let me know if this helped!

User Nivcaner
by
5.1k points