Hello, this is my first time in participating in this forum and also this is the first time that I've used Java for my entire life.
The objective behind my problem was:
"Create an Animal Interface that has two methods: eat and move. All these methods do not have any arguments, nor any return tree. These methods simply print out how the Animal object eats and moves"
However, I applied the abstract class for an attempt.
import javax.swing.JOptionPane;
abstract class Animals{
String inputAnimals[];
void setAnimals(String inputAnimals[]){
this.inputAnimals = inputAnimals;
}
void printAnimals(){
for (int i=0; i<inputAnimals.length; i++){
JOptionPane.showMessageDialog(null,inputAnimals[i]);
}
}
abstract void displayAnimal();
}
class Rabbit extends Animals{
void displayAnimal(){
JOptionPane.showMessageDialog(null,"He eats carrots!");
JOptionPane.showMessageDialog(null,"He leaps in 2 legs");
}
}
class Fish extends Animals{
void displayAnimal(){
JOptionPane.showMessageDialog(null,"It eats algae, plankton and other aquatic creatures");
JOptionPane.showMessageDialog(null,"It swims");
}
}
class Bear extends Animals{
void displayAnimal(){
JOptionPane.showMessageDialog(null,"It eats live fishes");
JOptionPane.showMessageDialog(null,"It can walk in 4 legs");
}
}
However, I based these codings in our teacher's photocopied J.E.D.I modules