Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***** I HAVE ALREADY DONE THIS FIRST PROBLEM. PLEASE LOOK AFTER THE CODE BLOCKS TO SEE THE SECOND PROBLEM.**** Task Implement a class Task, which

***** I HAVE ALREADY DONE THIS FIRST PROBLEM. PLEASE LOOK AFTER THE CODE BLOCKS TO SEE THE SECOND PROBLEM.****

Task

Implement a class Task, which is used to represent a job that should be done. It should contain the following private fields:

  • name text description of what job should be done (e.g., take out the trash, finish 1068 homework).
  • priority, a non-negative integer which stores the importance of a Task.
  • estMinsToComplete, a non-negative integer which holds the anticipated number of minutes it should take to complete the task
  • extra credit: whenDue a java.time.LocalDateTime object representing the date and time when the task should be completed

Implement at least the following public methods within the Task class:

  • a constructor, which initializes each of the fields
  • accessor methods for each of the fields. Use the naming convention getXXX() where XXX is the name of the field, e.g., code a method called getName() which returns the name of the Task.
  • mutator methods for each of the fields except for priority. Use the naming convention setXXX() where XXX is the name of the field, e.g., you'll code a method called setName(String newName), which would update the name field of the Task to newName.
  • toString( ), which returns a String representation of the Task.
  • increasePriority(int amount) increases the priority level by amount. If a negative amount is specified, the method returns without making any changes.
  • decreasePriority(int amount) decreases the priority level by amount. If the decrease is more than the current value of priority (and subtracting this amount would result in a negative priority), priority should be set to 0.
  • extra credit: overdue() returns true if the current date/time is later than whenDue or false otherwise.

For example, we should be able to do something like the following:

// creates a new Task object to remind you

// to complete 1068 homework. It has priority 3

// and I anticipate that it's going to take 120 minutes

Task doMyHW = new Task("finish 1068 homework", 3, 120);

// if we're doing extra credit, we might instead write:

Task postHW = new Task("post 1068 homework", 1, LocalDateTime.of(2019, 3, 23, 13, 0), 180);

// which would be to remind me to post the 1068 homework assignment.

// This has priority 1, should take me 180 minutes

// and it's due March 23, 2019 at 1 PM (i.e., 13:00)

Code a very short driver program (a separate class containing a main()) to test your code to make sure it's working. You are not required to write JUnit tests.

YOU DO NOT NEED TO DO THE TOP PROGRAM. I HAVE ALREADY DONE IT AND WILL INCLUDE IT. THE BOTTOM PROGRAM NEEDS TO BE COMPLETED STILL.

import java.time.LocalDateTime; public class Task { private String name; private int priority; private int estMinsToComplete; private LocalDateTime whenDue = null; Task(String name, int priority, int estMinsToComplete){ this.name = name; this.priority = priority; this.estMinsToComplete = estMinsToComplete; } Task(String name, int priority, LocalDateTime whenDue, int estMinsToComplete){ this.name = name; this.priority = priority; this.estMinsToComplete = estMinsToComplete; this.whenDue = whenDue; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPriority() { return priority; } public int getEstMinsToComplete() { return estMinsToComplete; } public void setEstMinsToComplete(int estMinsToComplete) { this.estMinsToComplete = estMinsToComplete; } public LocalDateTime getWhenDue() { return whenDue; } public void setWhenDue(LocalDateTime whenDue) { this.whenDue = whenDue; } public void increasePriority(int x) { if (x < 0) return; this.priority += x; } public void decreasePriority(int x) { if (x > this.priority) { this.priority = 0; } else { this.priority -= x; } } public boolean overdue() { LocalDateTime current = LocalDateTime.now(); if (current.compareTo(whenDue) < 0) { return false; } return true; } public String toString() { if (whenDue == null) return "Task: " + name + " This has Priority: " + priority + " Estimated Time to complete: " + estMinsToComplete; else return "Task: " + name + " This has Priority: " + priority + " Estimated Time to complete: " + estMinsToComplete + " Due in: " + whenDue.toString(); } } 

IN MAIN

import java.time.LocalDateTime; public class TaskMain { public static void main(String[] args) { Task task = new Task("finish writing IH essay", 4, 160); System.out.println(task); System.out.println("Current Name: " + task.getName()); task.setName("Proofread IH essay."); System.out.println("New Name: " + task.getName()); System.out.println("Current Priority: " + task.getPriority()); task.increasePriority(-1); System.out.println("New Priority: " + task.getPriority()); task.decreasePriority(task.getPriority() + 2); System.out.println("New Priority: " + task.getPriority()); task = new Task("code CIS 1068 project", 3, LocalDateTime.of(2023, 4, 11, 12, 0), 180); System.out.println(task); System.out.println("Overdue? " + task.overdue()); } } 

I NEED HELP WITH THE PROBLEM BELOW. YOU WILL NEED THE CODE FROM ABOVE IN ORDER TO DO IT.

HoneyDoList

Implement a class HoneyDoList, which is used to manage a collection of Task. It should contain the following private fields:

  • tasks[] an array of Task
  • numTasks, a non-negative integer storing the number of items contained in tasks[]. Note that this is not necessarily the same as tasks.length
  • INITIAL_CAPACITY, a constant non-negative integer. This is how large the task array should be when an empty list is created.

Implement at least the following public methods within the HoneyDo class:

  • a constructor, which creates the tasks[] array, giving it the capacity of INITIAL_CAPACITY, and setting numTasks to 0.
  • toString( ), which returns a String representation of each Task in tasks[]. Do not include in the String null for entries in tasks[] that are empty.
  • find(String name), which returns the index of the first occurence of a Task whose name matches the name specified ignoring case. Recall that there is an equalsIgnoreCase() method in the String class. The method should return -1 if no match is found.
  • addTask(), which appends a new Task to the occupied end of tasks[]. If tasks[] is already full when you attempt to add the new Task, a new array is created, all of the items are copied from the old array into the new one, and tasks[] is set to point to the new array.
  • totalTime() which returns the total time in minutes required to perform the tasks in the list.
  • shortestTime() which returns the index of the task that should take the least amount of time to finish or -1 if the list is empty.
  • completeTask(int index), which removes and returns the Task at the specified index shifting all subsequent tasks in the array one position to the left. If index is invalid, returns null. See example.
  • getTask(int index), returns a reference to the Task at the specified location. If index is invalid, returns null.
  • extra credit: overdueTasks() returns an array of Task consisting of only the items in tasks[] that are overdue.

For example, we should be able to do something like the following:

// make a new empty list

HoneyDoList honeydo = new HoneyDoList();

System.out.println(honeydo);

honeydo.addTask(new Task("take aspirin", 1, 120));

System.out.println(honeydo);

// print the item in the list which should

// take the least amount of time //

// this looks like a mouthful, but we first get the index of the Task

// that takes the least amount of time, get a reference to it

// call toString( ) on it, and print the String

// representation to the screen

System.out.println(honeydo.get(honeydo.shortestTime()));

Code a very short driver program to test your code to make sure it's working. You are not required to write JUnit tests.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions