12A
Many people want to follow a low carbohydrate diet. In order to do that, they need to know how many carbohydrates are in the foods they choose.
Make a subclass Food of the Product class we created in class. Besides the description and price inherited from Product, Food also has an instance variable carbs (an int). Do not redefine price and description variables. Call the super class to initialize them
Food has a methods:
public void setCarbs(int grams)public double getCarbs()public boolean isLowCarb() which tells if this Food is considered low carb. A Food is considered low carb if it has 10 or fewer grams of carbohydrates. Return true if the Food has 10 or fewer carbs. Otherwise, return false.public String getDescription() overrides the getDescription method in Product to also include the number of carbs. Call the getDescription method in the super class and add the new information on the end. The return string will look like this: oatmeal carbs=8.3Provide Javadoc.
For the draft, make Food a subclass of Product. Provide the new instance variable, carbs. Write the constructor that takes description, price, and carbs (updated 11/28/2017), in that order. Be sure to initialize all the instance variables. Provide getCarbs. Implement the the setCarbs and isLowCarb methods as stubs. Remember that if a stub's return type is boolean, it should return false. Do not include getDescription in the draft.
12B
Write a subclass SpecialRectangle of the Rectangle class A SpecialRectangle has a special set of colors. It has a String instance variable called paintColor. Do not add any instance variables except the paintColor. You will get lose credit if you do.
Valid paintColors and their red, green, blue values are:
vanilla (255, 255, 248)
blue_green (204, 255, 255)
purple (159, 0, 197)
burnt_orange (227, 117, 00)
Provide two constructors:
Each constructor will need to set the paintColor instance variable and call the super class setColor() method so the SpecialRectangle will be drawn in the correct color.
Provide methods to set and get the paintColor.
For the draft, provide the instance variables and implement the constructor with 4 parameters. . Implement the getPaintColor() method. Code setPaintColor as a stub.
12C
Animals need energy to move, which they get from eating food.
Create a class Animal with a constructor that takes no parameters and has an instance variable
private int energy;
When an animal is "born" it has no energy.
It has the methods
public void eat(int amount) - which increases the amount of energy the animal has by amount, but only if amount > 0public void move(int amount) - which decreases the amount of energy the animal has by amount. Energy changes only if amount > 0. The energy can never be less than 0. If an Animal has an energy of 2 and tries to move 5, its energy will be 0.public int getEnergy() - which returns the amount of energy the animal has leftNotice there is no setEnergy method. Energy is only changed by eating or moving.
When an animal is "born" it has no energy.
It isn't realistic for animals to be able to gather infinite amounts of energy. Create a subclass ImprovedAnimal which has a cap on the amount of energy an animal can have. The constructor takes a parameter that sets a maximum for energy. If the amount the ImprovedAnimal eats would set its energy above the max, the energy level is only increased to the max.
For the final, Animal will not change, but you need to submit it.
Provide Javadoc for both classes.
For the draft, write the Animal class. Include Javadoc