Question
CAN SOMEONE PLEASE HELP ME WITH THIS JAVA PROJECT? Project Requirements: 1. The Classes from Project 2 (Traveler and Spaceship) will be reused with the
CAN SOMEONE PLEASE HELP ME WITH THIS JAVA PROJECT?
Project Requirements: 1. The Classes from Project 2 (Traveler and Spaceship) will be reused with the modifications listed in the class description. 1. Starter code for these classes is provided, but feel free to use your own if you prefer. 2. SeatCategory class - the class for identifying the three SeatCategories: 1. The options are NOSEAT, FIRST, BUSINESS, COACH. 2. Implement the SeatCategory class as a Java Enum https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html 3. Traveler Class 1. Abstract class. 2. Instance variables and static nextIdNum same as project 2. 3. Methods 1. Constructors and methods same as project 2 except: 2. Abstract toString method as each class will provide a different version. 3. Abstract addFlightToHistory which takes an int representing the flight duration 4. Passenger Class 1. Subclass of Traveler class. 2. A class that stores specific Passenger information such as flight cost, seat class and rewards program status. 3. Instance Variables 1. cost double representing the cost of the flight based on the following 1. First class - $1499.99 2. Business class - $998.00 3. Coach - $449.00 2. seat current SeatClass of the passenger. 3. rewardsPoints int representing the number of rewards points of the passenger. 4. Methods 1. Default constructor sets all instance variables to a default value 1. Call the super class constructor passing appropriate parameters to it. 2. Set the rest of the variables to a default value. 3. Attempts to upgrade passenger if possible, using rewardUpgrade function defined below. 2. Parameterized Constructor 1. Takes in all parameters required to set the instance variables including super classs instance variables. 2. Cost should be set based on seat class. 3. Accessor and mutator methods as needed. Please note that if the seat category changes the cost must change. 4. rewardUpgrade 1. private method 2. Upgrades the passenger if they have more than 10,000 points based on the following 1. If not already first class, upgrades the passenger to first class. 2. If already first class, discounts the cost by 20%. 3. Subtracts 10,000 rewards points. 5. toString 1. Overwrites the super class method as needed to returns a nicely formatted String (see below) that represents the state of the object (the value of the instance variables) 2. Passenger [name=Klaes Ashford, id=3, current=BELT, seat=FIRST, cost = $1499.99, rewardsPoints = 3459] 6. addFlightToHistory 1. Adds 10* flightDuration points to this travelers rewardsPoints 5. Crew class 1. Subclass of Traveler class. 2. A class that stores specific Crew information such as position and number of flight hours. 3. Instance variables 1. position - String repressing their rank such as Captain, Co- Captain, Crewman. 2. flightHours - int representing their number of flight hours: String 4. Methods 1. Default constructor set all instance variables to a default value. 2. Parameterized constructor - Takes in all parameters required to set the instance variables including super classs instance variables. 3. Accessor/mutator methods. 4. toString 1. Overwrites the super class method as needed to return a nicely formatted String (see below) that represents the state of the object (the value of the instance variables) 2. Crew [name=Klaes Ashford, id=3, current=BELT, position = Captain, flight hours = 6728] 5. addFlightToHistory 1. Adds flightDuration hours to the crew members flightHours 6. Spaceship Class 1. Similar to Project 2 with the following modification 2. Instance variables 1. tripLength int representing the number of flight hours of the route flown by this spaceship rounded to the nearest int. 3. Methods 1. Default constructor sets all instance variables to a default value include new instance variables. 2. Parameterized Constructor 1. Takes in all parameters required to set the instance variables. 3. move method same functionality as Project 3 with the following modification 1. boolean method 1. returns true if moved allowed 2. returns false if moved not allowed. 2. Calls addFlightToHistory for all travelers on board 4. public String toString() 1. returns a nicely formatted String (see below) that represents the Spaceship object information as well as a list of all Travelers. 2. Display a list of all Travelers on the flight (hint call the toString on each Travelers object in the array) Spaceship [name=Behemoth, current=RING, destination=EARTH, capacity=20, travelers=10, tripLength = 20] Crew [name=Klaes Ashford, id=3, current=BELT, position = Captain, flight hours = 6728] Passenger [name=Klaes Ashford, id=3, current=BELT, seat=FIRST, cost = $1499.99, rewardsPoints = 3459] 7. AvailableTravelers 1. A class contains the Traveler object available for travel 2. Instance variables 1. travelers - a collection of Traveler objects. 2. numOfTravelers number of travelers in the collection (partially filled array value) 3. Methods 1. Default constructor 1. creates array to a size of 20 and 2. setsnumOfTravelersto0. 2. Parametrized constructor 1. Creates array and sets its size to the value of a parameter representing the capacity. 2. setsnumOfTravelersto0. 3. public boolean addTraveler(Traveler t) 1. adds the given Traveler to the array. 2. Increments numOfTravelers 3. returns false if the Traveler is already in the arry (test by ID) or the list is at capacity, 4. returns true if Travleler successfully added to array. 4. public Traveler findTravelerByName(String name) 1. returns the Traveler with the given name 2. null if not found. 5. public String toString - return a nicely formatted String (see below) that represents each traveler in the array. (hint call the toString on each Travelers object in the array) Crew [name=Klaes Ashford, id=3, current=BELT, position = Captain, flight hours = 6728] Passenger [name=Klaes Ashford, id=3, current=BELT, seat=FIRST, cost = $1499.99, rewardsPoints = 3459] 8. ExpanceTester - with a main method that completely tests the Travelers and Spaceship classes. 1. Initially the program creates an AvailableTravelers object and populates it with 1. 10 Travelers of which 4 are Passenger and 6 are Crew members (2 Captains, 2 Co-Captains and 2 crew members) 2. Two Space Ship with no travelers. 2. Develop a text-based menu system similar to Project 2 . 1. Executes the text-menu with the following options (Parts 2-4 below) 1. Add traveler to a Spaceship from the AvailableTravelers object 2. Search for traveler on a Spaceship 3. Move a spaceship to a new location 4. Displays a list of Available Travelers 5. Display of list of Travelers on a specific SpaceShip (Id by name) 6. Exit the program 7. Create UML Class Diagram for the final version of your project. The diagram should include: 1. The Traveler, Passenger, Crew, Spaceship and AvailableTravelers classes 2. All instance variables, including type and access specifier (+, -); 3. All methods, including parameter list, return type and access specifier (+, -); 4. Include Generalization and Aggregation where appropriate. 5. The ExpanseTester does not need to be included. 6. Refer to the UML Distilled pdf on the content page as a reference for creating class diagrams. 7. A Link to a drawing program, Dia, is also posted on the content page.
CODE FOR TRAVELER CLASS: (any changes I have already tried to make have comments next to them so I am not 100% sure they are correct)
public abstract class Traveler { // made abstract class private String name; private static int paxCreated = 0; private int id; private Location location; Traveler () { this("Bubba"); System.out.println("Name is required. Calling this traveler Bubba"); } Traveler (String name) { this(name, Location.EARTH); System.out.println("Location is required. Calling this location EARTH"); } Traveler (String name, Location location) { this.name = name; this.location = location; this.id = ++Traveler.paxCreated; } public abstract String toString (); // made abstract method and removed method body public abstract int addFlightToHistory(); // abstract addFlightToHistory method public Location getLocation () { return this.location; } public String getName () { return this.name; } public int getId () { return this.id; } public void setLocation (Location l) { this.location = l; } }
CODE FOR SPACESHIP CLASS: (any changes I have already tried to make have comments next to them so I am not 100% sure they are correct)
public class Spaceship { private String name; private Location currentLocation; private Location destination; private int capacity; private int numberOfCrew = 0; private static int tripLength; //tripLength initialized private Traveler[] crew; final private static int DEFAULT_CAPACITY = 10; Spaceship () { this(null, null, null, DEFAULT_CAPACITY, tripLength); System.out.println("This is going to be bad news, no values are set"); } Spaceship (String name, Location currentLocation, Location destination, int capacity, int tripLength) { this.name = name; this.currentLocation = currentLocation; this.destination = destination; this.capacity = capacity; this.crew = new Traveler[capacity]; this.tripLength = tripLength; } public boolean board (Traveler t) { if (this.canBoard(t)) { this.crew[numberOfCrew++] = t; return true; } return false; } public boolean goAshore (Traveler t) { if (this.isOnBoard(t)) { this.remove(t); return true; } return false; } private void remove (Traveler t) { for (int i = 0; i < this.numberOfCrew; i++) { if (crew[i].getId() == t.getId()) { for (int j = i; j < numberOfCrew-1; j++) { crew[j] = crew[j+1]; } crew[--numberOfCrew] = null; break; } } } public void move () { Location temp = this.currentLocation; this.currentLocation = this.destination; this.moveCrew(); this.removeCrew(); this.destination = temp; } private void moveCrew () { for (int i = 0; i < this.numberOfCrew; ++i) { this.crew[i].setLocation(this.destination); } } private void removeCrew () { this.crew = new Traveler[capacity]; this.numberOfCrew = 0; } private boolean canBoard (Traveler t) { return numberOfCrew < capacity && t.getLocation() == this.currentLocation && !this.isOnBoard(t); } public boolean isOnBoard (Traveler t) { boolean travelerFound = false; for (int i = 0; i < this.numberOfCrew; ++i) { if (this.crew[i].getId() == t.getId()) { travelerFound = true; break; } } return travelerFound; } public boolean searchByName (String name) { boolean travelerFound = false; for (int i = 0; i < this.numberOfCrew; ++i) { if (this.crew[i].getName().equals(name)) { travelerFound = true; break; } } return travelerFound; } public String getName () { return this.name; } public String toString () { return "[name="+this.name+", current="+this.currentLocation+", destination="+this.getDestination()+", capacity="+this.capacity+", crew="+this.numberOfCrew+"]"; } public String getDestination () { if (this.destination != null) { return ""+this.destination; } return "NULL"; } }
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