Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to complete this expanse tester class. I have the incomplete code, the instructions for the complete code are below. 1. ExpanseTester - with

I have to complete this expanse tester class. I have the incomplete code, the instructions for the complete code are below.

1. ExpanseTester - with a main method that completely tests the Travelers and Spaceship classes.

1. Using a file for input saves times and provides an easy way to test your program. Using the command line argument in Eclipse is simple and allows file processing.

2. Included on elearning is the beginnings of this class that is coded to use a text file and command line argument to populate the AvailableTravelers class with the required Travelers (see below).

3. Please use this class as a start to your program as we will use this class and the file structure to test your code.

4. 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.

3. See elearning for sample ExpanseTester

5. Develop a text-based menu system similar to Project 2 .

1. Executes the text-menu with the following options

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

========INCOMPLETE TESTER CLASS BELOW

import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException;

public class ExpanseTester {

public static void main(String[] args) throws IOException { BufferedReader inputStream = new BufferedReader(new FileReader(args[0])); String pName = ""; Location pLocation = null; SeatCatagory pCat = null; double pCost = 0; int pRewardPoints = 0; Traveler newTraveler = null; String cName = ""; Location cLocation = null; String cPosition = ""; double cPay = 0; int cFHours = 0; AvailableTravelers travList = new AvailableTravelers(); String line = inputStream.readLine(); while(line != null) { String[] lineArray= line.split(","); if(lineArray[0].equalsIgnoreCase("p")) { pName = lineArray[1]; pLocation = Location.valueOf(lineArray[2]); pCat = SeatCatagory.valueOf(lineArray[3]); pCost = Double.parseDouble(lineArray[4]); pRewardPoints = Integer.parseInt(lineArray[5]); newTraveler = new Passenger(pName,pLocation,pCost,pCat,pRewardPoints); travList.addTraveler(newTraveler); }else { if(lineArray[0].equalsIgnoreCase("c")) { cName = lineArray[1]; cLocation = Location.valueOf(lineArray[2]); cPosition = lineArray[3]; cPay = Double.parseDouble(lineArray[4]); cFHours = Integer.parseInt(lineArray[5]); newTraveler = new Crew(cName,cLocation,cPosition,cPay,cFHours); travList.addTraveler(newTraveler); } } line = inputStream.readLine(); } System.out.println(travList);

}

}

TRAVELER CLASS

======= public abstract class Traveler { int nextIDNum = 1000; String name; int id; String location; public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setID(int nextIDNum){ this.id = id; } public String getLocation() { return this.location; } public void setLocation(String location) { this.location = location; } public int getId() { return this.id; } public abstract String toString(); public abstract void move(SpaceShip a); }

Available Class =========

public class AvailableTravelers { private Traveler[] travelers; int numOfTravelers; public AvailableTravelers() { travelers = new Traveler[20]; numOfTravelers = 20; } public AvailableTravelers(int capacity) { travelers = new Traveler[capacity]; numOfTravelers = 0; } public boolean addTraveler(Traveler t) { if (numOfTravelers >= travelers.length) return false; for (int i=0; i

Crew Class========

class Crew extends Traveler { private String position; private double pay; private int flightHours; public Crew() { super(); } public Crew(String name, double pay, int id, String position, int flightHours, String current) { super(name, id, current, pay); this.flightHours = flightHours; this.position = position; } //this uses polymorphism to adjust flighthours @Override void move(SpaceShip s) { this.flightHours += s.getFlightHours(); } //this uses polymorphism to adjust the toString Method @Override public String toString() { return "[name="+ super.getName()+", id="+ super.getId()+", current="+ super.getCurrent()+ "position = " + this.position + "pay = " + super.getPay() + "$, " + "flight hours = " + this.flightHours + "]";

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Tell the merits and demerits of Mendeleev's periodic table.

Answered: 1 week ago