Results 1 to 3 of 3
  1. #1
    cool_guy364 is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Default java reservation class plane seat and reservation classes

    i need help writing out the code i thought it through did some and stuck on some,,

    Java Code:
    import java.util.Scanner;
    
    /*
    	Complete the Seat class.
     */
    class Seat {
    
    /*
    	It has 4 private instance variables:
    		an int called row (the row number 1 to whatever)
    		a char called letter (the seat letter A to whatever)
    		a boolean called occupied (true if occupied, false if not)
    		and a String called name (the name of the person who reserved the seat)
    */
    
    
    private int row;
    private char letter;
    private boolean occupied;
    private String name;
    
    
    /*
    	Make a constructor to set the row and letter instance variables
     */
    
    public Seat(int row, char letter) {
    	super();
    	this.row = row;
    	this.letter = letter;
    }
    
    
    /*
    	Make a method called book that has a single parameter called name which is a String
    	and that returns nothing. Set the name and make occupied true.
    */
    
    public void book (String name){
    name=name;
    occupied=true;
    
    }
    
    /*
    	Make a getter method called getName to return the name
    */
    
    public String getName() {
    	return name;
    }
    
    /*
    	Make a method called isBooked that returns the variable occupied
    */
    
    public boolean isBooked() {
    return occupied;
    }
    
    /*
    	Make a toString method that returns a string representing the row and letter, e.g. 3B
    */
    
    	public String toString(){
    
    		return 	"seat:" +row+letter;
    }
    
    
    
    
    }
    
    
    
    /*
    	Complete the Plane class.
     */
    
    class Plane {
    
    /* Make two private instance variables:
    	a 2D array of type Seat called seats
    	an int called bookings which will contain the total number of booked seats.
    */
    
    Seat [][] seats ;
    int bookings;
    
    
    /* Make a constructor for the plane class that takes two int parameters,
       one for the number of rows and one for the number of columns
       It should instantiate seats (create with new keyword) and then fill up the array of seats.
       Hint: use casts (char) to fill the letters. 'A' is the number 65, 'B' is the number 66 and so on
       	seats[0][0] should contain new Seat(1,'A')
       	seats[1][0] should contain new Seat(2,'A')
       	seats[0][1] should contain new Seat(1,'B')
    */
    
    public Plane (int rows, int columns) {
    
    }
    
    
    /*
    	make a method called book that returns a boolean and that takes an integer called row
    	and a char called col and a String called name as its parameters. If the seat is already
    	booked just return false, otherwise	book the seat, increase the number of bookings variable
    	and return true.
    	Hint: you need to subtract from int row and from char col
    	to get the position of the seat in the array.
    */
    
    
    
    
    /*
    	Complete the report method which returns a String that contains
    	a list of all bookings on the plane
    	Sample:
    		3A Ahmed Jamal
    		5D Khaled Eman
    		7B Amani Ibrahim 	etc...
     */
    	public String report(){
    		String result="";
    
    
    
    		return result;
    	}
    
    
    /*
    	Complete the toString method that returns the plane avaiable seating arrangement.
    	If the seat is booked use -- to indicate it.
    	Sample:
    		1A 1B -- 1D
    		-- 2B 2C 2D
    		3A -- 3C --
    		-- -- -- 4D
     */
    	public String toString(){
    		String result="";
    
    
    
    
    		return result;
    	}
    
    }
    
    
    /*
    	Complete the Reservations program.
     */
    
    
    public class Reservations {
    
    
    	public static void main(String[] args){
    
    // create a plane called shuttle with 9 rows and 4 seats on each row.
    
    
    // make a Scanner object called keys
    
    
    
    		boolean done=false;
    		while(!done){
    
    			System.out.println("Enter B to book a seat\nR to see the reservation report"+
    				"\nS for the available seats\nQ to quit:");
    
    // make a char called response
    
    // read in the user letter using next() and get its first letter using charAt and assign it to response
    
    
    
    			System.out.println();
    /* use a switch statement on the response.
    	If it is an R print out the report
    	If it is an S print out the shuttle
    	If it is a Q set done to true
    	If it is a B, print out "enter row number, space, row letter then name:"
    	and then read in the first number using nextInt then the next word using
    	next() and get the char using charAt. Finally use nextLine() to read in the name.
    	If it is booked print out "That seat is taken". Print some empty lines
    	If there is none of the above letters then continue (use the default)
    */
    
    
    
    
    		}
    
    
    
    
    	}
    
    }
    Last edited by Fubarable; 10-15-2009 at 12:38 AM. Reason: Code tags added for readability

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cool_guy364 View Post
    i need help writing out the code i thought it through did some and stuck on some,,
    Hello and welcome to the forum!

    A few suggestions to help make it easier for others to help you
    1) Use code tags when posting code as this makes your code readable. I've taken the liberty of adding code tags to your post above (if you edit the post, you'll see where I've done this), and I hope you don't mind.

    2) Ask specific questions if possible. We do much better at answering questions like:
    "I tried to solve X problem by trying Y, but instead of Z I'm getting Q."

    Rather than very general and vague statements such as
    "I need help and I'm stuck".

    How do you need help? What do you need help on? Most general questions are answered with a referral to this or that tutorial while most specific questions are given specific answers.

    Much luck with your project and your java education, and again, welcome!

  3. #3
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    brr... The code is hurting my eyes.

    It's not really readable, formatted like this...
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  2. Replies: 0
    Last Post: 05-13-2008, 06:16 AM
  3. Replies: 2
    Last Post: 05-05-2008, 10:55 AM
  4. How to Merge all classes into One class
    By jazz2k8 in forum New To Java
    Replies: 12
    Last Post: 04-23-2008, 03:40 AM
  5. Replies: 3
    Last Post: 04-08-2008, 07:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •