Question
PLEASE HELP Please fi the code bellow in java (eclipse) Why this code do not work? The output the table with name, date, age, country
PLEASE HELP
Please fi the code bellow in java (eclipse)
Why this code do not work?
The output the table with name, date, age, country etc.
How to change it in Java:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList;
import travel.PassengerTemplate; import vision.TVShowTemplate; public class Travel { static ArrayList ListPassengers = new ArrayList(); public static void main(String[] args) { InputStreamReader inp = null; BufferedReader input = null; int nOption = 0; try { inp = new InputStreamReader(System.in); input = new BufferedReader(inp); while(true) { System.out.println("1. Enter Passenger(s)"); System.out.println("2. Modify Passenger"); System.out.println("3. Delete Passenger"); System.out.println("4. Sort TV Shows."); System.out.println("5. Show all Passengers"); System.out.println("6. Exit."); System.out.println(" Choose an option(1-6) : "); nOption = Integer.parseInt(input.readLine()); switch(nOption) { case 1: AddPassenger(input); break; case 2: ModifyPassenger(input); break; case 3: DeletePassenger(input); break; case 4: ShowAllPassengers(); break; case 5: System.out.println("Exiting program."); input.read(); System.exit(0); break; } } } catch(Exception exp) { } } private static void AddPassenger(BufferedReader input) throws IOException { PassengerTemplate tmpObject = null; while(true) { tmpObject = new PassengerTemplate(); System.out.println("Enter the name: "); tmpObject.Name = input.readLine().toString(); System.out.println("Enter the date of travel: "+tmpObject.Name+"(Sun,Mon,Tue....): "); tmpObject.Day = input.readLine().toString(); System.out.println("Enter the age: "); tmpObject.Age = input.readLine().toString(); System.out.println("Do you have any health problems? (yes/no)"); tmpObject.Prob = input.readLine().toString(); System.out.println("Enter the country: "); tmpObject.Country = input.readLine().toString(); System.out.println("Enter the passport number: "); tmpObject.Passport = input.readLine().toString(); if(tmpObject != null) ListPassengers.add(tmpObject);
System.out.println(" Do you want to add another Passenger?(y/n): "); if(!input.readLine().toLowerCase().equals("y")) break; } } private static void ModifyPassenger(BufferedReader input) throws IOException { PassengerTemplate tmpObject = null; System.out.println("Passenger's name to modify: "); String OldName = input.readLine(); int index = getTVShowIndexByName(OldName); if(index == -1) { System.out.println(" Passenger " + OldName+ " not found."); } else { tmpObject = (PassengerTemplate)ListPassengers.get(index); showPassenger(tmpObject); System.out.println("What you want to modify (Name|Day|Country)?: "); String strOption = input.readLine(); if("name".equals(strOption.toLowerCase())) { System.out.println("New Passenger's Name: "); tmpObject.ShowName = input.readLine().toString(); } else if("day".equals(strOption.toLowerCase())) { System.out.println("New Day "+tmpObject.Name+"(Sun,Mon,Tue....) : "); tmpObject.Day = input.readLine().toString(); } else if("age".equals(strOption.toLowerCase())) { System.out.println("New Age: "); tmpObject.Age = input.readLine().toString(); } else if("country".equals(strOption.toLowerCase())) { System.out.println("New Country: "); tmpObject.Country = input.readLine().toString(); } else if("passport".equals(strOption.toLowerCase())) { System.out.println("New Passport's number: "); tmpObject.Passport = input.readLine().toString(); } else { System.out.println("Unable to locate the propety entered.."); } ListPassengers.set(index, tmpObject); } }
private static int getTVShowIndexByName(String Name) { int index = -1; PassengerTemplate tmp =null; for(int i=0;i private static void DeletePassenger(BufferedReader input) throws IOException { System.out.println("Name of the Passenger to delete: "); String OldName = input.readLine(); int index = getTVShowIndexByName(OldName); if(index == -1) { System.out.println(" Passenger " + OldName+ " not found."); } else { ListPassengers.remove(index); System.out.println(" Passenger " + OldName+ "deleted successfully."); } } private static void ShowAllPassengers() { System.out.println("** Passenger management **** "); System.out.println("Name\t\tDay\tAge"); for(int i=0;i showName((PassengerTemplate)ListPassengers.get(i)); } } } class PassengerTemplate { public String Passport; public String Country; public String Prob; public String Age; public String Name; public String ShowName = ""; public String Day = ""; }
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