Advertisement
Guest User

derp3

a guest
Mar 31st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. package Project1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TravProfInterface {
  6. private TravProfDB database;
  7.  
  8. public TravProfInterface(String newfileName){
  9. database = new TravProfDB(newfileName);
  10. initDB();
  11. }
  12.  
  13. public void getUserChoice(){
  14. Scanner scan = new Scanner(System.in);
  15. String selection = "";
  16. while (!selection.equals("0")) {
  17. System.out.println("Please Select a menu option:\n" +
  18. "1. Enter a New Traveller Profile\n" +
  19. "2. Delete a traveller by name\n" +
  20. "3. Display a traveller profile\n" +
  21. "4. Update a traveller profile\n" +
  22. "5. Display all traveller profiles\n" +
  23. "6. Write to database\n" +
  24. "7. Initialize Database\n" +
  25. "0. Exit Program \n");
  26. selection = scan.nextLine();
  27.  
  28. switch (selection) {
  29. case "1":
  30. createNewTravProf();
  31. break;
  32. case "2":
  33. deleteTravProf();
  34. break;
  35. case "3":
  36. findTravProf();
  37. break;
  38. case "4":
  39. updateTravProf();
  40. break;
  41. case "5":
  42. displayAllTravProf();
  43. break;
  44. case "6":
  45. writeToDB();
  46. break;
  47. case "7":
  48. initDB();
  49. break;
  50. }
  51. }
  52. }
  53.  
  54.  
  55. public TravProf createNewTravProf(){
  56. Scanner sc = new Scanner(System.in);
  57.  
  58. String travAgentID, FirtName, LastName, Address, Phone, TravelType, PaymentType, AlgType, IllType, MdContact, MdPhone;
  59. float TripCost;
  60.  
  61. System.out.println("Please enter your Agent ID: ");
  62. travAgentID = sc.nextLine();
  63.  
  64. System.out.println("Please enter the traveler's First name: ");
  65. FirtName = sc.nextLine();
  66.  
  67. System.out.println("Please enter the traveler's Last name: ");
  68. LastName = sc.nextLine();
  69.  
  70. System.out.println("Please enter the traveler's Address: ");
  71. Address = sc.nextLine();
  72.  
  73. System.out.println("Please enter the traveler's Phone number: ");
  74. Phone = sc.nextLine();
  75.  
  76. System.out.println("Please indicate the Travel type: ");
  77. TravelType = sc.nextLine();
  78.  
  79. System.out.println("Please enter the Payment type: ");
  80. PaymentType = sc.nextLine();
  81.  
  82. System.out.println("Please enter the Trip cost: ");
  83. TripCost = Float.parseFloat(sc.nextLine());
  84.  
  85. System.out.println("Please enter any Allergies: ");
  86. AlgType = sc.nextLine();
  87.  
  88. System.out.println("Please enter any Illnesses: ");
  89. IllType = sc.nextLine();
  90.  
  91. System.out.println("Please enter the Medical contact: ");
  92. MdContact = sc.nextLine();
  93.  
  94. System.out.println("Please enter the Medical contact phone: ");
  95. MdPhone = sc.nextLine();
  96.  
  97. MedCond medcondinfo = new MedCond(AlgType, IllType, MdContact, MdPhone);
  98. TravProf profile = new TravProf(travAgentID, FirtName, LastName, Address, Phone, TravelType, PaymentType, TripCost, medcondinfo);
  99.  
  100. database.insertNewProfile(profile);
  101.  
  102. return profile;
  103. }
  104.  
  105.  
  106.  
  107. public void deleteTravProf(){
  108. Scanner sc = new Scanner(System.in);
  109.  
  110. System.out.println("Please enter your ID: ");
  111. String travAgentID = sc.nextLine();
  112.  
  113. System.out.println("Please enter the Traveler's Last name: ");
  114. String LastName = sc.nextLine();
  115.  
  116. if(database.deleteProfile(travAgentID, LastName))
  117. System.out.println("Profile Deleted.");
  118. else
  119. System.out.println("Profile not found");
  120. }
  121.  
  122. public void updateTravProf(){
  123. Scanner sc = new Scanner(System.in);
  124.  
  125. System.out.println("Please enter your ID: ");
  126. String travAgentID = sc.nextLine();
  127.  
  128. System.out.println("Please enter the Traveler's Last name: ");
  129. String LastName = sc.nextLine();
  130.  
  131. TravProf profile = database.findProfile(travAgentID, LastName);
  132.  
  133. if(profile == null)
  134. System.out.println("Profile not found.");
  135. else {
  136. System.out.println("Please select which field to change: \n" +
  137. "1. Address \n" +
  138. "2. Phone number \n" +
  139. "3. Travel type \n" +
  140. "4. Payment type \n" +
  141. "5. Trip cost \n" +
  142. "6. Allergy \n" +
  143. "7. Illnesses \n" +
  144. "8. Medical Contact \n" +
  145. "9. Medical Phone number \n");
  146.  
  147. String selection = sc.nextLine();
  148.  
  149. switch (selection) {
  150. case "1":
  151. System.out.println("Enter the new Address: ");
  152. profile.updateAddress(sc.nextLine());
  153. break;
  154. case "2":
  155. System.out.println("Enter the new Phone number: ");
  156. profile.updatePhone(sc.nextLine());
  157. break;
  158. case "3":
  159. System.out.println("Enter the new Travel type: ");
  160. profile.updateTravelType(sc.nextLine());
  161. break;
  162. case "4":
  163. System.out.println("Enter the new Payment type: ");
  164. profile.updatePaymentType(sc.nextLine());
  165. break;
  166. case "5":
  167. System.out.println("Enter the new Trip cost: ");
  168. profile.updateTripCost(sc.nextLine());
  169. break;
  170. case "6":
  171. System.out.println("Enter the Allergy update: ");
  172. profile.getMedCondInfo().updateAlgType(sc.nextLine());
  173. break;
  174. case "7":
  175. System.out.println("Enter the Illness update: ");
  176. profile.getMedCondInfo().updateIllType(sc.nextLine());
  177. break;
  178. case "8":
  179. System.out.println("Enter the Medical contact update: ");
  180. profile.getMedCondInfo().updateMdContact(sc.nextLine());
  181. break;
  182. case "9":
  183. System.out.println("Enter the new Medical contact phone number: ");
  184. profile.getMedCondInfo().updateMdPhone(sc.nextLine());
  185. break;
  186. }
  187. }
  188. }
  189.  
  190. public void findTravProf(){ //
  191. Scanner sc = new Scanner(System.in);
  192.  
  193. System.out.println("Please enter your ID: ");
  194. String travAgentID = sc.nextLine();
  195.  
  196. System.out.println("Please enter the Traveler's Last Name: ");
  197. String LastName = sc.nextLine();
  198.  
  199. displayTravProf(database.findProfile(travAgentID, LastName));
  200. }
  201.  
  202. public void displayTravProf(TravProf traveler){
  203. System.out.println(traveler.gettravAgentID());
  204. System.out.println(traveler.getFirstName());
  205. System.out.println(traveler.getLastName());
  206. System.out.println(traveler.getAddress());
  207. System.out.println(traveler.getPhone());
  208. System.out.println(traveler.getTripCost());
  209. System.out.println(traveler.getTravelType());
  210. System.out.println(traveler.getPaymentType());
  211.  
  212. System.out.println("\nMedical Condition Info:\n" + traveler.getMedCondInfo().getAlgType());
  213. System.out.println(traveler.getMedCondInfo().getIllType());
  214. System.out.println(traveler.getMedCondInfo().getMdContact());
  215. System.out.println(traveler.getMedCondInfo().getMdPhone());
  216. }
  217.  
  218. public void displayAllTravProf(){
  219. Scanner sc = new Scanner(System.in);
  220.  
  221. System.out.println("Please enter your ID: ");
  222. String travAgentID = sc.nextLine();
  223.  
  224. TravProf profile = database.findFirstProfile();
  225.  
  226. for(int i = 0; i < database.numTravelers; i++){
  227. if(profile.gettravAgentID().equals(travAgentID)) {
  228. System.out.println("\n");
  229. displayTravProf(profile);
  230. System.out.println("\n");
  231. }
  232. }
  233. }
  234.  
  235. public void writeToDB(){
  236. database.WriteAllTravProf(database.fileName);
  237. }
  238.  
  239. public void initDB(){
  240. database.initializeDatabase(database.fileName);
  241. }
  242.  
  243. public static void main(String[] args){
  244. TravProfInterface face = new TravProfInterface("DataBase");
  245. face.getUserChoice();
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement