I need help creating a setter method for my code. I have created two setter methods for both of my string values, but I am A) not sure if they are implemented correct, and B) not sure how to call them so that they appear on the screen. Essentially I would like to be able to just call my lion and hippo classes and have them already have a name and a size, and not have to implement them inside my main function directly by inserting something like Hippo h = new Hippo("Tom", "42")
package game2;
public class Game2 {
public static void main(String[] args) {
//I am getting the error here, what I want to do is figure out how to
//get this to work and then declare a name and size for the animal
Hippo h = new Hippo();
Lion l = new Lion();
}
}
package game2;
public abstract class Animal {
private String name;
private String Size;
public String getName() {
return name;
}
public String getSize() {
return Size;
}
public void setName(String name) {
name = "Tom";
}
public void setSize(String name) {
name = "42";
}
public Animal(String theName, String theSize) {
name = theName;
Size = theSize;
}
}
package game2;
public class Hippo extends Animal {
public Hippo(String name, String Size) {
super(name, Size);
}
}
package game2;
public class Lion extends Animal{
public Lion(String name, String Size) {
super(name, Size);
}
}