Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class PetRecord { private String name; private int age;//in years private double weight;//in pounds public String toString( ) { return (Name: + name

public class PetRecord
{
private String name;
private int age;//in years
private double weight;//in pounds
public String toString( )
{
return ("Name: " + name + " Age: " + age + " years"
+ " Weight: " + weight + " pounds");
}
public PetRecord(String initialName, int initialAge,
double initialWeight)
{
name = initialName;
if ((initialAge
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = initialAge;
weight = initialWeight;
}
}
public void set(String newName, int newAge, double newWeight)
{
name = newName;
if ((newAge
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = newAge;
weight = newWeight;
}
}
public PetRecord(String initialName)
{
name = initialName;
age = 0;
weight = 0;
}
public void setName(String newName)
{
name = newName;
}
public PetRecord(int initialAge)
{
name = "No name yet.";
weight = 0;
if (initialAge
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = initialAge;
}
public void setAge(int newAge)
{
if (newAge
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = newAge;
}
public PetRecord(double initialWeight)
{
name = "No name yet";
age = 0;
if (initialWeight
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = initialWeight;
}
public void setWeight(double newWeight)
{
if (newWeight
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = newWeight;
}
public PetRecord( )
{
name = "No name yet.";
age = 0;
weight = 0;
}
public String getName( )
{
return name;
}
public int getAge( )
{
return age;
}
public double getWeight( )
{
return weight;
}
}
image text in transcribed
Using the PetRecord class stored on Canvas, write a driver program (main) with a main method to read in data from the user for five Pets and display the following data: name of smallest pet, name of largest pet, name of oldest pet, name of youngest pet, average weight of the five pets, and average age of the five pets. Also, test to see if any of the five pets are the same

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

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago