Question
Part 1: Hwk2Pet and Hwk2PetTester: Write the Java code for a Hwk2Pet class which matches the following description. Each pet will have a name, an
Part 1: Hwk2Pet and Hwk2PetTester: Write the Java code for a Hwk2Pet class which matches the following description.
Each pet will have a name, an animal type (dog, cat, etc.) and the year they were born. This data about each pet should be stored. Identify the instance variables and their types.
Each pet will be created using a no-argument constructor. Default values of your choice can be used to initialize the instance variables.
Each instance variable should have an accessor and mutator method (getters and setters).
In addition a printData() method that displays the values of all the data (instance variables) of a pet is needed.
NOTE: There should not be a main method in the Hwk2Pet class!
Write the Java code for a Hwk2PetTester class which matches the following description: Should contain a main method which does the following
Constructs four different Hwk2Pet objects.
Use the set methods to store a value in the name, animal, and year fields for each object.
Use the printData method on each object to display the contents of the object
IMPORTANT: Upload both Hwk2Pet.java and Hwk2PetTester.java files in the appropriate D2L Assignments folder.
Include comments in the entire code (program header, method header, variables)
Do your own work do not copy files or code from others!
Part 2: Hwk2Square Class
Create a class called Hwk2Square which has the following instance variable (do NOT add any other instance variables to the class):
Length of sides (could be decimal values)
Methods
Create the constructor which receives the length of the sides as a parameter
setLength. This method stores a value in the length instance variable
getLength. This method returns the value of the length instance variable
computeArea. This method returns the area of the square
computePerimeter. This method returns the perimeter of the square
printData. This method should display the contents of each the instance variables in a nice format
NOTE: There should not be a main method in the Hwk2Square class!
Hwk2SquareTester Class
Create a class called Hwk2SquareTester which constructs four different Square objects
For each Square object you created:
SOP the squares length
SOP the squares area
SOP the squares perimeter
Notes
Upload to the D2L Dropbox
Hwk2Square.java
Hwk2SquareTester.java
Include comments in the entire code (program header, method header, variables)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started