Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help writing a java program called DogDemo class that reads in five pets of

ID: 3546062 • Letter: N

Question

Need help writing a java program called DogDemo class that reads in five pets of type Dog and displays the name and breed of all dogs that are over two tears old and have not had thier booster shots.

This is what i have so far.


public class Dog extends Pet
{
private String breed = null;
private boolean booster;

public Dog()
{
super();
breed = "undefined";
}

public Dog(String newBreed, boolean boosterShot)
{
booster = boosterShot;
breed = newBreed;
}

public void reset(String newName, String newBreed, boolean boosterShot)
{
setName(newName);
booster = boosterShot;
breed = newBreed;
}

public String getBreed()
{
return breed;
}

public boolean getBooster()
{
return booster;
}

public void setBoosterShot(boolean newboosterShot)
{
booster = newboosterShot;
}

public void setBreed(String newBreed)
{
breed = newBreed;
}

public void writeOutput()
{
System.out.println("name: " + super.getName());
System.out.println("age: " + super.getAge());
System.out.println("weight: " + super.getWeight());
System.out.println("boosterShot: " + getBooster());
System.out.println("breedName: " + getBreed());
}
}


public class Pet {
public String name;
private int age; //in years
private double weight;//in pounds
public Pet() {
name = ".";
age = 0;
weight = 0;
}

public Pet(String initialName, int initialAge,
double initialWeight) {
name = initialName;
if ((initialAge < 0) || (initialWeight < 0)) {
System.out.println("Error: Negative age or weight.");
System.exit(0);
} else {
age = initialAge;
weight = initialWeight;
}
}
public void setPet(String newName, int newAge,
double newWeight) {
name = newName;
if ((newAge < 0) || (newWeight < 0)) {
System.out.println("Error: Negative age or weight.");
System.exit(0);
} else {
age = newAge;
weight = newWeight;
}
}
public Pet(String initialName) {
name = initialName;
age = 0;
weight = 0;
}
public void setName(String newName) {
name = newName; //age and weight are unchanged.
}
public Pet(int initialAge) {
name = "No name yet.";
weight = 0;
if (initialAge < 0) {
System.out.println("Error: Negative age.");
System.exit(0);
} else
age = initialAge;
}
public void setAge(int newAge) {
if (newAge < 0) {
System.out.println("Error: Negative age.");
System.exit(0);
} else
age = newAge;
//name and weight are unchanged.
}
public Pet(double initialWeight) {
name = "No name yet";
age = 0;
if (initialWeight < 0) {
System.out.println("Error: Negative weight.");
System.exit(0);
} else
weight = initialWeight;
}
public void setWeight(double newWeight) {
if (newWeight < 0) {
System.out.println("Error: Negative weight.");
System.exit(0);
} else
weight = newWeight; //name and age are unchanged.
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public double getWeight() {
return weight;
}
public void writeOutput() {
System.out.println("Name: " + name);
System.out.println("Age: " + age + " years");
System.out.println("Weight: " + weight + " pounds");
}
}





Explanation / Answer

Hai bro i just made some changes in your Dog Class just check it out and now copy the program save it with Dog file name and compile it the Run the Dog Class u will get the output


public class Dog extends Pet

{

private String breed = null;

private boolean booster;


public Dog()

{

super();

breed = "undefined";

}


public Dog(String newBreed, boolean boosterShot)

{

booster = boosterShot;

breed = newBreed;

}


public void reset(String newName, String newBreed, boolean boosterShot)

{

setName(newName);

booster = boosterShot;

breed = newBreed;

}


public String getBreed()

{

return breed;

}


public boolean getBooster()

{

return booster;

}


public void setBoosterShot(boolean newboosterShot)

{

booster = newboosterShot;

}


public void setBreed(String newBreed)

{

breed = newBreed;

}


public void writeOutput()

{

System.out.println("name: " + super.getName());

System.out.println("age: " + super.getAge());

System.out.println("weight: " + super.getWeight());

System.out.println("boosterShot: " + getBooster());

System.out.println("breedName: " + getBreed());

}

public static void main(String r[]){


Dog d=new Dog();

d.setBreed("pamelian");

d.setAge(2);

d.setWeight(12);

d.setBoosterShot(true);

d.setName("rocky");



d.writeOutput();

}

}



class Pet {

public String name;

private int age; //in years

private double weight;//in pounds

public Pet() {

name = ".";

age = 0;

weight = 0;

}


public Pet(String initialName, int initialAge,

double initialWeight) {

name = initialName;

if ((initialAge < 0) || (initialWeight < 0)) {

System.out.println("Error: Negative age or weight.");

System.exit(0);

} else {

age = initialAge;

weight = initialWeight;

}

}

public void setPet(String newName, int newAge,

double newWeight) {

name = newName;

if ((newAge < 0) || (newWeight < 0)) {

System.out.println("Error: Negative age or weight.");

System.exit(0);

} else {

age = newAge;

weight = newWeight;

}

}

public Pet(String initialName) {

name = initialName;

age = 0;

weight = 0;

}

public void setName(String newName) {

name = newName; //age and weight are unchanged.

}

public Pet(int initialAge) {

name = "No name yet.";

weight = 0;

if (initialAge < 0) {

System.out.println("Error: Negative age.");

System.exit(0);

} else

age = initialAge;

}

public void setAge(int newAge) {

if (newAge < 0) {

System.out.println("Error: Negative age.");

System.exit(0);

} else

age = newAge;

//name and weight are unchanged.

}

public Pet(double initialWeight) {

name = "No name yet";

age = 0;

if (initialWeight < 0) {

System.out.println("Error: Negative weight.");

System.exit(0);

} else

weight = initialWeight;

}

public void setWeight(double newWeight) {

if (newWeight < 0) {

System.out.println("Error: Negative weight.");

System.exit(0);

} else

weight = newWeight; //name and age are unchanged.

}

public String getName() {

return name;

}

public int getAge() {

return age;

}

public double getWeight() {

return weight;

}

public void writeOutput() {

System.out.println("Name: " + name);

System.out.println("Age: " + age + " years");

System.out.println("Weight: " + weight + " pounds");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote