Assignment 1 Requirements: In Assignment 1, you will instantiate various subclasses of the Action class, and store each instance in an array. In Part 3 of the assignment you’ll search the array to see...



Assignment 1 Requirements:


In Assignment 1, you will instantiate various subclasses of the Action class, and
store each instance in an array. In Part 3 of the assignment you’ll search the
array to see if the date of each Action object matches the date requested by the
user, i.e. which action task is ‘occursOn’ that particular date. Whenever it is,
that object’s description is printed out using its toString() method.


action1: regular -- action1 Action[] actions Input date: 11/19/22
Due Date: anymonth/03/anyyear occursOn(11/19/22)? true
Description: “inspect rudder” "Wash your hands"
action2: occasional -- action2 occursOn(11/19/22)? false
Due Date: anymonth/19/anyyear
Description: “change wheels”
action3: occasional -- action3 occursOn(11/19/22)? true
Due Date: today “Take a PCR test”
Description: “check engine vibration”
action4: occasional -- action4 occursOn(11/19/22)? true
Due Date: 12/07/2022 “Get a booster shot”
Description: “wear a mask”
action5: rare --action5 occursOn(11/19/22)? false


Part 1 requires that you add an abstract occursOn() method to the Action class. As
an abstract method, it will have no body, just the header. And because we may wish
to have actions for one or more days of the year, occursOn() needs to take three
parameters: ints for day, month, and year. Action also needs a one-arg constructor
to load the description String. (Ideally, as a superclass, it should have a no-arg
constructor as well, although this is not absolutely essential here.)
The RegularAction class extends Action, and should include its own constructor
chained to the one-arg superclass constructor in Action. Furthermore, since Action
contains an abstract method, all its subclasses will need to override occursOn() with a
concrete implementation of that method—including RegularAction.
occursOn() determines if there are any tasks to report for this day, depending on the
type of Action subclass. For example, if something occurs every day, then the actual
date passed doesn’t really matter: any day you enter matches the requested date,
since that task happens every day.


Now create a class called ActionDriver to test your new subclass:
❖ Test that RegularAction is a subclass of Action
Output a string to indicate the type of test—”RegularAction is just a subclass
of Action: “—followed by the java reflection code needed to compare
RegularAction’s superclass with the Action class itself.
The expected output is ‘true’. So after you’ve compared RegularAction’s
superclass with the Action class itself (using ‘==‘), output a line to remind the
user that the expected output is true.




RegularAction is just a subclass of Action: true
Expected: true


❖ Since the only field used by RegularAction is inherited from its superclass, test
that RegularAction has no declared fields of its own.
Again, output a String that indicates the test for extra fields in RegularAction,
run the appropriate java reflection test, and indicate the expected result.




RegularAction activities have no extra fields:true
Expected: true


❖ Instantiate a new RegularAction constructor and load it with the message
indicated in the sample output. Having loaded an item, you should now be able
to output it’s description using the object’s toString() method. Then output the
result of occursOn() and the expected output.




RegularAction activities have no extra fields:true
Expected: true
Looking at regular actions: Wash your hands
Expected: Wash your hands
true
Expected: true


In Part 2 you add two more subclasses, OccasionalAction and RareAction, for items
that occur on the same day each month, and only once on a particular day, month,
and year, respectively. Again, the shell of these two class is provided for you, and
you must override the occursOn() method so that it returns true or false if the new
subclass object’s day, month, and year meet the requirement specified for that class.
Again, these two new classes should have appropriate constructors and overridden
concrete implementations of occursOn(), which returns an appropriate boolean value
depending on the requirements of the subclass.
Create a new test class, ActionDriver2, that includes tests for the following:
❖ Test that both test classes have the same superclass, Action
❖ Test the number of fields for each subclass. For the OccasionalAction class, only
the day of the month is required for a comparison. Hence the month has one
new declared field not found in the superclass. For the RareAction class, the day,
month and year are required, hence it has three new fields.
❖ Again, instantiate new instances of both subclasses, load a description, and test
the occursOn() method in each.


In Part 3 you’ll instantiate different Action objects, load them into an array, and
perform the tests indicated by the sample output—as described in the first slide.
❖ Load an array of Action objects of various types, i.e. Regular, Occasional, and
Rare. Create various different descriptions of the tasks to be performed.
❖ Instantiate a new Scanner, prompt the user to enter a date as three ints
corresponding to year, month, day (clearly indicating the order in which these
values are entered)
❖ Loop through the array of Action objects, test each object’s occursOn() method
against the three int’s just entered by the user, and then, whenever the method
returns true, print that object’s toString() method, displaying the task stored in
the object’s description field.


Notes:
❖ You cannot use an external class, like Calendar or Date, to perform the
operations that your code is supposed to do



TASKS: Draw a representation of the inheritance hierarchy between the classes provided in this assignment. You don't need to show the variables, methods or constructors in the classes.


/**
This is the Action Superclass class that provides a catalog of actions to be carried out in view of COVID-19 OPH protocols.
You are required to complete read and review this code to appropriately fill the required loopholes.
*/
public class Action
{
private String description;


/**
Constructs an action without a description.
*/
public Action()
{
description = "";
}


/**
Sets the description of this action.
@param description the text description of the action
*/
public void setDescription(String description)
{
this.description = description;
}


/**
Determines if this action occurs on the specified date.
@param year the year
@param month the month
@param day the day
@return true if the action activity occurs on the specified date.
*/


/**
YOUR TASK - TO DO: Write your abstract method named occursOn() here.
*/


/**
Converts action activity to string description.
*/
public String toString()
{
return description;
}
}



PART 1:



1. Review the starter-code that has been supplied for you actions named Action.java.



2. This Superclass (Action.java) has a subclass named RegularAction.java



3. Action has a description and could be carried out on one or more dates. An example of description could be "Wash your hands" or "Wear a face mask".



4. You should write an abstract method in the Superclass named occursOn(). This abstract method has parameters year, month and day which checks if the action occurs on the specific date.



5. Complete the starter-code provided for you on the RegularAction class (this shows the actions that happened regularly on an everyday basis). Hint: Observe the sample output provided to you for compliance.



6. Write an ActionDriver class that contains the main method to run your code. In writing the class named ActionDriver.java carefully follow the pattern of the output that has been provided. Instantiate required action objects to test this portion of your code.



SAMPLE OUTPUT FOR PART 1:



RegularAction is just a subclass of Action: true



Expected: true



RegularAction activities have no extra fields: true



Expected: true



Looking at regular actions: Wash your hands



Expected: Wash your hands



true



Expected: true


------------------------------------------------------------------------------------------------------------------


/**
In this file you will provide the code solution for Part 2.
You are required to create a subclass named OccasionalAction.
These are activities that occur on the same day of every month specified.
*/


// YOUR CODE STARTS HERE!!!


public class . . .
{
. . .


/**
In this file you will provide the code solution for Part 2.
You are required to create a subclass named RareAction.
Activities for RareAction occurs on a particular date of the year specified.
*/


// YOUR CODE STARTS HERE!!!
public class . . .
{
. . .



PART 2:



1. Include two more subclasses of the Superclass namely, OccasionalAction and RareAction. OccasionalAction shows actions that are conducted once each month, while RareAction depicts actions that take place only once on a specified day of the year.



2. Complete the starter-code provided for you for the two classes
OccasionalAction.java and RareAction.java. Hint: Be guided by obsering the sample output provided.



3. Your code must check if the action is carried out on that date.
For example, if dealing with anOccasionalAction that happens once a month, your code must ensure that the day of the month matches.



4.
Write an ActionDriver2 class that contains the main method to run this second part of your code. In writing the class named ActionDriver2.java carefully follow the pattern of the output that has been provided. Instantiate required action objects that suit both the OccasionalAction and RareAction subclasses.



SAMPLE OUTPUT FOR PART 2:



OccasionalAction is subclass of Action: true



Expected: true



RareAction is subclass of Action: true



Expected: true



OccasionalAction have no extra fields: true



Expected: true



RareAction have no extra fields: true



Expected: true


------------------------------------------------------------------------------------------------------------------


import java.util.Scanner;
/**
In this file, you are required to write code for your part Part 3.
The reason for this class is to demonstrate the Action class and subclasses.
You must fill an array of action objects (hint: check the sample output file provided for you) with
different action activities. A user of this system should be able to input a date of their choice and
retrieve an output of all activities that would occur on that date.
You should reuse the Action class and RegularAction classes from Part I of your solution
and then the OccasionalAction and RareAction classes from your Part 2.
*/


// YOUR CODE STARTS HERE!!!


public class AllActionTest
{
public static void main(String[] args)
{
. . .



Part 3:



1. Create a new class called AllActionTest.java with a main method to demonstrate your work.



2. In this class, create and fill an array of Action objects with different types of actions permitted by Ontario Public Health for the COVID-19 protocol including actions that should occur everyday, actions that occur once a month, and actions designated to occur only on a certain date in a year.



3. Implement your code (entire classes) such that the users can input a date and retrieve an output of all actions that would happen on that date.



SAMPLE OUTPUT FOR PART 3:



Enter a date (like 2010 01 30): 2022 05 01 These are your actions on 05/01/2022: Wash your hands. Take a PCR test. Sit two meters apart. Enter a date (like 2018 01 30): 2022 12 15 These are your actions on 12/15/2022: Wash your hands. Get a booster shot. Sit two meters apart. Enter a date (like 2018 01 30): 2022 06 01 These are your actions on 06/01/2022: Wash your hands. Take a PCR test. Get a booster shot. Sit two meters apart. Enter a date (like 2018 01 30): 2022 02 26 These are your actions on 02/26/2022: Wash your hands Sit two meters apart
Mar 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here