The task is to: 1. Add an attribute to the "Mammal" class called "Weight" and also add methods that set and get that weight value.
2. Also, in the "MainApplication" class, invoke the 'set' and 'get' methods.
3. Make sure that the weight I set the attribute to prints out.
Here is the original code:
class MainApplication {
public static void main(String args[]) {
Mammal dog = new Mammal();
dog.setHairColor("Blue");
}
}
// Class Mammal
public class Mammal {
private String hairColor;
public void growHair(){
System.out.println("Hair Growing");
}
public void setHairColor(String color){
hairColor = color;
}
}
And here is my attempt:
class MainApplication {
public static void main(String args[]) {
Mammal dog = new Mammal();
dog.setHairColor("Blue");
dog.setWeight(50);
}
}
// Class Mammal
public class Mammal {
private String hairColor;
public void growHair(){
System.out.println("Hair Growing");
}
public void setHairColor(int color){
hairColor = color;
}
private String Weight;
public void dog.setWeight(int weight){
dog.getWeight = weight;
}
}
Please explain to me what I need to fix/add. When I compile it (in JCreator LE) , the errors messages I am receiving are:
line 28 : "(" expected
line 28 : invalid method declaration; return type required.
Thanks in advance!

New Topic/Question
Reply




MultiQuote





|