Problem

Consider the following classes. class Cat { private String name; private...

Consider the following classes.

class Cat {

private String name;

private Breed breed;

private double weight;

public Cat(String name, Breed breed, double weight){

this.name = name;

this.breed = breed;

this.weight = weight;

}

public Breed getBreed() {

return breed;

}

public double getWeight() {

return weight;

}

//other accessors and mutators

. . .

}

class Breed {

private String name;

private double averageWgt; //in lbs.

public Breed(String name, double averageWgt){

this.name = name;

this.averageWgt = averageWgt;

}

public double getWeight( ) {

return averageWgt;

}

//other accessors and mutators

. . .

}

Identify the invalid statements in the following main class. For each invalid statement, state why it is invalid.

class Q1Main {

public static void main(String[] args ) {

Breed persian = new Breed("Persian", 10.0);

Cat chacha = new Cat("Cha Cha", persian, 12.0);

Cat bombom = new Cat("Bom Bom", "mix", 10.0);

Cat puffpuff = new Cat("Puff Puff", chacha, 9.0);

double diff = chacha.getWeight()

- persian.getWeight();

System.out.println(

puffpuff.getBreed().getWeight());

}

}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7