Question
import java.util.LinkedList; import java.util.Scanner; public class Agency { private Administrator loggedInUser; private Destinations destinations; private Flights flights; private Administrators admins; public Agency() { admins =
import java.util.LinkedList;
import java.util.Scanner;
public class Agency {
private Administrator loggedInUser;
private Destinations destinations;
private Flights flights;
private Administrators admins;
public Agency() {
admins = new Administrators();
admins.insertDummyData();
destinations = new Destinations(this);
flights = new Flights(this);
}
public Destinations getDestinations() {
return destinations;
}
public Flights getFlights() {
return flights;
}
public void login() {
Scanner scanner = new Scanner(System.in);
boolean loggedIn = false;
while (!loggedIn) {
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
if (admins.validateCredentials(username, password)) {
loggedIn = true;
loggedInUser = new Administrator(admins.getAdminName(username), username, password);
mainMenu(scanner);
} else {
System.out.println("Invalid Credentials! Try Again.");
}
}
}
public void destinationsMenu(Scanner scanner) {
System.out.println("Welcome to the Destinations section " + loggedInUser.getName() + ", Please make a selection from the menu:");
while (true) {
System.out.println("1. View All Destinations");
System.out.println("2. View Destinations by Country");
System.out.println("3. Add a Destination");
System.out.println("4. Remove a Destination");
System.out.println("X. Return to Main Menu");
System.out.print("Please enter an option: ");
String option = scanner.nextLine();
switch (option) {
case "1":
destinations.displayAllDestinations();
break;
case "2":
break;
case "3":
break;
case "4":
break;
case "X":
mainMenu(scanner);
return;
default:
System.out.println("Please enter a valid choice, or press X to exit.");
}
}
}
public void mainMenu(Scanner scanner) {
System.out.println("Welcome to the Prog2 Travel Agency " + loggedInUser.getName() + ", Please make a selection from the menu:");
while (true) {
System.out.println("1. Explore Flights");
System.out.println("2. Explore Destinations");
System.out.println("3. Book a Trip");
System.out.println("X. Exit the System");
System.out.print("Please enter an option: ");
String option = scanner.nextLine();
switch (option) {
case "1":
break;
case "2":
destinationsMenu(scanner);
break;
case "3":
break;
case "X":
System.out.println("Thanks for using the Prog2 Travel Agency.");
System.exit(0);
default:
System.out.println("Please enter a valid choice, or press X to exit.");
}
}
}
public static void main(String[] args) {
Agency agency = new Agency();
agency.login();
}
}
public class Destination {
private String country;
private String name;
public Destination(String name, String country) {
this.name = name;
this.country = country;
}
public String getCountry() {
return country;
}
public String getName() {
return name;
}
}
import java.util.LinkedList;
public class Destinations {
private LinkedList destinations;
private Agency agency;
public Destinations(Agency agency) {
this.agency = agency;
destinations = new LinkedList<>();
destinations.add(new Destination("Eiffel Tower", "France"));
destinations.add(new Destination("Opera House", "Australia"));
destinations.add(new Destination("Uluru", "Australia"));
destinations.add(new Destination("Machu Picchu", "Peru"));
destinations.add(new Destination("Great Pyramids", "Egypt"));
destinations.add(new Destination("Niagara Falls", "Canada"));
}
public LinkedList getAllDestinations() {
return destinations;
}
public LinkedList getDestinationsByCountry(String country) {
LinkedList result = new LinkedList<>();
for (Destination dest : destinations) {
if (dest.getCountry().equalsIgnoreCase(country)) {
result.add(dest);
}
}
return result;
}
public void displayAllDestinations() {
System.out.println("+----------------------+----------------+--------------+-------+-------+");
System.out.println("| Destinations |");
System.out.println("+----------------------+----------------+--------------+-------+-------+");
for (Destination destination : destinations) {
System.out.println(destination.getName() + " in " + destination.getCountry());
}
System.out.println("+----------------------+----------------+--------------+-------+-------+");
}
}
the login works i need help using the untils to header and footer and also with the test case above.
Username: david46@uts.com Password: 123 Welcome to the Prog2 Travel Agency David Dyer, Please make a selection from the menu: 1. Explore Flights 2. Explore Destinations 3. Book a Trip X. Exit the System Please enter an option: 2 Welcome to the Destinations section David Dyer, Please make a selection from the menu: 1. View All Destinations 2. View Destinations by Country 3. Add a Destination 4. Remove a Destination X. Return to Main Menu Please enter an option: 2 Country: sdfdfs No matching destinations found. Country: australia No matching destinations found. Country: Australia Destinations Opera House in Australia Uluru in Australia 1. View All Destinations 2. View Destinations by Country 3. Add a Destination 4. Remove a Destination X. Return to Main Menu Please enter an option: X Welcome to the Prog2 Travel Agency David Dyer, Please make a selection from the menu: 1. Explore Flights 2. Explore Destinations 3. Book a Trip X. Exit the System Please enter an option: X Thanks for using the Prog2 Travel Agency.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer Heres an updated version of your code addressing some of these points import javautilLinkedList import javautilScanner public class Agency private Administrator loggedInUser private Destinations destinations private Flights flights private Administrators admins public Agency admins new Administrators adminsinsertDummyData destinations new Destinationsthis flights new Flightsthis public Destinations getDestinations return destinations public Flights getFlights return flights public void login Scanner scanner new ScannerSystemin boolean loggedIn false while loggedIn SystemoutprintUsername String username scannernextLine SystemoutprintPassword String password scannernextLine if adminsvalidateCredentialsusername password loggedIn true loggedInUser new AdministratoradminsgetAdminNameusername username password mainMenuscanner else SystemoutprintlnInvalid Credentials Try Again public void destinationsMenuScanner scanner SystemoutprintlnWelcome to the Destinations section loggedInUsergetName Please make a selection from the menu while true Systemoutprintln1 View All Destinations Systemoutprintln2 View Destinations by Country Systemoutprintln3 Add a Destination ...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