Question

In: Computer Science

java code: adds a new regular task, delete a task , show all tasks, and show...

java code: adds a new regular task, delete a task , show all tasks, and show regular tasks, mark a task as important (possibly through ID), complete task, show all completed tasks, show important tasks.

I also need a UML diagram for the code


update: The "task" is like something in a to do list. example) task 1. name: get carrots important: no completed: yes. you can run my code as an example if needed

Solutions

Expert Solution

Task.java

public class Task {
private String name, importance, status;
  
public Task()
{
this.name = this.importance = this.status = "";
}

public Task(String name, String importance, String status) {
this.name = name;
this.importance = importance;
this.status = status;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getImportance() {
return importance;
}

public void setImportance(String importance) {
this.importance = importance;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
  
@Override
public String toString()
{
return("Task: " + getName() + ", Important: " + getImportance() + ", Completed: " + getStatus());
}
}

TaskListMain.java (Main class)

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

public class TaskListMain {
  
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
ArrayList<Task> taskList = new ArrayList<>();
  
displayMainMenu();
performAction(taskList);
}
  
private static void displayMainMenu()
{
System.out.print("COMMAND MENU:\n"
+ "list - List all tasks\n"
+ "add - Add a task\n"
+ "complete - Complete a task\n"
+ "delete - Delete a task\n"
+ "exit - Exit program\n\n");
}
  
private static void performAction(ArrayList<Task> list)
{
Scanner sc = new Scanner(System.in);
String command;
  
do
{
System.out.print("Command: ");
command = sc.nextLine().trim();
  
switch(command)
{
case "list":
{
if(list.isEmpty())
System.out.println("No tasks to show!\n");
else
{
for(int i = 0; i < list.size(); i++)
{
System.out.println((i + 1) + ". " + list.get(i));
}
System.out.println();
}
break;
}

case "add":
{
System.out.print("Description: ");
String name = sc.nextLine().trim();
System.out.print("Important? [y/n]: ");
char imp = sc.nextLine().trim().charAt(0);
while(imp != 'Y' && imp != 'y' && imp != 'N' && imp != 'n')
{
System.out.println("Invalid selection!");
System.out.print("Important? [y/n]: ");
imp = sc.nextLine().trim().charAt(0);
}
if(imp == 'Y' || imp == 'y')
list.add(new Task(name, "Yes", "Not completed"));
else
list.add(new Task(name, "No", "Not completed"));
System.out.println();
break;
}

case "complete":
{
System.out.print("Number: ");
int taskNumber = Integer.parseInt(sc.nextLine().trim());
while(taskNumber <= 0 || taskNumber > list.size() - 1)
{
System.out.println("Please enter a valid task number: ");
taskNumber = Integer.parseInt(sc.nextLine().trim());
}
list.get(taskNumber - 1).setStatus("complete");
System.out.println();
break;
}

case "delete":
{
System.out.print("Number: ");
int taskNumber = Integer.parseInt(sc.nextLine().trim());
while(taskNumber <= 0 || taskNumber > list.size())
{
System.out.println("Please enter a valid task number: ");
taskNumber = Integer.parseInt(sc.nextLine().trim());
}
list.remove(taskNumber - 1);
System.out.println();
break;
}

case "exit":
{
System.out.println("\nThank you, Goodbye!\n");
System.exit(0);
}

default:
System.out.println("\nInvalid command!\n");
}
}while(!command.equalsIgnoreCase("exit"));
}
}

*********************************************************** SCREENSHOT *****************************************************

UML DIAGRAM :


Related Solutions

need to add these functions to my code: • show only important tasks • show all...
need to add these functions to my code: • show only important tasks • show all completed tasks My code in java: import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String work=""; boolean completed=false; boolean important=false; public TodoList(String a,String b,boolean c,boolean d){ this.date=a; this.work=b; this.completed=c; this.important=d; } public boolean isCompleted(){ return this.completed; } public boolean isImportant(){ return this.important; } public String getDate(){ return this.date; } public String getTask(){ return this.work; } } class Main{ public static void main(String[]...
Can you complete the tasks inside the sample code. All the to-do task is inside the...
Can you complete the tasks inside the sample code. All the to-do task is inside the code commented out. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> typedef struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }node; /*Task 1 - Complete the function below, newNode() will return a tree node*/ node* newNode(int key){ } /*Task 2 - Complete the function below to return the size (number of elements stored) of a binary tree*/ int size(node* root){ }...
(JAVA) ExceptionSum The objective of this exercise is to create a method that adds all the...
(JAVA) ExceptionSum The objective of this exercise is to create a method that adds all the numbers within an array with an exception you cant sum the 6, and the 7, and the numbers between them cannot be added too, taking into account that whenever a 6 appears will be followed by a 7. If we have an array such that [1,2,3,6,10,9,8,7,5] when we pass it through the method it will give us an int such that the sum will...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks....
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each...
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks....
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each...
code in python I want to make a function that adds all the multipliers together. The...
code in python I want to make a function that adds all the multipliers together. The code is posted below and please look at wanted output section to see what I want the code to output. The last line of the code is the only addition I need. Thanks. Code: initial=int(input("Initial value : "))       #taking inputs multiplier=float(input("Multiplier : ")) compound=int(input("No of compounds : ")) print("Your values are:") mult=initial                         #initalizing to find answer for i in range(0,compound):         #multiplying by multiplier    ...
All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /**...
All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /** * Return the number of iterations needed to determine if z(n + 1) = z(n) * z(n) + c * remains bounded where z(0) = 0 + 0i. z(n + 1) is bounded if its magnitude * is less than or equal to 2. Returns 1 if the magnitude of c * is greater than 2. Returns max if the magnitude * of z(n...
Write a java code that could be used to show the simulation of a tornado. use...
Write a java code that could be used to show the simulation of a tornado. use the understanding of the mix of low temperature and high temperature wind go create a spinning vortex. ***POSTED INCORRECT QUESTION** here is the real question: plz write a simple java code to show a spinning circle of particles.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT