Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java class Frog. The weight of a frog is at least 1; it has no legs if its weight is no more than 5, 4

Java class Frog. The weight of a frog is at least 1; it has no legs if its weight is no more than 5, 4 legs if its weight is more than 20, and 2 legs otherwise.

The following constants are provided, and program cannot have any magic number, even 1 or 0.

public static final int MIN_WEIGHT_FOR_FROG = 1; public static final int MAX_WEIGHT_FOR_LIGHT_WEIGHT_FROG = 5; public static final int MAX_WEIGHT_FOR_MED_HEIGHT_FROG = 20; public static final int LEGS_FOR_LIGHT_WIGHT_FROG = 0; public static final int LEGS_FOR_MED_WIGHT_FROG = 2; public static final int LEGS_FOR_HEAVY_WIGHT_FROG = 4;

The class has one instance variable for the weight, and you will provide the following constructor.

public Frog(int theWeight)Creates a frog object with the given weight but sets the weight to 1 if the parameter is not positive. You will provide the following methods for the class, including the Javadoc.

public int getWeight()Gets the weight of this frog object.

public int getLegs()Calculates and returns the number of legs of this frog object.

public void grow(int amount)Increases the weight of this frog by amount if amount is positive; otherwise, do nothing.

public String toString()Gets a string for this Frog object in the format Frog[Weight:5,Legs:0].

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago