Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:28:14+00:00 2026-06-03T07:28:14+00:00

This is for coursework. I’ve built the whole program, and it does everything right,

  • 0

This is for coursework. I’ve built the whole program, and it does everything right, apart from this one thing.

I have a class called ‘Schedule’ this method is at the very end of schedule:

public void bookSeatMenu()
    {   boolean leaveBookSeatMenu = false;
        String seatBookingMenuStr;
        int seatBookingMenuInt = 14;
        boolean isInteger = false;
        Scanner input = new Scanner(System.in);
        System.out.println("Press 1 to add an individual booking, 2 to cancel a booked seat or 3 to go back");

        seatBookingMenuStr = input.nextLine();
                  try {
                      seatBookingMenuInt = Integer.parseInt(seatBookingMenuStr);
                      isInteger = true;
                    }

                    catch (NumberFormatException e) {

                    }
                  switch (seatBookingMenuInt) {
                      case 1: 
                        bookSeat();
                        break;
                      case 2:
                        cancelSeat();
                        break;
                      case 3:
                        leaveBookSeatMenu = true;
                        break;
                      default:
                        System.out.println("Invalid Choice");
                    } while (leaveBookSeatMenu == false);

                } 

I know you all know what a switch menu looks like, but I thought I’d throw it in there anyway, in case (pardon the pun) I’m going wrong here.

Moving on, I have the bookSeat method, this is where the user books a seat (which works fine). Then afterwards it displays the bookSeatMenu() just it displays the menu. But then it won’t go back to the previous one.

   public void bookSeat()
   {
       Scanner input = new Scanner(System.in);
       boolean isSeatBooked = true;
       showSeatPlan();
       int seatNum = 0;
       int rowNum = 90;
       int columnNum = 16;
       boolean isInt = false;

       while (isSeatBooked == true)
       {
           System.out.println("Please pick column of a seat to book");
           columnNum = input.nextInt();

           System.out.println("Please pick row of a seat to book");
           rowNum = input.nextInt();


           seatNum = (columnNum + ((rowNum) * 15));

           if (seats[seatNum] == false)
           {
               isSeatBooked = false;
           }
           else
           {
               System.out.println("This seat is already booked");
            }
       }

       seats[seatNum] = true;


       System.out.println("");
       bookSeatMenu();
   }

Now not for love nor money am I able to get it to go back to the previous menu after it’s booked a seat.

Basically the process is:

Book a seat –> go to bookSeatMenu –> press 4 to go back –> Arrive at previous menu.

If I don’t book a seat, the program will happily go back to the menu before hand, but after, it just keeps on going on to a new line in the command prompt, not doing anything else, no error etc.

I’m pretty tempted to say this might be a problem with BlueJ, although a bad workman blames his tools, and I don’t wanna be ‘that guy’

I also need to make a ‘testing class’ – having never used a ‘testing class’ before, and the assignment asking us to look in the ‘textbook’ which noone bothered to buy, I actually have no idea!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:28:16+00:00Added an answer on June 3, 2026 at 7:28 am

    There’s no switch...while so I assume your problem is as soon you do choose 3, you end up in while(true); which is an infinite loop.

    correct pseudo-code:

    do {
       // read System.in
    
       // handle menu options with your switch
    } while(...)
    

    By the way, design is bad IMHO, you should try to think about your model (in your case I would see something like Room, Seat, Scheduler, Menu) and make those object interact with each others :

    public class Room {
        private Seat[][] seats;
        public String toString() {
            // like showSeatPlan() using toString() of Seat
        }
    }
    
    public class Seat {
        private int row, column;
        private boolean isBooked;
        public void book() { /* ... */ }
        public void cancel() { /* ... */ }
        public String toString() { /* "X" or " " */ }
    }
    
    public final class Scheduler {
       // "main class" with a "main" method
    }
    
    public class Menu {
        private Room room;
        public String toString() {
            // print out menu
        }
        public void bookSeat() { /* ... */ }
        public void cancelSeat() { /* ... */ }
    }
    

    (something like that)

    For the test part, each class have a test class and each method have a test method, as an example, for Seat:

    public class Seat {
        public void book() { 
            if (this.isBooled) {
               throw new CannotBookException("seats is taken!");
            }
            this.isBooled = true;
        }
    }
    
    public class SeatTest {
        @Test // when I book a seat, it's markedas booked.
        public void testBook() {
            final Seat seat = new Seat();
            seat.book();
            assertTrue(seat.isBooked)
        }
    
        @Test(expected = CannotBookException.class) // when I book an already booked seat, I get an exception.
        public void testBookAlreadBooked() {
            final Seat seat = new Seat();
            // book the seat
            seat.book();
            assertTrue(seat.isBooked)
    
            // try to book again
            seat.book();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say i have a object like this public class Student{ public IList<Coursework> Courseworks{get;set;} public
So this is from a uni coursework and is my first time working with
I took this from an online MIT courseware discussion (pdf warning): public class Human
Before anything, yes, this is from coursework and I've been at it sporadically while
I have this question in a Compilers coursework but I don't really know how
I am working on a piece of coursework and part of this involves me
This has been a rather problematic issue on numerous occasions. We have alot of
I'm doing some coursework for uni, I really should know this but I am
I've recently set some coursework for some undergraduate students for which they have to
so for my university coursework, i have to create an oracle database for an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.