Question

In: Computer Science

NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...

NEed UML diagram for this java code:

import java.util.ArrayList;
import java.util.Scanner;

class ToDoList {
    private ArrayList<Task> list;//make private array

    public ToDoList() {
//this keyword refers to the current object in a method or constructor
        this.list = new ArrayList<>();
    }

    public Task[] getSortedList() {
        Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array
        //fills array with given values by using a for loop
        for (int i = 0; i < this.list.size(); i++) {
            sortedList[i] = this.list.get(i);
        }
        //sorting values in array using bubble sort
        Task temp;//temp var to hold sorted values
        for (int i = 0; i < sortedList.length; i++) {
            for (int j = 1; j < (sortedList.length - i); j++) {
                if (sortedList[j].isEarlier(sortedList[j - 1])) {
                    temp = sortedList[j - 1];
                    sortedList[j - 1] = sortedList[j];
                    sortedList[j] = temp;
                }
            }
        }
        return sortedList;
    }//end of getSortedList
    public void addTask(Task task) {
        this.list.add(task);//.add to add elements in the list
    }
    public void deleteTask(int taskID) {
        //delete tasks using task ID
        for (int i = 0; i < this.list.size(); i++) {
            if (this.list.get(i).getTaskID() == taskID) {
                this.list.remove(i);
            }
        }
    }
    public void deleteAllTasks() {
        this.list.clear();
    }
    public int getTaskNumber() {
        return this.list.size();
    }
    public void printList(Task[] tasks) {
        System.out.println("-------------------------");
        for (Task task : tasks) {
            task.printTask();
        }
        System.out.println("-------------------------");
    }
    public static void displayMenu() {
        System.out.println("1)Add tasks");
        System.out.println("2)List tasks");
        System.out.println("3)Delete Tasks");
        System.out.println("4)Delete all tasks");
        System.out.println("5)Exit");
      }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ToDoList toDoList = new ToDoList();
       boolean run = true;

        while (run) {//will continue to loop until user chooses a valid option
             displayMenu();
            int choice = in.nextInt();
            switch (choice) {
                //nextLine() method advances this scanner past the current line and returns the input that was skipped
                case 1:
                    in.nextLine();
                    System.out.print("Task Name: ");
                    String taskTitle = in.nextLine();
                    System.out.print("Task Deadline (dd mm yyyy): ");
                    int taskDay = in.nextInt();
                    int taskMonth = in.nextInt();
                    int taskYear = in.nextInt();
                    in.nextLine();
                    System.out.print("Time Deadline (hh mm): ");
                    int taskHour = in.nextInt();
                    int taskMin = in.nextInt();
                    in.nextLine();
                    System.out.print("Is task Regular or Important?: ");
                    String taskImportant = in.nextLine();
                    //Task ID made with all info set up neatly
                    Task newTask = new Task(new Time(taskHour, taskMin), new Date(taskDay, taskMonth, taskYear), taskTitle, taskImportant, toDoList.getTaskNumber() + 1);
                    //Adds the new task to the list
                    toDoList.addTask(newTask);
                    //Display the sorted tasks
                    System.out.printf("Task %d is added. The To-Do list is as follows:\n", newTask.getTaskID());
                    toDoList.printList(toDoList.getSortedList());
                    break;
                case 2:
                    //List all tasks
                    toDoList.printList(toDoList.getSortedList());
                    break;
                case 3:
                    //Delete a task
                    toDoList.printList(toDoList.getSortedList());
                    in.nextLine();
                    System.out.print("Enter ID number to delete task: ");
                    int taskID = in.nextInt();
                    toDoList.deleteTask(taskID);
                    System.out.printf("\nTask %d is deleted. The new list is:\n", taskID);
                    toDoList.printList(toDoList.getSortedList());
                    break;
                case 4:
                    //Delete all tasks
                    toDoList.deleteAllTasks();
                    System.out.println("Tasks Deleted");
                    break;
                case 5:
                    //Exit program
                    System.out.println("Exiting program, goodbye.");
                    run = false;
                    break;
            }
        }
    }

}


class Date {

    private int day;
    private int month;
    private int year;
    //Default constructor for date,
    public Date() {
        this(0, 0, 0);
    }

    public Date(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }
    //accessors and mutators
    public int getDay() {
        return this.day;
    }

