Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is another class that extends from the Animal class and it asking for this requirements, but i do not think they are any how

This is another class that extends from the Animal class and it asking for this requirements, but i do not think they are any how met, can you please review it and help me accordingly:
Follow these steps:
Modify the existing Animal.java file for this task.
Create a class called Cheetah that:
Inherits from the Animal class.
Makes use of at least one static field which needs to have a static
setter and getter.
Contains a constructor.
Contains a toString() method.
Has an array as one of its fields.
Create an application class. Within the main method, create a Cheetah
object and print out (to the screen) the details that describe this object.
Compile, save and run your file.
class Cheetah extends Animal {
public Cheetah(int numTeeth, boolean spots, int weight){
super(numTeeth, spots, weight);
}
public String toString(String cheetah){
String output = "Number of Teeth: "+ getNumTeeth();
output +="
Does it have spots?: "+ getSpots();
output +="
How much does it weigh: "+ getWeight();
output +="
Cheetah";
return output;
}
}
import java.util.Scanner;
public class Animal {
private int numTeeth =0;
private boolean spots = false;
private int weight =0;
public Animal(int numTeeth, boolean spots, int weight){
this.setNumTeeth(numTeeth);
this.setSpots(spots);
this.setWeight(weight);
}
public int getNumTeeth(){
return numTeeth;
}
public void setNumTeeth(int numTeeth){
this.numTeeth = numTeeth;
}
public boolean getSpots(){
return spots;
}
public void setSpots(boolean spots){
this.spots = spots;
}
public int getWeight(){
return weight;
}
public void setWeight(int weight){
this.weight = weight;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
// Get user informations
System.out.println("Enter the number of teeth: ");
int numTeeth = input.nextInt();
System.out.println("Does it have spots? (true/false)");
boolean spots = input.nextBoolean();
System.out.println("Enter the weight: ");
int weight = input.nextInt();
; // Create an instance of the Lion class
Lion lion = new Lion(numTeeth, spots, weight);
// Display information about the lion
System.out.println(lion.toString());
input.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions