Results 1 to 3 of 3
- 10-14-2009, 11:10 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 1
- Rep Power
- 0
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
-
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!
- 10-15-2009, 09:56 AM #3
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 10
Similar Threads
-
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum
By tlouvierre in forum New To JavaReplies: 14Last Post: 05-28-2009, 05:44 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
[SOLVED] instantiating a class from other classes of different types...
By olbion in forum New To JavaReplies: 2Last Post: 05-05-2008, 10:55 AM -
How to Merge all classes into One class
By jazz2k8 in forum New To JavaReplies: 12Last Post: 04-23-2008, 03:40 AM -
[SOLVED] Using classes and overriding one class for another
By StealthRT in forum New To JavaReplies: 3Last Post: 04-08-2008, 07:12 AM
Bookmarks