    public int getMonth() {
        return this.month;
    }

    public int getYear() {
        return this.year;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public void setYear(int year) {
        this.year = year;
    }

        public String toString() {
        return String.format("%d/%d/%d", this.day, this.month, this.year);

    }
    //Returns whether this date is earlier than another date provided as parameter. If they are the same, returns false
    public boolean isEarlier(Date date) {
        //If the years are the same, narrow the comparison down the months
        if (this.year == date.year) {
            //Repeat the same thing as years, but narrowed down for months
            if (this.month == date.month) {
                if (this.day == date.day) {
                    //Returns false because if they are the same date, then one is not earlier than the other
                    return false;
                } else if (this.day < date.day) {
                    return true;
                } else {
                    return false;
                }
            } else if (this.month < date.month) {
                return true;
            } else {
                return false;
            }
                    } else if (this.year < date.year) {
            return true;
                    } else {
            return false;
        }
    }
}
class Time {

    private int hour;
    private int min;
    //Default constructor for time
    public Time() {
        this(0, 0);
    }

    public Time(int hour, int min) {
        this.hour = hour;
        this.min = min;
    }
    //Accessors and mutator methods for hour and min attributes
    public int getHour() {
        return this.hour;
    }

    public int getMin() {
        return this.min;
    }

    public void setHour(int hour) {
        this.hour = hour;
    }

    public void setMin(int min) {
        this.min = min;
    }

    //Returns time in HH:MM format
    public String toString() {
        return String.format("%d:%d", this.hour, this.min);
    }
    //Returns whether or not this time is earlier than the time provided as a parameter. Returns false if both same
    public boolean isEarlier(Time time) {
        //If they are the same hour, narrow the comparison down to the minute
        if (this.hour == time.hour) {
            //Exact same process, but for min
            if (this.min == time.min) {
                //Returns false because if they're the same time, one is not earlier than the other
                return false;
            } else if (this.min < time.min) {
                return true;
            } else {
                return false;
            }
            //If this hour is less than the other hour, it is earlier, so return true
        } else if (this.hour < time.hour) {
            return true;
            //Otherwise, the time isn't earlier
        } else {
            return false;
        }
    }

}
class Task {
    private Time time;
    private Date date;
    private String title;
    private String Important;
    private int taskID;
    //Default constructor leaves attributes blank
    public Task() {
        this(null, null, null, null, 0);
    }
    public Task(Time time, Date date, String title, String Important, int taskID) {
        this.time = time;
        this.date = date;
        this.title = title;
        this.Important = Important;
        this.taskID = taskID;
    }
    //accessors and mutators for time, date, title, Important, and taskID
    public Time getTime() {
        return this.time;
    }
    public Date getDate() {
        return this.date;
    }
    public String getTitle() {
        return this.title;
    }
    public String getImportant() {
        return this.Important;
    }
    public int getTaskID() {
        return this.taskID;
    }
    public void setTime(Time time) {
        this.time = time;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public void setImportant(String Important) {
        this.Important = Important;
    }
    //Prints task date
    public void printTask() {
        System.out.printf("* Task %d: %s, %s, %s, %s\n", this.taskID, "title: ", this.title, this.date.toString(), this.time.toString(), this.Important);
    }
    //Returns true if this task is earlier than task provided as parameter.
    public boolean isEarlier(Task task) {
        //If the other task's date is earlier than this task's date, it must be earlier
        if (this.date.isEarlier(task.getDate())) {
            return true;
            //However, if the dates are the same, narrow the check down to the tasks' times
        } else if (!this.date.isEarlier(task.getDate()) && !task.getDate().isEarlier(this.date)) {
            return this.time.isEarlier(task.time);
        }
        return false;
    }
}

Solutions

Expert Solution

Description:

Since the class Task has members Data and Time,there is a dependencey between them.After that there will be a dependency between ToDOList and Task.

This Relationship is depicted in the following UML Diagram:


Related Solutions

UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public class CourseeCOM616 {        private String courseName;     private String[] studentsName = new String[1];     private String studentId;        private int numberOfStudents;        public CourseeCOM616(String courseName) {         this.courseName = courseName;     }     public String[] getStudentsName() {         return studentsName;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getStudentId() {         return studentId;    ...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT