Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

TestPet.java Test Harness /* * Lab 02 * * Test harness provided to students to test class 'Pet'. * * MAKE NO CHANGES TO THIS

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

TestPet.java Test Harness

/* * Lab 02 * * Test harness provided to students to test class 'Pet'. * * MAKE NO CHANGES TO THIS TEST HARNESS! * * * (c) 2019, Terri Davis */ import java.util.Scanner; // Scanner class to support user input

public class TestPet { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Objects & Variables required for processing */ Scanner input = new Scanner( System.in ); // Set the keyboard as the input device for this process String name, // These String objects will hold the user input to be used species, // when calling the full constructor method of class Pet. parent, // For simplicity, we have used the same names here as the birthday; // names given to the instance variables in the Class definition. boolean again = true; // This boolean controls the while loop we will use. String response; // This String holds the user's response re: continuing the loop. Pet spot = new Pet( ); // This is simply a 'holding space' for the object(s) we create. while( again ) // Continue the loop until the user says otherwise... { // Collect the necessary input from the user System.out.println( "Please enter the pet's name: " ); name = input.next( ); System.out.println( "Please enter the pet's species (NOT breed): " ); species = input.next( ); System.out.println( "Please enter the pet's parent's name: " ); parent = input.next( ); System.out.println( "Please enter the pet's birthday in yyyy/mm/dd format: " ); birthday = input.next( ); // Using the user-provided data, INSTANTIATE a Pet object by calling the full constructor spot = new Pet( name, // User-provided Pet name species, // User-provided Pet species parent, // User-provided Pet parent birthday ); // User-provided Pet birthday // Using the Pet object named 'spot', call the toString method and output the results System.out.printf( "%n %s", spot.toString( ) ); // Ask if the user wants to enter another Pet System.out.printf( "%n%nDo you wish to enter another Pet? (Yes or No)" ); response = input.next( ); // Test the user input if( response.equals( "No" ) ) again = false; } // end while loop // Let user know we are finished System.out.printf( "%n%n Thank you!" ); } // end main } // end TestPet

Lab 02 Defining a Class; Objects, & instantiation General Information This lab will review defining a Class of objects, instantiating objects of that class, and calling methods of an instantiated object. Instructions Write a Java class named Pet to meet the requirements described in the UML Class Diagram attached to the assignment. This lab will adhere to the published Coding Standards. Failure to follow the standards will have a significant and negative affect on your grade for the lab. Zip your source code (and only your source code) and submit the zipped folder as an attachment to the assignment in Blackboard. DO NOT submit edit/backup versions (with the in the file type) or compiled code (.class files); submission of either will result in a grade of zero (0). Provided to You The following resources are provided: These instructions, including sample toString output The UML Class Diagram for class Pet A test harness to use in testing your Pet.java code o NOTE: Grading does not use the provided test harness. The code used for grading will verify that your submitted code follows the published Coding Standards Requirements The provided UML Class Diagram describes the requirements for the class Pet. In addition to the requirements described there, be aware of the requirements included in the Coding Standards. Specifically be aware of the following: All get and set methods must be named according to industry standards, based on the provided UML document. All get and set methods must be 'final' methods. (We will discuss this at greater length in the lecture class.) The only direct access to instance variable values is through the set and get methods; no other direct access is every permitted. Expected toString Output Your output need not be identical to that shown here, but you MUST include all instance values in the output, in the order shown. Spot, whose fur-parent is Data, is a Cat, born on 1991/01/05 Mr. Ed, whose fur-parent is Wilbur, is a Horse, born on 1961/01/04 Grading Grading rubric for this lab: Submission Pet.java submitted, compiles cleanly, is defined correctly, & functions exactly as required Pet.java submitted, compiles cleanly, is defined correctly, but some output is missing Pet.java submitted, compiles cleanly, but output is incorrect Any submission that does not match one of the above groupings. This will include any significant transgression of Coding Standards. Grade 100% 80% 70% 0% Attributes private name: String private species: String private parent: Strin private birthday: String Pet's name Pet's species (NOTE: not breed) Pet's parent (owner) name Pet's birthday in www/mm/dd format: 2017/02/28 Operations public Pet ): Pet public > Pet (name: String, Default or null constructor; returns a reference to a fully functional Pet object Constructor accepting four (4) parameters, all of type String. Returns areference to a fully formed and functional Pet object species: String, parent: String, birthday: String): Pet public setName aName: String ): void public setSpecies( aSpecies: String ): void Accepts a String object (local name: aName) and assigns it to the instance variable name Accepts a String object (local name: aSpecies) and assigns it to the instance variable species public setParent(aParent: String): void public setBirthday( aBDay: String): void public getName(): String public getSpecies(): String public getParent: Strin public getBirthday): String Accepts a String object (local name: aParent) and assigns it to the instance variable parent Accepts a String object (local name: aBDay) and assigns it to the instance variable birthda Returns the current value of instance variable name Returns the current value of instance variable species Returns the current value of instance variable parent Returns the current value of instance variable birthda public toString:Strin Returns a formatted String containing a verbose description of the Pet object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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