Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help coding this TEST_INTERFACEIMPLEMENTATION Code: /* * Lab 05 * * Code to test the Assignment class hierarchy, the Event class, and those

i need help coding this

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

TEST_INTERFACEIMPLEMENTATION Code:

/*

* Lab 05

*

* Code to test the Assignment class hierarchy, the Event class, and those classes' use of the

* DateFormat interface.

*

* This is a very "thin" testing process. Students are STRONGLY ENCOURAGED to add additional

* test cases to this code.

*

* (c) 2020 Terri Davis

*/

public class Test_InterfaceImplementation

{

/*

* An array to hold various objects of types implementing the DateFormat interface should be

* declared and instantiated GLOBALLY here.

*

* Instantiate the array to hold five (5) objects of types using the interface.

*

* The array must use the "private" access identifier. Also - remember that this array will be

* accessed directly from the main method of the code - that also has implications on how the

* array must be declared.

*

*/

>>>>>>>>>>>>>> DECLARE AND INSTANTIATE THE ARRAY HERE

public static void main( String[] args )

{

/*

* The executable code called in the next statement has been provided to students.

*

* Please note that CODE THAT FAILS THIS STANDARDS CHECK WILL EARN A GRADE OF ZERO.

*/

Lab05_StdsCheck.standardsCheck( );

/*

* Instantiate objects of IMPLEMENTOR CLASSES of the INTERFACE DateFormat &

* store each object references individually in the global array

*/

dateFormats[0] = new Assignment( "GBA2013", // SUPERclass Assignment full constructor

"007",

"20200301" );

dateFormats[1] = new Quiz( "ACC2003", // SUBclass Quiz full constructor

"015",

"20200131",

"T-Accounts",

25,

true );

dateFormats[2] = new Project( "IS2043", // SUBclass Project full constructor

"005",

"20200202",

"Programming Assignment 01",

false );

dateFormats[3] = new Event( "Graduation", // Class Event full constructor

"AlamoDome",

null, // No eventRoom data for this object

"20200523" );

dateFormats[4] = new Event( "Grad Program Info Session", // Class Event full constructor

"NPB",

"3.01.10",

"20200221" );

/*

* Use an ENHANCED FOR LOOP to output the toString return for every object

* in the (global) array

*

* You will complete this control statement in the enhanced for loop construct

*/

System.out.printf( "%n%n\t\tObjects of Assignment Hierarchy%n%n" );

for( >>>>>>>>>>>> ADD THE CONTROL STATEMENT HERE

{

System.out.printf( "%s\tDays remaining: %d%n%n",

nextItem.toString( ),

nextItem.findDiffDays( nextItem.formatDateShort( ) ) );

} // end enhanced for loop

} // end main

} // end Test_AssignmentHierarchy

ASSIGNMENT code:

public class Assignment { private String assignCourse, assignSctn, assignDue; //int

public Assignment(){ //public } public Assignment(String assignCourse, String assignSctn, int assignDue) { //public this.assignCourse = assignCourse; this.assignSctn = assignSctn; this.assignDue = assignDue; }

public String toString() { //public string return "Assingment is due on " + this.getAssignDue() + " for " + this.getAssignCourse() + "." + this.getAssignSctn() + " "; } }

Quiz code:

public class Quiz extends Assignment{ private String quizName; // string private int quizNbrQuests; //int private boolean quizRetake; //boolean public Quiz(){ //public super(); } public Quiz(String assignCourse, String assignSctn, String assignDue, String quizName, int quizNbrQuests, boolean quizRetake ) { //full constructor super(assignCourse, assignSctn, assignDue ); this.quizName = quizName; this.quizNbrQuests = quizNbrQuests; this.quizRetake = quizRetake;

} public String toString(){ //string return super.toString() +this.getQuizName() + " has " + this.getQuizNbrQuests() + " questions. Retake(s) available: " + this.getQuizRetake() + " "; } }

Project Code:

public class Project extends Assignment{ private String projDesc; //string private boolean projGroup; //boolean public Project(){ //public super(); } public Project(String assignCourse, String assignSctn, String assignDue, String projDesc, boolean projGroup){ //full constructor public super(assignCourse, assignSctn, assignDue); this.projDesc = projDesc; this.projGroup = projGroup;

}

public String toString(){ //string return super.toString() + "Is " + this.getProjDesc() + " a group project: " + this.getProjGroup() + " "; } }

Event Code so far:

public class Event extends Assignment{ private String eventName, eventBldg, eventRoom,eventDate; public Event(){ } public Event(String eventName, String eventBldg, String eventRoom, String eventDate) { //public this.eventName = eventName; this.eventBldg = eventBldg; this.eventRoom = eventRoom; this.eventDate = eventDate; } public default String formatTodayShort()

String date = String year = date.substring(0,4); String month = date.substring(4, 6); String day = date.substring(6);

public String toString(){ //string return super.toString() + "Is " + this.eventName() + " a group project: " + this.getProjGroup() + " ";

}

Expected Output:

image text in transcribed

Lab 05 Interfaces and Polymorphism General Information Object-oriented languages support polymorphism, the ability to tailor processing of an object based on that object's type or class. In this lab, you will modify your Assignment hierarchy to use an interface, and then make changes to the test harness to allow it to test both your hierarchy as well as an unrelated class (Event), with respect to how well those classes have implemented the interface. Instructions A minor change has been made to the definition of the Assignment class - the assignDue instance variable is now defined as a String type. This change "flows through to the subclasses; appropriate modifications will be required in those modules as well. The hierarchy of classes beginning with Assignment will use the interface DateFormat. You will make the required changes to the class definition(s) to support this new requirement. This lab will use an interface named DateFormat interface. You are not required to write any code for the interface - your lab materials include the executable code for the interface. This lab introduces a new and unrelated class, Event, which also uses the DateFormat interface. You are not required to write any code for this class - your lab materials include the executable code for the class. This lab will adhere to the published Basic Coding Standards. Failure to follow the standards will result in an assignment grade of zero (O). Zip the three (3).java source files (Assignment.java, Quiz.java, and Project.java) into a compressed folder named Lab05 Submission. Include source code for the object classes only in the zipped folder. DO NOT include the test harness (TestInterface Implementation.java), edit/backup versions (with the in the file type) of the source code, or any compiled code (.class files); submission of either will result in a grade of zero (O). Submit only the zipped folder Lab05 Submission as an attachment to this assignment. Provided to You The following resources are provided: These instructions, including sample output UML Class Diagrams Showing the changes in the Assignment hierarchy o Describing the new class Event O Describing the interface DateFormat Executable class files for the code you will use, but not write: o Event.class o DateFormat.class o Lab@5_Stds_Check.class A test harness (which you will complete) to test your implementation of the DateFormat interface. Requirements 1. Review the provided UML Diagrams. The executable code for the class Event and the interface DateFormat are part of the provided materials for this lab; you are not required to write that code. Modify classes Assignment, Quiz, Project as needed to meet the revised requirements described in the UML Class Diagrams attached to the assignment. (See the green highlighted portions of the UML diagrams.) 3. Add the necessary code to the Assignment hierarchy to permit those classes to use the DateFormat interface. 4. Make the required additions to Test Interface Implementation.java code: a. LINE 26: Add the declaration and instantiation of an array. i. The array must hold five (5) objects of class types that use the interface DateFormat. ii. The array must be marked as private - that is, inaccessible outside the scope of the test code. iii. Keep in mind that main method of the test code accesses the array directly. This has implications for the declaration of the array. b. LINE 78: Add the control statement required to control the enhanced for loop here. 5. Be sure you have the following executables in your folder along with your modified code: a. DateFormat.class b. Event.class C. Labo5_Stds_Check.class 6. Compile and execute your modified code. NOTE: Some standards violations will prevent the package from compiling. Compile error messages should assist in isolating the standards violations. Hints There are several ways to "break up" a String object into parts in order to rearrange those parts or reformat them. Chapter 14 of the text covers some of these methods. You are welcome to use whatever process you choose to do the "slicing and dicing" needed to support the interface functionality. The code below is from the Event class source code and shows one way to solve the problem. String date = // retrieve date field from this object String year = date.substring( 0, 4); // "slice out year portion String month = date.substring( 4, 6); // "slice out month portion String day = date.substring( 6); // "slice out day portion Once you have the "parts" of the date, you can be rearrange and/or format as needed. Attributes private assignCourse: String private assignSctn: String private assignDue: String Assignment implements DateFormat) Notes The course number of the class for this assignment (e.g. IS2041, ACC2003, etc.) The section number of the class for this assignment (e.g., 001, EB1, etc.) The due date for this assignment in yyyymmdd format (e.g., 20200331 for March 30, 2020) Operations public Assignment(): Assignment Description A null constructor returning a reference to an Assignment object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) A full constructor, requiring one input parameter per instance value, returning a reference to an Assignment object whose instance variables have all been set to specified values public Assignment(course:String, sctn: String, due: int): Assignment public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. 4. PLEASE NOTE: The type of the assignDue instance variable has been changed. Also - see sample output for change in toString output Attributes private quizName: String private quizNbrQuests: int private quizRetake: boolean Quiz (subclass of Assignment) Notes A name identifying the quiz (e.g., Chapter 09, Review, etc.) The number of questions on the quiz May more than one attempt be made for this quiz? True or false Operations public Quiz(): Quiz Description A null constructor returning a reference to an Quiz object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) This constructor must call the superclass null constructor A full constructor, requiring one input parameter per instance value, returning a reference to an Quiz object whose instance variables have all been set to specified values The superclass full constructor must be called from this full constructor public Quiz( course: String, sctn: String, due: String, name: String, quests: int, retake: boolean ): Quiz public toString(): String Returns a reference to a string object containing a complete description of this Quiz object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes private projDesc: String private projGroup: boolean Project (a subclass of Assignment) Notes A description of the project; may be verbose Is this a team project or individual? True = team; false = individual Operations public Project(): Project Description A null constructor returning a reference to an Project object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) This constructor must call the superclass null constructor A full constructor, requiring one input parameter per instance value, returning a reference to an Project object whose instance variables have all been set to specified values The superclass full constructor must be called from this full constructor public Project(course: String, sctn: String, due: String, desc: String, team: boolean ): Project public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes private eventName: String private eventBldg: String Event (implements DateFormat) Notes The name of the event (e.g., "Health Svcs Blood Drive") The building (or other location) at which the event will be held (e.g. "BB" for the Business Building, "NPB" for North Paseo Building) The room in which the event will be held (e.g., 3.01.10). If there is no room (for example, if the event is held in the Convocation Center), this will be a null reference. private eventRoom: String private eventDate: String The event date in yyyymmdd format (e.g., 20200512 for May 12, 2020) Operations public Event(): Event Description A null constructor returning a reference to an Event object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) public Event( name: String, bldg: String, room: String, date: String): Event A full constructor, requiring one input parameter per instance value, returning a reference to an Event object whose instance variables have all been set to specified values public formatDateShort(): String As required by interface DateFormat public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes DateFormat (interface) Notes interfaces do not typically define attributes.... Operations public default formatTodayShort(): String public default formatTodayLong(): String public default formatDateDdMmYyyy( int year, int month, int day): String Description Returns a reference to a string object containing today's date (as per the processor clock) formatted as: MM/DD/YYYY Returns a reference to a string object containing today's date (as per the processor clock) formatted as: DAYNAM, MONTHNAME dd, yyyy (e.g.: MONDAY, JANUARY 6, 2020) Returns a reference to a string object containg a formatted date based on the year, month, and day values passed to the method. The formatted String includes the long- form month name, e.g.: 29 February, 2020. Date validation is managed within the method. Returns the difference, in calendar days, between today's date (as per the processor clock) and the date represented by the passed String reference. The passed date should be in the short format: MM/DD/YYYY. This method must be provided in implementor types. The String reference returned from this method must be in the short format: MM/DD/YYYY public defaul find DiffDays( String shortformat ): long public abstract formatDateShort(): String Expected Output Execution of the provided test harness should produce the results shown here. Slight alterations in spacing or of wording within the toString return are acceptable, but order of data items must match that shown. *** Some number will appear here **** Assignment.java passed minimal standards check. Quiz.java passed minimal standards check. Project.java passed minimal standards check. Event.java passed minimal standards check. Assignment implementation passes check Event implementation passes check Project implementation passes check Quiz implementation passes check Objects of Assignment Hierarchy Assignment is due on 03/01/2020 for GBA2013.007 Days remaining: 54 Quiz is due on 01/31/2020 for ACC2003.015 T-Accounts has 25 questions. Retake(s) available: true Days remaining: 24 Project is due on 02/02/2020 for IS2043.005 Is Programming Assignment 01 a group project: false Days remaining: 26 Event Graduation will take place on 05/23/2020 at AlamoDome. Days remaining: 137 Event Grad Program Info Session will take place on 02/21/2020 at NPB Room 3.01.10. Days remaining: 45 Lab 05 Interfaces and Polymorphism General Information Object-oriented languages support polymorphism, the ability to tailor processing of an object based on that object's type or class. In this lab, you will modify your Assignment hierarchy to use an interface, and then make changes to the test harness to allow it to test both your hierarchy as well as an unrelated class (Event), with respect to how well those classes have implemented the interface. Instructions A minor change has been made to the definition of the Assignment class - the assignDue instance variable is now defined as a String type. This change "flows through to the subclasses; appropriate modifications will be required in those modules as well. The hierarchy of classes beginning with Assignment will use the interface DateFormat. You will make the required changes to the class definition(s) to support this new requirement. This lab will use an interface named DateFormat interface. You are not required to write any code for the interface - your lab materials include the executable code for the interface. This lab introduces a new and unrelated class, Event, which also uses the DateFormat interface. You are not required to write any code for this class - your lab materials include the executable code for the class. This lab will adhere to the published Basic Coding Standards. Failure to follow the standards will result in an assignment grade of zero (O). Zip the three (3).java source files (Assignment.java, Quiz.java, and Project.java) into a compressed folder named Lab05 Submission. Include source code for the object classes only in the zipped folder. DO NOT include the test harness (TestInterface Implementation.java), edit/backup versions (with the in the file type) of the source code, or any compiled code (.class files); submission of either will result in a grade of zero (O). Submit only the zipped folder Lab05 Submission as an attachment to this assignment. Provided to You The following resources are provided: These instructions, including sample output UML Class Diagrams Showing the changes in the Assignment hierarchy o Describing the new class Event O Describing the interface DateFormat Executable class files for the code you will use, but not write: o Event.class o DateFormat.class o Lab@5_Stds_Check.class A test harness (which you will complete) to test your implementation of the DateFormat interface. Requirements 1. Review the provided UML Diagrams. The executable code for the class Event and the interface DateFormat are part of the provided materials for this lab; you are not required to write that code. Modify classes Assignment, Quiz, Project as needed to meet the revised requirements described in the UML Class Diagrams attached to the assignment. (See the green highlighted portions of the UML diagrams.) 3. Add the necessary code to the Assignment hierarchy to permit those classes to use the DateFormat interface. 4. Make the required additions to Test Interface Implementation.java code: a. LINE 26: Add the declaration and instantiation of an array. i. The array must hold five (5) objects of class types that use the interface DateFormat. ii. The array must be marked as private - that is, inaccessible outside the scope of the test code. iii. Keep in mind that main method of the test code accesses the array directly. This has implications for the declaration of the array. b. LINE 78: Add the control statement required to control the enhanced for loop here. 5. Be sure you have the following executables in your folder along with your modified code: a. DateFormat.class b. Event.class C. Labo5_Stds_Check.class 6. Compile and execute your modified code. NOTE: Some standards violations will prevent the package from compiling. Compile error messages should assist in isolating the standards violations. Hints There are several ways to "break up" a String object into parts in order to rearrange those parts or reformat them. Chapter 14 of the text covers some of these methods. You are welcome to use whatever process you choose to do the "slicing and dicing" needed to support the interface functionality. The code below is from the Event class source code and shows one way to solve the problem. String date = // retrieve date field from this object String year = date.substring( 0, 4); // "slice out year portion String month = date.substring( 4, 6); // "slice out month portion String day = date.substring( 6); // "slice out day portion Once you have the "parts" of the date, you can be rearrange and/or format as needed. Attributes private assignCourse: String private assignSctn: String private assignDue: String Assignment implements DateFormat) Notes The course number of the class for this assignment (e.g. IS2041, ACC2003, etc.) The section number of the class for this assignment (e.g., 001, EB1, etc.) The due date for this assignment in yyyymmdd format (e.g., 20200331 for March 30, 2020) Operations public Assignment(): Assignment Description A null constructor returning a reference to an Assignment object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) A full constructor, requiring one input parameter per instance value, returning a reference to an Assignment object whose instance variables have all been set to specified values public Assignment(course:String, sctn: String, due: int): Assignment public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. 4. PLEASE NOTE: The type of the assignDue instance variable has been changed. Also - see sample output for change in toString output Attributes private quizName: String private quizNbrQuests: int private quizRetake: boolean Quiz (subclass of Assignment) Notes A name identifying the quiz (e.g., Chapter 09, Review, etc.) The number of questions on the quiz May more than one attempt be made for this quiz? True or false Operations public Quiz(): Quiz Description A null constructor returning a reference to an Quiz object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) This constructor must call the superclass null constructor A full constructor, requiring one input parameter per instance value, returning a reference to an Quiz object whose instance variables have all been set to specified values The superclass full constructor must be called from this full constructor public Quiz( course: String, sctn: String, due: String, name: String, quests: int, retake: boolean ): Quiz public toString(): String Returns a reference to a string object containing a complete description of this Quiz object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes private projDesc: String private projGroup: boolean Project (a subclass of Assignment) Notes A description of the project; may be verbose Is this a team project or individual? True = team; false = individual Operations public Project(): Project Description A null constructor returning a reference to an Project object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) This constructor must call the superclass null constructor A full constructor, requiring one input parameter per instance value, returning a reference to an Project object whose instance variables have all been set to specified values The superclass full constructor must be called from this full constructor public Project(course: String, sctn: String, due: String, desc: String, team: boolean ): Project public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final" methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes private eventName: String private eventBldg: String Event (implements DateFormat) Notes The name of the event (e.g., "Health Svcs Blood Drive") The building (or other location) at which the event will be held (e.g. "BB" for the Business Building, "NPB" for North Paseo Building) The room in which the event will be held (e.g., 3.01.10). If there is no room (for example, if the event is held in the Convocation Center), this will be a null reference. private eventRoom: String private eventDate: String The event date in yyyymmdd format (e.g., 20200512 for May 12, 2020) Operations public Event(): Event Description A null constructor returning a reference to an Event object whose instance variables have all been set to "neutral defaults" (i.e., null String references or zeros) public Event( name: String, bldg: String, room: String, date: String): Event A full constructor, requiring one input parameter per instance value, returning a reference to an Event object whose instance variables have all been set to specified values public formatDateShort(): String As required by interface DateFormat public toString(): String Returns a reference to a string object containing a complete description of this Assignment object NOTES: 1. Accessor and mutator methods are not listed here, but are assumed to be present and to use standard naming. 2. Mutator and accessor methods must be defined as "final methods. There is no exception to this rule. 3. Direct access to instance variables/values is permitted ONLY through the appropriate mutator/accessor methods. Ever. Period. Attributes DateFormat (interface) Notes interfaces do not typically define attributes.... Operations public default formatTodayShort(): String public default formatTodayLong(): String public default formatDateDdMmYyyy( int year, int month, int day): String Description Returns a reference to a string object containing today's date (as per the processor clock) formatted as: MM/DD/YYYY Returns a reference to a string object containing today's date (as per the processor clock) formatted as: DAYNAM, MONTHNAME dd, yyyy (e.g.: MONDAY, JANUARY 6, 2020) Returns a reference to a string object containg a formatted date based on the year, month, and day values passed to the method. The formatted String includes the long- form month name, e.g.: 29 February, 2020. Date validation is managed within the method. Returns the difference, in calendar days, between today's date (as per the processor clock) and the date represented by the passed String reference. The passed date should be in the short format: MM/DD/YYYY. This method must be provided in implementor types. The String reference returned from this method must be in the short format: MM/DD/YYYY public defaul find DiffDays( String shortformat ): long public abstract formatDateShort(): String Expected Output Execution of the provided test harness should produce the results shown here. Slight alterations in spacing or of wording within the toString return are acceptable, but order of data items must match that shown. *** Some number will appear here **** Assignment.java passed minimal standards check. Quiz.java passed minimal standards check. Project.java passed minimal standards check. Event.java passed minimal standards check. Assignment implementation passes check Event implementation passes check Project implementation passes check Quiz implementation passes check Objects of Assignment Hierarchy Assignment is due on 03/01/2020 for GBA2013.007 Days remaining: 54 Quiz is due on 01/31/2020 for ACC2003.015 T-Accounts has 25 questions. Retake(s) available: true Days remaining: 24 Project is due on 02/02/2020 for IS2043.005 Is Programming Assignment 01 a group project: false Days remaining: 26 Event Graduation will take place on 05/23/2020 at AlamoDome. Days remaining: 137 Event Grad Program Info Session will take place on 02/21/2020 at NPB Room 3.01.10. Days remaining: 45

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_2

Step: 3

blur-text-image_3

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago