I am a beginner and I would appreceiate if anyone help me.
My task is:
Create an Animal class with member-type data (dog, cat, fish), age and weight.
• Designers
• get & set
• toString ()
B. Create a Speakable interface with the void method
C. Create Cat and Dog classes, descendants of Animal with an additional fur color field and implementing the Speakable interface - the speak () method to display a message with the sounds made by the animal
For the Cat and Dog classes, write constructors (constructors should have 3 parameters, because the value of one of the inherited fields - the animal type is given as a constant), get & set for the additional field and redefine the toString () method
D. Create an ArrayList of type Animal, fill it with objects from the three classes and for each object call the toString () method (use loop)
E. Change the values of some of the fields of the first animal with the appropriate set () method and display the contents of the list again.
F. Determine the index of the first animal-dog, delete it and display the list again
G. Create an ArrayList of type Speakable, fill it with objects of type Cat and Dog, for each of them call the method get () for the type field and the interface method speak () - to get a message about the type of animal and the sounds that issues
My task is:
Create an Animal class with member-type data (dog, cat, fish), age and weight.
• Designers
• get & set
• toString ()
B. Create a Speakable interface with the void method
C. Create Cat and Dog classes, descendants of Animal with an additional fur color field and implementing the Speakable interface - the speak () method to display a message with the sounds made by the animal
For the Cat and Dog classes, write constructors (constructors should have 3 parameters, because the value of one of the inherited fields - the animal type is given as a constant), get & set for the additional field and redefine the toString () method
D. Create an ArrayList of type Animal, fill it with objects from the three classes and for each object call the toString () method (use loop)
E. Change the values of some of the fields of the first animal with the appropriate set () method and display the contents of the list again.
F. Determine the index of the first animal-dog, delete it and display the list again
G. Create an ArrayList of type Speakable, fill it with objects of type Cat and Dog, for each of them call the method get () for the type field and the interface method speak () - to get a message about the type of animal and the sounds that issues
Updates
+1 y
I dont understand anything in that subject, please dont judge me
Thanks in advance
Thanks in advance
Updates
+1 y
for now I have written this:
public class HelloWorld{
public static void main (String []args){
System. out. println ("Hello World");
}
}
enum Type
{
DOG,
CAT,
FISH
}
class Animal
{
private Type type;
private int age;
private double weight;
public String toString ()
{
String s = "";
switch (type) {
case DOG:
s = "dog";
break;
case CAT:
s = "cat";
break;
case FISH:
s = "fish";
break;
default:
s = "Unknown";
break;
}
return s;
}
}
Aa
public class HelloWorld{
public static void main (String []args){
System. out. println ("Hello World");
}
}
enum Type
{
DOG,
CAT,
FISH
}
class Animal
{
private Type type;
private int age;
private double weight;
public String toString ()
{
String s = "";
switch (type) {
case DOG:
s = "dog";
break;
case CAT:
s = "cat";
break;
case FISH:
s = "fish";
break;
default:
s = "Unknown";
break;
}
return s;
}
}
Aa
What Girls & Guys Said
Opinion
2Opinion
Sounds pretty simple.
There are tons of basic Java tutorials online.
Yeah, I know, I dont have time and I dont know why I have to study this.
What class is it for? Why are you taking that class?
It is compulsary, I study General Pharmacy
Shouldn't take more than an hour or two with a basic tutorial.
Now you need
interface Speakable {
public String Speak () {}
}
class Dog extends Animal{ ... }
etc
and add "implements Speakable" to Animal definition
The toString for each type of Animal should be defined in the subclasses (Dog, Cat, etc)
Okay, thank you, I will try that.
I’m learning Python instead