Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- // Change this to an abstract class?
- class Queue{
- private int count;
- ArrayList<Object> qlist = new ArrayList<Object>();
- Queue(){
- count = 0;
- }
- public Object dequeue(){
- if(isEmpty()){
- System.out.println("The queue is empty");
- }
- Object res = qlist.get(0);
- qlist.remove(0);
- count --;
- return res;
- }
- public void enqueue(Object item){
- System.out.println("\n*****************************************");
- System.out.println("Adding the below information to the queue" + item);
- System.out.println("*****************************************");
- qlist.add(item);
- count ++;
- }
- public int size(){
- return count;
- }
- public Boolean isEmpty(){
- return(size() == 0);
- }
- public String toString(){
- return Arrays.deepToString(qlist.toArray());
- }
- }
- class Task{
- private String date;
- private String start_time;
- private String duration;
- ArrayList<String> people = new ArrayList<String>();
- Task(String date, String start_time, String duration, ArrayList<String> people){
- this.date = date;
- this.start_time = start_time;
- this.duration = duration;
- this.people = people;
- }
- public String toString(){
- return("\nType: task" + "\nDate: " + date + "\nStart time: " + start_time + "\nDuration: " + duration +"\nPeople: " + Arrays.deepToString(people.toArray()));
- }
- }
- // *************************************************************
- // Change input so that location can be multiple words
- // *************************************************************
- class Event{
- private String date;
- private String start_time;
- private String location;
- Event(String date, String start_time, String location){
- this.date = date;
- this.start_time = start_time;
- this.location = location;
- }
- public String toString(){
- return("\nType: event" + "\nDate: " + date + "\nStart time: " + start_time + "\nLocation: " + location);
- }
- }
- class ToDoList{
- public static void remove_item(Queue to_do_list){
- Object item = to_do_list.dequeue();
- System.out.println("\nRemoved: " + item + "\nfrom the to-do list");
- }
- public static void add_item(Object item, Queue to_do_list){
- to_do_list.enqueue(item);
- }
- public static void createTask(Queue to_do_list){
- Scanner input = new Scanner(System.in);
- System.out.println("\n*Creating Task*\nInput in this order a date, start time, duration and the people that are involved");
- String info = input.nextLine();
- String words[] = info.split(" ");
- ArrayList<String> people = new ArrayList<String>();
- if(words.length >= 4){
- System.out.println("Received: " + Arrays.toString(words));
- String date = words[0];
- String start_time = words[1];
- String duration = words[2];
- for(int i = 3; i < words.length; i++){
- people.add(words[i]);
- }
- Task newTask = new Task(date, start_time, duration, people);
- add_item(newTask, to_do_list);
- }
- else{
- System.out.println("\n**********************************************************");
- System.out.println("Not enough information. Please enter all requested details");
- System.out.println("**********************************************************");
- }
- }
- public static void createEvent(Queue to_do_list){
- Scanner input = new Scanner(System.in);
- System.out.println("\n*Creating Event*\nInput in this order a date, start time and location");
- String info = input.nextLine();
- String words[] = info.split(" ");
- if(words.length >= 3){
- String date = words[0];
- String start_time = words[1];
- String[] locationTokens = Arrays.copyOfRange(words, 2, words.length);
- String location = String.join(" ", locationTokens);
- Event newEvent = new Event(date, start_time, location);
- add_item(newEvent, to_do_list);
- }
- else{
- System.out.println("\n***********************************************************************");
- System.out.println("Incorrect amount of information entered. Please enter requested details");
- System.out.println("***********************************************************************");
- }
- }
- public static void prompt(){
- System.out.println("\nPlease enter:");
- System.out.println("\"task\" to input a task");
- System.out.println("\"event\" to input an event");
- System.out.println("\"dequeue\" to get the item on the top of the queue");
- System.out.println("\"queue\" to see what is on the to do list queue");
- System.out.println("\"exit\" to exit");
- }
- public static void main(String[] args){
- Queue to_do_list = new Queue();
- Scanner input = new Scanner(System.in);
- prompt();
- String item = input.next();
- while(!"exit".equals(item)){
- if(item.equals("task")){
- createTask(to_do_list);
- }
- else if(item.equals("event")){
- createEvent(to_do_list);
- }
- else if(item.equals("dequeue")){
- remove_item(to_do_list);
- }
- else if(item.equals("queue")){
- System.out.println("\nCurrent to do list:\n" + to_do_list);
- }
- else{
- System.out.println("Please enter one of the below commands");
- prompt();
- }
- System.out.println("\nPlease enter a command");
- item = input.next();
- }
- System.out.println("\nEnding program, goodbye");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement