Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.Scanner;
  8.  
  9. public class Driver {
  10. private String username;
  11. private String password;
  12. private boolean available;
  13. ArrayList<String> notifications = new ArrayList<String>(); //Declares new ArrayList of String objects called notifications
  14.  
  15. public Driver(String username, String password, boolean av) {
  16. this.username = username;
  17. this.password = password;
  18. this.available = av;
  19. }
  20.  
  21. public void printN(){ //printN() method declares new scanner called keyboard and prints username
  22. Scanner keyboard = new Scanner(System.in);
  23. System.out.println(username);
  24. }
  25.  
  26. public Boolean checkPassword(String password) { //methods to check username & password inputted equals password of driver
  27. return this.password.equals(password);
  28. }
  29.  
  30. public Boolean checkUsername(String username) {
  31. return this.username.equals(username);
  32. }
  33.  
  34. public String getUsername() {
  35. return username;
  36. }
  37.  
  38. public boolean isAvailable() { //isAvailable method returns true if driver is available, false if not.
  39. if(available)return true;
  40. else return false;
  41. }
  42.  
  43. public void addNotification(String note){ //method to add a note to the notifications arrayList
  44. notifications.add(note);
  45. }
  46.  
  47. public void printNotifications(){ //method to iterate through notifications arrayList and prints notifications for logged in user
  48. for (int i = 0; i < notifications.size(); i++) {
  49. System.out.println(notifications.get(i));
  50. }
  51. System.out.println(" ||-----------------------|| \n \n");
  52. }
  53. public Container setDate(){
  54. Scanner keyb = new Scanner(System.in);
  55. Container b = new Container();
  56. Container c = new Container();
  57. Date curDate = new Date(); //curDate gets assigned to current time
  58.  
  59. c.SetContainer(false, 0);
  60.  
  61. System.out.println(" Please enter the start date then end date in the format 7-Jun-2013 \n StartDate: ");
  62. String date1 = keyb.nextLine();
  63.  
  64. System.out.println(" EndDate: \n");
  65. String date2 = keyb.nextLine();
  66.  
  67.  
  68. SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); //new SimpleDateFormat with format dd-mm-yyyy
  69.  
  70. try {
  71. java.util.Date date = formatter.parse(date1); //formats 'date1' to SimpleDateFormat and assigns to 'date'
  72. java.util.Date date3 = formatter.parse(date2);
  73. Calendar calendar = Calendar.getInstance(); //creating two new calendars and setting them to 'date' so we
  74. Calendar calendar2 = Calendar.getInstance(); //can add or remove days and assigning these new dates to new variables
  75. calendar.setTime(date); //'datePlus3Days' & 'dateMinus2Days'. We then compare these against curDate
  76. calendar2.setTime(date); //to check if start & end date are valid
  77. calendar.add(Calendar.DAY_OF_MONTH, -2);
  78. calendar2.add(Calendar.DAY_OF_MONTH, +3);
  79. calendar2.add(Calendar.SECOND, +1);
  80. Date dateMinus2Days = calendar.getTime();
  81. Date datePlus3Days = calendar2.getTime();
  82.  
  83. if (curDate.after(dateMinus2Days)) {
  84. System.out.println(" The start date must be at least 48 hours in advance & a maximum of 72 hours long! \n");
  85. setDate();
  86. }
  87.  
  88. else if (curDate.before(dateMinus2Days))b.date1 = date;
  89.  
  90. if (date3.before(datePlus3Days)){
  91. b.date2 = date3;
  92. b.isTrue = true;
  93. return b;
  94. }else {
  95. System.out.println(" The start date must be at least 48 hours in advance & a maximum of 72 hours long! \n");
  96. setDate();
  97. }
  98. } catch (ParseException e) {
  99. e.printStackTrace();
  100. return c;
  101. }
  102. return c;
  103. }
  104. public void setSchedule(String reg, String name) throws IOException { //method to setup a new schedule
  105. Date date = null;
  106. Date endDate = null;
  107. Date startDate = null;
  108. Scanner keyboard3 = new Scanner(System.in);
  109.  
  110. System.out.println(" Please enter the clients name");
  111. String client = keyboard3.nextLine();
  112. Container temp = setDate();
  113. if(temp.isTrue = false){
  114. temp = setDate();
  115. }else {
  116. startDate = temp.date1;
  117. endDate = temp.date2;
  118. }
  119. String State = " Pending";
  120. System.out.print(" Your new schedule looks like this:" + "\n Client: " + client + "\n Driver: " + name + "\n Start Date: " + startDate + "\n End Date: " + endDate + "\n" + " Vehicle Reg: " + reg + "\n");
  121. WorkSchedule schedule = new WorkSchedule(name, client, startDate, endDate, reg, State);
  122. State = schedule.setState();
  123. schedule.handleState();
  124. System.out.println(" State:" + State + "\n \n");
  125. Depot.workSArray.add(schedule);
  126. Depot.setUpWorkSchedule();
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement