Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Project1;
- import java.util.Scanner;
- public class TravProfInterface {
- private TravProfDB database;
- public TravProfInterface(String newfileName){
- database = new TravProfDB(newfileName);
- initDB();
- }
- public void getUserChoice(){
- Scanner scan = new Scanner(System.in);
- String selection = "";
- while (!selection.equals("0")) {
- System.out.println("Please Select a menu option:\n" +
- "1. Enter a New Traveller Profile\n" +
- "2. Delete a traveller by name\n" +
- "3. Display a traveller profile\n" +
- "4. Update a traveller profile\n" +
- "5. Display all traveller profiles\n" +
- "6. Write to database\n" +
- "7. Initialize Database\n" +
- "0. Exit Program \n");
- selection = scan.nextLine();
- switch (selection) {
- case "1":
- createNewTravProf();
- break;
- case "2":
- deleteTravProf();
- break;
- case "3":
- findTravProf();
- break;
- case "4":
- updateTravProf();
- break;
- case "5":
- displayAllTravProf();
- break;
- case "6":
- writeToDB();
- break;
- case "7":
- initDB();
- break;
- }
- }
- }
- public TravProf createNewTravProf(){
- Scanner sc = new Scanner(System.in);
- String travAgentID, FirtName, LastName, Address, Phone, TravelType, PaymentType, AlgType, IllType, MdContact, MdPhone;
- float TripCost;
- System.out.println("Please enter your Agent ID: ");
- travAgentID = sc.nextLine();
- System.out.println("Please enter the traveler's First name: ");
- FirtName = sc.nextLine();
- System.out.println("Please enter the traveler's Last name: ");
- LastName = sc.nextLine();
- System.out.println("Please enter the traveler's Address: ");
- Address = sc.nextLine();
- System.out.println("Please enter the traveler's Phone number: ");
- Phone = sc.nextLine();
- System.out.println("Please indicate the Travel type: ");
- TravelType = sc.nextLine();
- System.out.println("Please enter the Payment type: ");
- PaymentType = sc.nextLine();
- System.out.println("Please enter the Trip cost: ");
- TripCost = Float.parseFloat(sc.nextLine());
- System.out.println("Please enter any Allergies: ");
- AlgType = sc.nextLine();
- System.out.println("Please enter any Illnesses: ");
- IllType = sc.nextLine();
- System.out.println("Please enter the Medical contact: ");
- MdContact = sc.nextLine();
- System.out.println("Please enter the Medical contact phone: ");
- MdPhone = sc.nextLine();
- MedCond medcondinfo = new MedCond(AlgType, IllType, MdContact, MdPhone);
- TravProf profile = new TravProf(travAgentID, FirtName, LastName, Address, Phone, TravelType, PaymentType, TripCost, medcondinfo);
- database.insertNewProfile(profile);
- return profile;
- }
- public void deleteTravProf(){
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter your ID: ");
- String travAgentID = sc.nextLine();
- System.out.println("Please enter the Traveler's Last name: ");
- String LastName = sc.nextLine();
- if(database.deleteProfile(travAgentID, LastName))
- System.out.println("Profile Deleted.");
- else
- System.out.println("Profile not found");
- }
- public void updateTravProf(){
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter your ID: ");
- String travAgentID = sc.nextLine();
- System.out.println("Please enter the Traveler's Last name: ");
- String LastName = sc.nextLine();
- TravProf profile = database.findProfile(travAgentID, LastName);
- if(profile == null)
- System.out.println("Profile not found.");
- else {
- System.out.println("Please select which field to change: \n" +
- "1. Address \n" +
- "2. Phone number \n" +
- "3. Travel type \n" +
- "4. Payment type \n" +
- "5. Trip cost \n" +
- "6. Allergy \n" +
- "7. Illnesses \n" +
- "8. Medical Contact \n" +
- "9. Medical Phone number \n");
- String selection = sc.nextLine();
- switch (selection) {
- case "1":
- System.out.println("Enter the new Address: ");
- profile.updateAddress(sc.nextLine());
- break;
- case "2":
- System.out.println("Enter the new Phone number: ");
- profile.updatePhone(sc.nextLine());
- break;
- case "3":
- System.out.println("Enter the new Travel type: ");
- profile.updateTravelType(sc.nextLine());
- break;
- case "4":
- System.out.println("Enter the new Payment type: ");
- profile.updatePaymentType(sc.nextLine());
- break;
- case "5":
- System.out.println("Enter the new Trip cost: ");
- profile.updateTripCost(sc.nextLine());
- break;
- case "6":
- System.out.println("Enter the Allergy update: ");
- profile.getMedCondInfo().updateAlgType(sc.nextLine());
- break;
- case "7":
- System.out.println("Enter the Illness update: ");
- profile.getMedCondInfo().updateIllType(sc.nextLine());
- break;
- case "8":
- System.out.println("Enter the Medical contact update: ");
- profile.getMedCondInfo().updateMdContact(sc.nextLine());
- break;
- case "9":
- System.out.println("Enter the new Medical contact phone number: ");
- profile.getMedCondInfo().updateMdPhone(sc.nextLine());
- break;
- }
- }
- }
- public void findTravProf(){ //
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter your ID: ");
- String travAgentID = sc.nextLine();
- System.out.println("Please enter the Traveler's Last Name: ");
- String LastName = sc.nextLine();
- displayTravProf(database.findProfile(travAgentID, LastName));
- }
- public void displayTravProf(TravProf traveler){
- System.out.println(traveler.gettravAgentID());
- System.out.println(traveler.getFirstName());
- System.out.println(traveler.getLastName());
- System.out.println(traveler.getAddress());
- System.out.println(traveler.getPhone());
- System.out.println(traveler.getTripCost());
- System.out.println(traveler.getTravelType());
- System.out.println(traveler.getPaymentType());
- System.out.println("\nMedical Condition Info:\n" + traveler.getMedCondInfo().getAlgType());
- System.out.println(traveler.getMedCondInfo().getIllType());
- System.out.println(traveler.getMedCondInfo().getMdContact());
- System.out.println(traveler.getMedCondInfo().getMdPhone());
- }
- public void displayAllTravProf(){
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter your ID: ");
- String travAgentID = sc.nextLine();
- TravProf profile = database.findFirstProfile();
- for(int i = 0; i < database.numTravelers; i++){
- if(profile.gettravAgentID().equals(travAgentID)) {
- System.out.println("\n");
- displayTravProf(profile);
- System.out.println("\n");
- }
- }
- }
- public void writeToDB(){
- database.WriteAllTravProf(database.fileName);
- }
- public void initDB(){
- database.initializeDatabase(database.fileName);
- }
- public static void main(String[] args){
- TravProfInterface face = new TravProfInterface("DataBase");
- face.getUserChoice();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement