Question
Java Code! Do not use instanceof in the code. Assume of code that Color enum or other code is created. Toy : Is the abstract
Java Code! Do not use instanceof in the code. Assume of code that Color enum or other code is created.
Toy: Is the abstract superclass of toy inheritance Hierachy.
Contains: Constructors that takes the product Code and Name.
int getProductCode(), String getString(), int HappinessLVL(), boolean isRetired, double getWear(), void increaseWear(double amount), void play(int time);(Assume that Toy abstract class is Finished.)
Bear is a concrete Class that Inherits from Toy:
-It has Constructor that takes the spoken common phrase, fur color, age and name. (Special Product Code begins at 100 and increases by 1 each time a new one is constructed.)
-Age: returns the age
-Phrase: returns the phrase
-Fur: return Fur color
-UPlay: Following Order
1) A tab indented, "\t", message is displayed to standard output in the format:
{name} brushes their {fur color} fur and says, "{phrase}"
For example:
Teddy brushes his BLUE fur and says, "Can_you_sing_the_ABC?"
2) The wear increases by age.
-toString(): Returns a string in the format:
Toy{PC:?, N:?, H:?, R:?, W:?}, Bear{FC:?, A:?, P:?}
The Toy part of the string comes from Toy's toString()
FC for the fur color
A for the age
P for the phrase
For example:
Toy{PC:100, N:Ted, H:101, R:true, W:18.0}, Bear{FC:BLUE, A:8, S:Can_you_sing_the_ABC?}
AnimatedBear is a concrete Class that inherits from Bear. what it has:
-A Constructor that takes the age, name and spoken phrase. All animated bears have FUR_COLOR (purple) fur. The unique product code starts at 300 and increases by 1 each time a new one is constructed.
- PowerLVL(): Returns Power level (Begins at START_PWR_LVL and increases when played with).
-UPlay(): Following Order:
1)A tab indented, "\t", message is displayed to standard output in the format (where the energy formula is computed as: energy * time):
{name} karate chops with {Power-formula} energy!
For example:
MegaMan karate chops with 39 power energy!
2) The power is increased by 1.
3) The unique play (UPlay) of Bear is called.
- toString(): Returns a string in following format:
Toy{PC:?, N:?, H:?, R:?, W:?}, Bear{FC:?, A:?, P:?}, AnimatedBear{PL:?}
The Bear part of the string comes from Bear's toString()
PL for the power level.
Toy{PC:100, N:MegaMa, H:77, R:fslse, W:67.0}, Bear{FC:RED, A:12, S:Get_Blasted_with_my_lasers!}, AnimatedBear{PL:7}
ChargedLVL is abstract subclass of Toy.
-Constructor that contains: Product Code, Name and number of batteries
-CurrentChargedLvl(): return current charged lvl (starts at FULLY_CHARGED = 100)
-NumBattery(): returns the number of batteries
- usedCharged(): When played with batteries are used and this happens:
1) The charged lvl is reduced by: time + num-of-batteries
2)If battery level is out:
1) Battery LVL capped at DEPLETED
2) A tab "\t", depletion message is displayed in the format:
DEPLETED:toy-toString
3) Battery Lvl is back to FULLY_CHARGED.
4) A tab indented, "\t", recharge message is displayed in the format:
RECHARGED:toy-toString
-toString(): Returns String format:
Toy{PC:?, N:?, H:?, R:?, W:?}, BatteryPowered{CL:?, NB:?}
Toy part of string comes from Toy's toString()
CL = Charged Level
NB = Num of batteries
Toy{PC:200, N:Jess, H:101, R:true, W:50.0}, ChargedLVL{CL:78, NB:3}
ToyCar is a concrete class that inherits from ChargedLVL.
-Constructor with name and number of batteries. Special Product Code Starts at 500 and increases by 1 each time a new one is constructed.
-Speed(): Return the current speed (Starts at BEGIN_SPEED and increases when played with)
-UPlay(): Following happens:
1)A tab indented, "\t", message is displayed to standard output in the format:
{name} races around at {speed}knots!
For example:
LightningMcQueen races around at 13knots!
2) The batteries are used for the amount of time.
3) The wear increases by the current speed.
4) The speed increases by SPEED_INCREASE.
Airplane is a concrete class that inherits from ChargedLVL.
-Constructor takes the # of batteries, name and if it flies or not. Special Code Starts at 300 and increases by 1 each time a new one is created.
-Flying(): returns whether it flies or not.
-Miles(): Returns the total miles traveled when played with (starts at START_SPEED).
-UPlay(): 1) If flying: miles is increased by time * FLY_SPEED
2) A tab indented, "\t", message is displayed to standard output in the format:
{name} is flying around with total distance: {miles}
For example:
Bumble is flying around with total distance: 1783
3)The wear increases by FLY_SPEED
2) If not flying:
1) The distance is increased by time * RUN_SPEED
2)A tab indented, "\t", message is displayed to standard output in the format:
{name} is running around with total distance: {miles}
For example:
Sven is running around with total distance: 238
3) The wear increases by RUN_SPEED
3) The batteries are used for the amount of time.
toString(): Returns a string format:
Toy{PC:?, N:?, H:?, R:?, W:?}, ChargedLVL{CL:?, NB:?}, Airplane{F:?, M:?}
The Toy part of the string comes from Toy's toString()
The ChargedLVL part of the string comes from ChargedLVL's toString()
F for flying or not (true or false)
M for Miles
For example:
Toy{PC:403, N:CopperSteve, H:73, R:false, W:50.0}, ChargedLVL{CL:3, NB:3}, Airplane{F:true, M:1293}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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