Question: Hey, in Java, I tried doing these next couple steps in my program but keep getting errors. I think my syntax is wrong and need

Hey, in Java, I tried doing these next couple steps in my program but keep getting errors. I think my syntax is wrong and need help. I have a HomePets and Pets class and a Homepets Driver. My Pets class I figured out but its the HomePets class that I need help with.

What I have to do:

1. Implement two methods totalPrice and totalWeight where it returns the total price and total weight of the home pets respectively.

2. Write statements that prints the two methods mentioned in the previous step.

3. Implement getter bethods for dog and cat instance variables.

4, In the Driver, add statements that add 10 the price of myPet's dog and subtract 5 from the price of myPet's cat and then print the total price again. (The object created in Driver.)

5. In Driver, print myPets again to make sure that the prices have changed.

my HomePets class:

public class HomePets { private String ownerName; private Pet dog; private Pet cat; public HomePets(String homeName, Pet homeDog, Pet homeCat) { this.ownerName = homeName; this.dog = homeDog; this.cat = homeCat; } public String toString() { String output = " "; output += this.ownerName; output += this.dog; output += this.cat; return output; } public totalPrice() { } public totalWeight() { }

My Pet class:

public class Pet { private String name; private double price; private int weight; //constructor public Pet(String petName, double petPrice, int petWeight) { this.name = petName; this.price = petPrice; this.weight = petWeight; } public String toString() { String output = " "; output += this.name + " \t"; output += this.price + " dollars \t"; output += this.weight + " pounds \t"; return output; } public double getPrice() { return price; } public int getWeight() { return weight; }

public void changePrice (double amount) { if (amount < 0) this.price = getPrice() + amount; else this.price = getPrice() + amount; } }

my Driver:

public class HomePetsDriver { public static void main (String [] args) { Pet myDog = new Pet("Carter", 1000 , 30); Pet myCat = new Pet("Hunter", 500 , 50); HomePets myPets = new HomePets("Long: ", myDog, myCat); //myPets object System.out.println(); //testing toString System.out.println(myDog.toString()); System.out.println(myCat.toString() +" "); System.out.println(myPets.toString()); //myPets toString System.out.println(); //using changePrice myDog.changePrice(20.00); myCat.changePrice(-10.00); System.out.println(myDog); System.out.println(myCat); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!