Question

In: Computer Science

Implement and test a TaskList application in Java that will allow a client to manage information...

Implement and test a TaskList application in Java that will allow a client to manage information about daily tasks.  A task has a task name, is scheduled on a specific day of the week and can have a comment attached to it. Together, the task name and day uniquely identify a task. There may be tasks with the same name scheduled for different days of the week. The application should allow the client to start with an empty TaskList and then manage it by adding, deleting, searching and displaying information about tasks from the TaskList according to the specifications below.

Your application should offer the client a menu with the following operations:

                0. Exit.

1. Add a task.

                2. Delete a task on a specified day.

                3. Delete a specified task.

                4. Print content of TaskList.

                5. Search day for tasks.

Here is the specification of the functionality of the TaskList application:  

1. Add a task: Adds information about a task to the TaskList. Requests the following input from the client: day, task name, and comment. If there is already a task with this name scheduled for that week day, the task cannot be added and the user should be notified of this fact.

2. Delete a task on a specified day:  Deletes a specified task on a specified day from the TaskList. Requests the following input from the client: task name and day. The user should be notified if there is no task with that name scheduled for that day in the TaskList.

3. Delete a specified task. Deletes a specified task from any day it may appear in the TaskList. Requests the following input from the client: task name. The user should be notified if there is no task with that name in the TaskList.

4. Display content of TaskList: Displays information about all tasks in the TaskList. Requests the following input from the client: None. For each task in the TaskList, displays task name, day it is scheduled on and comment attached to it.

5. Search day for tasks: Displays information about the tasks registered for a specified day. Requests the following input from the client: day.

Hint:  Make sure that you use object oriented design in your solution. In future applications the TaskList class may be used in an application used to manage several clients’ task lists. You should be able to extend your design without changes to the TaskList.

Solutions

Expert Solution

Task.java

public class Task {
private String name, comment;
private int day;
  
public Task()
{
this.name = "";
this.day = 0;
this.comment = "";
}

public Task(int day, String name, String comment)
{
this.name = name;
this.comment = comment;
this.day = day;
}

public String getName() {
return name;
}

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

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public int getDay() {
return day;
}

public void setDay(int day) {
this.day = day;
}
  
@Override
public String toString()
{
return("Day of the week: " + this.day + ", Task Name: " + this.name + ", Comment: " + this.comment);
}
}

TaskList.java

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

public class TaskList {
private ArrayList<Task> taskList;
  
public TaskList()
{
this.taskList = new ArrayList<>();
}
  
public void addTask()
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter day of the week: ");
int day = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter task name: ");
String name = sc.nextLine().trim();
String comment;
  
// search for the day and the task name
boolean found = false;
for(Task t : taskList)
{
if(day == t.getDay() && name.equalsIgnoreCase(t.getName()))
{
found = true;
break;
}
}
if(found)
System.out.println("A similar task is already scheduled!\n");
else
{
System.out.print("Enter a comment for the task: ");
comment = sc.nextLine().trim();
  
taskList.add(new Task(day, name, comment));
System.out.println(name + " is successfully scheduled on day " + day + "\n");
}
}
  
public void deleteTaskOnSpecifiedDay()
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter day of the week: ");
int day = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter task name: ");
String name = sc.nextLine().trim();
  
// search for the day and the task name
boolean found = false;
int index = 0;
for(int i = 0; i < taskList.size(); i++)
{
if(day == taskList.get(i).getDay() && name.equalsIgnoreCase(taskList.get(i).getName()))
{
found = true;
index = i;
break;
}
}
if(!found)
System.out.println("\nNo such task scheduled on day " + day + "\n");
else
{
System.out.println(taskList.get(index).getName() + " successfully removed!\n");
taskList.remove(index);
}
}
  
public void deleteSepcifiedTask()
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter task name: ");
String name = sc.nextLine().trim();
  
// search for the task name
// add all the indices of the matching task to a list
ArrayList<Task> tasks = new ArrayList<>();
  
for(int i = 0; i < taskList.size(); i++)
{
if(name.equalsIgnoreCase(taskList.get(i).getName()))
{
tasks.add(taskList.get(i));
}
}
  
if(tasks.isEmpty())
System.out.println("\nNo such task found on any day!\n");
else
{
int count = tasks.size();
for(Task task : tasks)
{
taskList.remove(task);
}
System.out.println("\nTotal " + count + " such tasks were found and deleted successfully!\n");
}
}
  
public void printTaskList()
{
if(taskList.isEmpty())
System.out.println("\nSorry, the list is empty. Please add some tasks to the list!\n");
else
{
System.out.println("\n*** THE TASK LIST ***\n---------------------");
for(Task task : taskList)
{
System.out.println(task.toString());
}
System.out.println();
}
}
  
public void searchDayForTasks()
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter day of the week: ");
int day = Integer.parseInt(sc.nextLine().trim());
  
// search if any task is scheduled
ArrayList<Task> filterTasks = new ArrayList<>();
for(Task task : taskList)
{
if(task.getDay() == day)
{
filterTasks.add(task);
}
}
  
if(filterTasks.isEmpty())
System.out.println("\nDay " + day + " has got no tasks scheduled!\n");
else
{
System.out.println("\nTasks scheduled on day " + day + ":");
for(Task task : filterTasks)
{
System.out.println(task.toString());
}
System.out.println();
}
}
}

TaskApp.java (Driver class)

import java.util.Scanner;

public class TaskApp {
  
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
TaskList taskList = new TaskList();
  
int choice;
  
do
{
printMenu();
choice = Integer.parseInt(sc.nextLine().trim());
  
switch(choice)
{
case 1:
{
taskList.addTask();
break;
}
  
case 2:
{
taskList.deleteTaskOnSpecifiedDay();
break;
}
  
case 3:
{
taskList.deleteSepcifiedTask();
break;
}
  
case 4:
{
taskList.printTaskList();
break;
}
  
case 5:
{
taskList.searchDayForTasks();
break;
}
  
case 0:
{
System.out.println("\nGood Bye!\n");
System.exit(0);
}
  
default:
System.out.println("\nInvalid choice!\n");
}
}while(choice != 0);
}
  
private static void printMenu()
{
System.out.print("0. Exit\n"
+ "1. Add a task\n"
+ "2. Delete a task on a specified day\n"
+ "3. Delete a specified task\n"
+ "4. Print all tasks\n"
+ "5. Search day for tasks\n"
+ "Enter your choice: ");
}
}

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

**********************************************************************************************************************************************


Related Solutions

Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
Java programming language Write a Java application that simulates a test. The test contains at least...
Java programming language Write a Java application that simulates a test. The test contains at least five questions. Each question should be a multiple-choice question with 4 options. Design a QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions – simulateQuestion - create a method to check the answer – checkAnswer - create a method to display a random message for the user – generateMessage - create a method to...
using Java Your mission in this exercise is to implement a very simple Java painting application....
using Java Your mission in this exercise is to implement a very simple Java painting application. Rapid Prototyping The JFrame is an example that can support the following functions: 1. Draw curves, specified by a mouse drag. 2. Draw filled rectangles or ovals, specified by a mouse drag (don't worry about dynamically drawing the shape during the drag - just draw the final shape indicated). 3. Shape selection (line, rectangle or oval) selected by a combo box OR menu. 4....
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
Java - Design and implement an application that creates a histogram that allows you to visually...
Java - Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered. Sample...
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
Create a Java windows application to manage a list of stocks 1. Add a class Stock...
Create a Java windows application to manage a list of stocks 1. Add a class Stock with the following fields: companyName, pricePerShare, numberOfShares (currently owned) and commission (this is the percent you pay a financial company when you purchase or sell stocks. Add constructor, getters and methods: ***purchaseShares (method that takes the number of shares purchased, updates the stock and return the cost of purchasing these shares make sure to include commission. ***sellShares (method that takes the number of shares...
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
in Java - implement ftp-server and ftp-client. ftp-server Logging into ftp-server from ftp-client The ftp-server is...
in Java - implement ftp-server and ftp-client. ftp-server Logging into ftp-server from ftp-client The ftp-server is an interactive, command-line program that creates a server socket, and waits for connections. Once connected, the ftp-client can send and receive files with ftp-server until ftp-client logs out. Sending and receiving files The commands sent from the ftp-client to the ftp-server must recognize and handle are these: rename- the ftp-server responds to this command by renaming the named file in its current directory to...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT