Question
(JAVA QUESTION) Your goal is to design and implement a simple Cruise Line Information System to keep track of rooms and passengers on a cruise
(JAVA QUESTION)
Your goal is to design and implement a simple Cruise Line Information System to keep track of rooms and passengers on a cruise ship. You will do this in two steps. First you need to implement a Room class and a Passenger class. Test them completely in a driver. Then, you will implement a Cruise class that represents the entire system. Basically, a cruise will contain a number of rooms and a number of passengers. Then you will make a Cruise Driver which will test the Cruise class.
Step 1:
1.Create a class Passenger that can be used to represent a passenger on a cruise line. The class should at least have the following instance variables:
name String
address String
roomNumber int
Create 3 constructors(fully qualified, no argument(use the keyboard to enter values), copy constructor). Make setters/getters. Make an equals method that compares the names. Make a toString that formats output like:
Passenger: Ann Foley
Philadelphia
Room Number: 1
2. Create a class called Room that represents a room on a cruise ship. This class should have the following instance variables:
roomNumber int
isOccupied boolean
guest Passenger that stores a reference to the Passenger object that stays in that room.
Implement all constructors, accessors and mutators, toString and equals methods.
See for a start : Room Fill in the missing parts
3. Write a simple driver (test program/class with main) that creates a single Passenger and a Room, and tests all the methods you have defined in the Passenger and Room classes. Print out information on each object right after creation, and again at the end This program is not required to be turned in. the output format should be:
Room Number: 1
Occupied
Passenger: Ann Foley
Part 2:
1. Design and implement a class Cruise . A cruise object will store the following instance variables : (Remember to import java.util.ArrayList; and make the variables private)
shipName String,
numRooms int
numPass =0 int
ArrayList of Passengers
ArrayList cruisePass = new ArrayList();
ArrayList of Rooms
ArrayList cruiseRoom = new ArrayList();
2. The constructor of the Cruise class should initialize all instance variables.
Prompt the user to enter the name of the ship and the number of rooms. You do not have to do anything to the Passenger ArrayList
public Cruise(){
//prompt user to enter name of ship, numRooms
//Build the ArrayList of Rooms
for (int i=1; i <= numRooms; i++) {
cruiseRoom.add( new Room(i, false));
}
}
3. Provide the method in the Cruise class: public void addPassenger ()
In the method you need to :
cruisePass.add(new Passenger();<--------- makes a passenger and puts in ArrayList
You have to increment the number of passengers
numPass ++;
3. On this Cruise, the first Passenger added goes in Room1. This is how you would update the room number in the Passenger ArrayList
cruisePass.get(numPass).setRoomNumber(numPass);
4. You also need to update all the Room info
cruiseRoom.get(numPass).setRoomNumber(numPass);
5. Use the setters in Room to update the Room info . (use your setGuest, and setIsOccupied) cruiseRoom.get(numPass).setIsOccupied(true);
4. Provide the method in the Cruise Class: public boolean findPassenger (String name) which takes a name as an argument, and if that name is found as one of the passenger names in the cruise, it returns a true otherwise returns false.
public boolean findPassenger(String name) {
for (int i=0; i < cruisePass.size(); i++) {
if (cruisePass.get(i).getName().equals(name))
return true;
}
return false;
}
5. Provide the toString method that formats information about the cruise, name, the room list and a list of all passengers in the cruise in the following form:
SEE HINT BELOW
Ship Name: Queen Mary
Number of Rooms: 10, Occupied: 2
Room Number: 1
Occupied
Passenger: Ann Foley
Room Number: 2
Occupied
Passenger: Fred Flintstone
Passenger: Ann Foley
Philadelphia
Room Number: 1
Passenger: Fred Flintstone
Bedrock
Room Number: 2
HINT : to do the toString for the cruise, think of it in three pieces - you keep adding on to one String.
Write out the Cruise info
Go through the ArrayList of Passengers
for(int j=0; j < numPass; j++) {<--------- or j
str+= cruisePass.get(j).toString();
}
3. Do the same type of thing as done above for Passengers - for each Room
6. Write a driver to test Cruise. It should create a Cruise ship.
Cruise queenMary = new Cruise();
It should add two Passengers .
queenMary.addPassenger();
quennMary.addPassenger();
It should print out the information as shown above.
System.out.println(queenMary.toString());
You should call findPassenger two times - one passing in the name you used to add and one a name that will return a not found.
System.out.println("Is Ann Foley on ship: "+ queenMary.findPassenger("Ann Foley"));
System.out.println("Is John Jones on ship: "+ queenMary.findPassenger("John Jones"));
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started