Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. // Change this to an abstract class?
  4. class Queue{
  5.  
  6. private int count;
  7. ArrayList<Object> qlist = new ArrayList<Object>();
  8.  
  9. Queue(){
  10. count = 0;
  11. }
  12.  
  13. public Object dequeue(){
  14. if(isEmpty()){
  15. System.out.println("The queue is empty");
  16. }
  17.  
  18. Object res = qlist.get(0);
  19. qlist.remove(0);
  20. count --;
  21. return res;
  22. }
  23.  
  24. public void enqueue(Object item){
  25. System.out.println("\n*****************************************");
  26. System.out.println("Adding the below information to the queue" + item);
  27. System.out.println("*****************************************");
  28. qlist.add(item);
  29. count ++;
  30. }
  31.  
  32. public int size(){
  33. return count;
  34. }
  35.  
  36. public Boolean isEmpty(){
  37. return(size() == 0);
  38. }
  39.  
  40. public String toString(){
  41. return Arrays.deepToString(qlist.toArray());
  42. }
  43. }
  44.  
  45. class Task{
  46.  
  47. private String date;
  48. private String start_time;
  49. private String duration;
  50. ArrayList<String> people = new ArrayList<String>();
  51.  
  52. Task(String date, String start_time, String duration, ArrayList<String> people){
  53. this.date = date;
  54. this.start_time = start_time;
  55. this.duration = duration;
  56. this.people = people;
  57. }
  58.  
  59. public String toString(){
  60. return("\nType: task" + "\nDate: " + date + "\nStart time: " + start_time + "\nDuration: " + duration +"\nPeople: " + Arrays.deepToString(people.toArray()));
  61. }
  62. }
  63.  
  64. // *************************************************************
  65. // Change input so that location can be multiple words
  66. // *************************************************************
  67. class Event{
  68.  
  69. private String date;
  70. private String start_time;
  71. private String location;
  72.  
  73. Event(String date, String start_time, String location){
  74. this.date = date;
  75. this.start_time = start_time;
  76. this.location = location;
  77. }
  78.  
  79. public String toString(){
  80. return("\nType: event" + "\nDate: " + date + "\nStart time: " + start_time + "\nLocation: " + location);
  81. }
  82. }
  83.  
  84. class ToDoList{
  85.  
  86. public static void remove_item(Queue to_do_list){
  87. Object item = to_do_list.dequeue();
  88. System.out.println("\nRemoved: " + item + "\nfrom the to-do list");
  89. }
  90.  
  91. public static void add_item(Object item, Queue to_do_list){
  92. to_do_list.enqueue(item);
  93. }
  94.  
  95. public static void createTask(Queue to_do_list){
  96. Scanner input = new Scanner(System.in);
  97.  
  98. System.out.println("\n*Creating Task*\nInput in this order a date, start time, duration and the people that are involved");
  99. String info = input.nextLine();
  100. String words[] = info.split(" ");
  101.  
  102. ArrayList<String> people = new ArrayList<String>();
  103. if(words.length >= 4){
  104. System.out.println("Received: " + Arrays.toString(words));
  105. String date = words[0];
  106. String start_time = words[1];
  107. String duration = words[2];
  108. for(int i = 3; i < words.length; i++){
  109. people.add(words[i]);
  110. }
  111. Task newTask = new Task(date, start_time, duration, people);
  112. add_item(newTask, to_do_list);
  113. }
  114. else{
  115. System.out.println("\n**********************************************************");
  116. System.out.println("Not enough information. Please enter all requested details");
  117. System.out.println("**********************************************************");
  118. }
  119. }
  120.  
  121. public static void createEvent(Queue to_do_list){
  122. Scanner input = new Scanner(System.in);
  123. System.out.println("\n*Creating Event*\nInput in this order a date, start time and location");
  124. String info = input.nextLine();
  125. String words[] = info.split(" ");
  126. if(words.length >= 3){
  127. String date = words[0];
  128. String start_time = words[1];
  129. String[] locationTokens = Arrays.copyOfRange(words, 2, words.length);
  130. String location = String.join(" ", locationTokens);
  131. Event newEvent = new Event(date, start_time, location);
  132. add_item(newEvent, to_do_list);
  133. }
  134. else{
  135. System.out.println("\n***********************************************************************");
  136. System.out.println("Incorrect amount of information entered. Please enter requested details");
  137. System.out.println("***********************************************************************");
  138. }
  139. }
  140.  
  141. public static void prompt(){
  142. System.out.println("\nPlease enter:");
  143. System.out.println("\"task\" to input a task");
  144. System.out.println("\"event\" to input an event");
  145. System.out.println("\"dequeue\" to get the item on the top of the queue");
  146. System.out.println("\"queue\" to see what is on the to do list queue");
  147. System.out.println("\"exit\" to exit");
  148. }
  149.  
  150. public static void main(String[] args){
  151.  
  152. Queue to_do_list = new Queue();
  153. Scanner input = new Scanner(System.in);
  154. prompt();
  155.  
  156. String item = input.next();
  157. while(!"exit".equals(item)){
  158. if(item.equals("task")){
  159. createTask(to_do_list);
  160. }
  161. else if(item.equals("event")){
  162. createEvent(to_do_list);
  163. }
  164. else if(item.equals("dequeue")){
  165. remove_item(to_do_list);
  166. }
  167. else if(item.equals("queue")){
  168. System.out.println("\nCurrent to do list:\n" + to_do_list);
  169. }
  170. else{
  171. System.out.println("Please enter one of the below commands");
  172. prompt();
  173. }
  174. System.out.println("\nPlease enter a command");
  175. item = input.next();
  176. }
  177. System.out.println("\nEnding program, goodbye");
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement