4. SpaceShipTester class with a main method: A text-based driver program that pe
ID: 3754338 • Letter: 4
Question
4. SpaceShipTester class with a main method: A text-based driver program that performs the following steps a. It asks for four Travelers and two StarShips (Part 1, below) b. It executes a text-menu with the following options (Parts 2-4 below) . Add traveler to a Spaceship n. Search for traveler on a Spaceship 1. Move a spaceship to a new location tw. Exit the program Sample run Part 1: Define Travelers and Ships Data for Traveler 1 Name: Naomi Current: EARTH Traveler 1 Traveler [name-Naomi, id-1, current-EARTH] Data for Tráveler2 Name: Klaes Current: MARS Traveler 2 Traveler [name-Klaes, id-2, current MARS] Data for Traveler 3 Name: Lucinda Current: MOON Current: BELT Traveler 3 Traveler [name-Lucinda, id-3, current-BELT] Data for Traveler 4 Name: Amos Current: MARS Travelen 4 Trayele Iname Amos. id 4, Current-MARS ]Explanation / Answer
please give thumbs up, thanks
import java.util.Scanner;
/**
*
* @author VISHAL
*/
public class SpaceShipTester {
public static void main(String []args)
{
int choice;
int ID=1;
String name,Current;
Scanner sc=new Scanner(System.in);
SpaceShip S=new SpaceShip();
while(true)
{
System.out.println("1. Add traveler to a SpaceShip");
System.out.println("2. Search for traveler on a SpaceShip");
System.out.println("3. Move spaceship to a new Location");
System.out.println("4. Exit");
choice=Integer.parseInt(sc.nextLine());
switch(choice)
{
case 1:
System.out.println("Data for Traveler "+ID);
System.out.print("Enter Name: ");
name=sc.nextLine();
System.out.print("Current: ");
Current=sc.nextLine();
System.out.println("Traveler "+ID+" Traveler[name="+name+", current="+Current+"]");
S.addTraveller(ID,name,Current);
ID++;
break;
case 2:
System.out.print("Enter Name: ");
name=sc.nextLine();
if(S.serachName(name))
System.out.println("Traveler "+name+" is in Spaceship");
else
System.out.println("Traveler "+name+" is not in Spaceship");
break;
case 3:
System.out.print("Enter new Location for SpaceShip : ");
String location=sc.nextLine();
S.moveSpaceShip(location);
System.out.println("SpaceShip is Moved");
break;
case 4:
System.exit(0);
break;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.