Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following startup code of Java classes: Listing 1: Task Class Listing 2: TestingTask Class 1. Status Enumeration (4 marks) (a) Add a private

Given the following startup code of Java classes:

Listing 1: Task Class

image text in transcribed

Listing 2: TestingTask Class

image text in transcribed

1. Status Enumeration (4 marks) (a) Add a private constructor Status(int value) that initializes each constant to its value (2 marks)

(b) Add a getter method that retrieves the value of the read-only field value (2 marks)

2. Task Class (20 marks) (a) Add appropriate getters and/or setters for each instance variable (12 marks) A task cannot be set to a status whose value is less than or equal to its current status

(b) Add a constructor Task(String name) that i (4 marks) Setup a tasks Task(id)should be set to its hash code Setup the A tasks createdAt to the date when it was created

(c) Add a method toString() that returns a string representation of a task object in the format (see figure 1 on page 3) (4 marks) image text in transcribedFigure 1: toString() Format

3. TestingTask Class (10 marks) (a) Add appropriate code in the main() method that displays the Status values in the following format (see figure 2 on page 3)

image text in transcribedFigure 2: Enumeration Values

(b) Add appropriate code in the main() method that instantiates a task and modifies its status (see figure 3 on page 4) (6 marks)

image text in transcribedFigure 3: Sample Output Format

Listing 1: Task Class package tasks; import java.text.SimpleDateFormat; import java.util. Date; public class Task\{ enum Status\{ CREATED(0), STARTED(1), IN_PROGRESS (2), COMPLETED (3); // you code goes here \} // read-only field private int id; private String name; private Status status; // read-only field private Date createdAt; // your code goes here \} Listing 2: TestingTask Class \begin{tabular}{r|l} 1 & package tasks; \\ 2 & import tasks. Task.Status; \\ 3 & \\ 4 & public class TestingTask \{ \\ 5 & \\ 6 & public static void main(String [] args) \{ \\ 7 & // your code goes here \\ 8 & \\ 9 & \\ 10 & \} \end{tabular} |Task Name: Lab 2. |Task created on 13:44:26 p.m. 0800. |Task Status . \( \begin{array}{l}\mid(\text { Status, Value })=(\text { CREATED }, \theta) \\ \mid \text { (Status, Value })=(\text { STARTED, } 1) \\ \mid \text { (Status, Value })=(\text { IN_PROGRESS, } 2) \\ \mid \text { (Status, Value })=(\text { COMPLETED, } 3)\end{array} \)

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

Students also viewed these Databases questions

Question

=+1. What were the variables of interest in this study?

Answered: 1 week ago