Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question involves the use of an object and a Tester class. A pet shop had a program to keep track of the current pets

This question involves the use of an object and a Tester class. A pet shop had a program to keep track of the current pets being offered for adoption. The Pets class contains all of the information about a particular pet available in the shop. In part a of this question, you will implement the constructor and the methods identified below. In part b of this question, you will implement the tester for the program. The general form for the classes can be found below.

public class Pets {

//declare instance variables for pet name, pet breed and pet age //create the default constructor //create the constructor with parameters //setter & getter methods for petName, petBreed and petAge

}

public class PetsTester {

public static void main (String [] args) {

//to be implemented in part b }

}

Part A

Write the instance variables, constructor, getter and setter methods for the Pets class. The constructor takes three parameters. The first one is a String containing the name of the pet. The second is a String containing the breed of the pet, such a dog, cat or reptile. The third is an int variable containing the age of the pet. The class should also contain the getter and setter methods for the object. The getter methods, when called, should return the value for the associated instance variable. The setter methods when called will take a single parameter and use the parameter to update the appropriate instance variable.

Example 1 An object is constructed in the Tester class with the values (Samantha, cat, 5)

After the code segment has executed, the instance variables will contain the word Samantha in the instance variable petName, the word cat in the instance variable petBreed and a 5 in the instance variable petAge.

Example 2 An object is constructed in the tester class with the values (Kelson, dog, 2)

After the code segment has executed, the instance variables will contain the word Kelson in the instance variable petName, the word dog in the instance variable petBreed and a 2 in the instance variable petAge.

Class information for this question

public class Pets

public Pets(String name, String breed, int age) public String getName() public String getBreed() public int getAge()

public void setName(String newName) public void setBreed(String newBreed) public void setAge(int newAge)

Part B

Create the tester class for the Pets program. The tester should contain the main method. In the main method, the program should do the following things:

  • Ask the user for the name of the pet

  • Ask the user for the breed of the pet

  • Ask the user for the pets age

  • The program should create a Pets object based on the information collected from the

    user,

  • Using the appropriate methods of the Pets object, the program should print the name,

    breed and age of the pet to the console (screen).

  • After the information is finished, the program should ask the user if they would like to

    enter another pet. o Iftheanswerisyes,theprogramshouldrunagain. o Iftheanswerisno,theprogramshouldexitandtelltheusergoodbye.

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

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago