12A

Write a subclass of Product called Food. In addition to description and price, the constructor takes a third parameter, carbs which is the grams of carbohydrates in a standard serving. Use a double.

Add a method to getCarbs. Override the getDescription method to include the new instance variable and its value.

Add a new method isLowCarb()which determines if the Food has few enough carbs to be included in a low carbohydrate diet. If so it returns true. Otherwise, false. To be considered in a low carbohydrate diet, the food should have fewer than 20 grams of carbohydrates. Define and use a public constant called CARB_LIMIT

Provide Javadoc

For the draft, start the Food class as a subclass of Product. Provide the new instance variable, carbs, as a double. Write the constructor that takes description, price, and carbs, in that order. Be sure to initialize all the instance variables in the constructor. Write the getCarbs method. Implement isLowCarb as a stub. Remember that if a stub's return type is boolean, return false. Do not override the getDescription method until the final. Provide Javadoc

12A draft:
12A final:

12B

You are given the Critter class for the interactivities in your e-book. You can look at its documentation by opening it in Bluej.

Write a subclass, Slug. A Slug does one of three things when the move method is called. It eats, it sleeps or it moves. If it moves, it only moves 1 space no matter what the parameter is.

The Slug is sleepy when it is created. So the first time the move method is called, the slug sleeps and the word "sleep" is added to the history. The next time, it eats and the word "eat" is added to the history, The next time, it moves 1 space. (You will need to call super.move()) The next time move method is called, it sleeps again.

You will need to use AddHistory, bo not override the AddHistory method. Do not redefine position or weight. Override the move method to behave in this manner.

Define and use public constants for the states of the slug: ready to sleep, ready to eat, ready to move. These indicate the action the slug will take the next time the move method is called.

For the draft, define the new instance variable, define the constants, write the constructor. Be sure to initialize the state with your "ready to sleep" constant.

In the final you will override the move method.

12B draft:
12B final:

12C

You are given a Book class. It has a name and author in that order. You can open it in Bluej and look at the documentation

You are to write two subclasses (Fiction and NonFiction) and finish the BookRunner class.

Write a subclass Fiction.

It has genre as the third parameter (Genre is the type of fiction: science fiction, mystery, romance, etc). It has a method getGenre()to get the genre. It overrides the getInfo method of the super class to include genre like this:

Hamlet by William Shakespeare Genre: play

Call super.getInfo. Provide Javadoc

Write a subclass NonFiction.

It has the Dewey decimal number as the third parameter. This will need to be a string because leading zeros are significant. The class has a method getDeweyDecimal() to get the Dewey decimal number. It overrides the getInfo method of the super class to include the Dewey decimal number. like this:

Big Java by Cay Horstmann Dewey Decimal: 005.133

Call super.getInfo. Provide Javadoc.

Here is an explanation of Dewey Decimal System from Wikipedia

A library assigns a classification number (the Dewey decimal number) that unambiguously locates a particular volume in a position relative to other books in the library, on the basis of its subject. The number makes it possible to find any book and to return it to its proper place on the library shelves.

Here is a link if you would like a little more information

Complete the application BookRunner.

This BookRunner shows an example of polymorphism and dynamic binding. Each time through the loop, you have a Book reference. The first time through the loop the object that is referenced is a Fiction, but the second time the object is a NonFiction and the third time, it is a NonFiction. and the fourth time, it is a Fiction. The getInfo method of the underlying object is called not the method of the object reference (a Book reference)

For the draft, implement the Fiction class.

For the final, you will implement the NonFiction class and complete the BookRunner class.

12C draft:
12C final: