setter and getter methods and parameters help!

I'm frustrated! How can I get this code to work?

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: [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;
}


} [/code]


And here is my attempt:
[code]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;
}

}[/code]

[b]WHAT AM I DOING WRONG! Am I close?
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.[/b]

Thanks in advance!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories