Question
Develop a main method, stored in a java file called Multi.java , for the provided objects that does the following: Multidimensional array of animals: Animal[][]list
Develop a main method, stored in a java file called Multi.java, for the provided objects that does the following:
- Multidimensional array of animals:
- Animal[][]list = new Animal[3][15];
- Sugg: Use the row to keep track of the type of animal, such that all elements in list[0] are Animals, list[1] is Dogs and list[2] is RescueDogs
- Randomly establish animals to fill the array
- Sort each row by either animal height or weight
- Display the array in an easy to read manner
- Sugg: Override toString in all object classes
- Calculate the total height and weight:
- For all Animals
- For all Dogs
- For all RescueDogs
- Calculate the average height and weight for each of the following (separately):
- For all Animals
- For all Dogs
- For all RescueDogs
Notes:
- You can develop additional methods in the object classes to establish any part of the above requirements.
- Sugg: create a print method or override toString in each class
- You can use instance of within an if/else statement to determine the actual type of a reference. Example:
- if( animal[i] instance of Animal){
//do something with the animal references
}
- if( animal[i] instanceof Dog){
//do something with the dog references
}
- if( animal[i] instanceof RescueDog){
//do something with the rescue dog references
}
_____________________________________________________________________________________________________________
Code for reference:
public class Animal{
double height;
double weight;
public Animal(){
this(0,0);
System.out.println("In Animal -- No Arg Constructor");
}
public Animal (double height, double weight){
this.height = height;
this.weight = weight;
System.out.println("In Animal -- 2-Arg Constructor");
}
public void eat(){
System.out.println("Nom Nom Nom");}
}
class Dog extends Animal{
String breed;
public Dog(){
breed = "";
System.out.println("In Dog -- No Arg Constructor");
}
public Dog(double height, double weight, String breed){
super(height, weight);
this.breed = breed;
System.out.println("In Dog -- 3-Arg Constructor");
}
public void bark(){
System.out.println("Woof!");
}
public void bark(int n){
for(int i=0; i this.bark();} } @Override public void eat(){ System.out.println("Who wants a treat?!");} public void play(){ System.out.println("Let's play fetch!");} } class RescueDog extends Dog{ String gotchaDate; public RescueDog(){ super(); gotchaDate = "N/A"; System.out.println("In RescueDog -- No Arg Constructor"); } public RescueDog(String gotchaDate, String breed){ super.breed = breed; this.gotchaDate=gotchaDate; System.out.println("In RescueDog -- 2-Arg Constructor"); } @Override public void eat(){ super.eat(); System.out.println("Give me a bone!"); } } public class PracticeComp{ public static void main(String[]args){ Dog lady = new Dog(); RescueDog amelia = new RescueDog("03202020","mutt"); Animal doug = new Dog(32.3, 75, "Labrador"); ... } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the Multijava file with the main method implementation java import javautilArrays import javautilRandom public class Multi public static void ma...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started