Note: in this homework, we deduct points

3A

Complete the PiggyBank class which models a child's piggy bank. Copy it and the tester from Codecheck. We need to be able to add and remove a specified amount from the PiggyBank. We also need to be able to get the total in the piggy bank.

What does the class need to remember? That is the instance variable.

PiggyBank has a no-argument constructor which initializes the instance variable (total) to 0. Remember that a constructor has the same name as the class.

It has the following methods:

Provide Javadoc for the class, the constructor, methods, parameters and return values.

For the draft, provide the instance variable and implement the constructor to initialize the instance variable. Provide Javadoc at the top of the class and for the constructor

3A draft:
3A final:

3B

Create a RobotFriend class. RobotFriend is a new toy just on the market. Copy the starter class and the tester form Codecheck. A RobotFriend has a name and replies to various commands

Provide a constructor that takes the name of the RobotFriend as a parameter. Remember that a constructor has the same name as the class.

What does the class need to remember? That is the instance variable.

Provide the following methods:

Supply Javadoc for the class itself (at the top), for the constructor and all the methods

You can use the String concat method to join strings together, but I find the easiest thing to do is use the + operator. Look at this example of combining two Strings to make a third. I want to combine the phrase "My cat is " with the variable containing my cat's name and then a period.

String cat = "Corky"  
String message = "My cat is " + cat +".";

This is called concatenation.

For the draft, provide the instance variable and write the constructor to initialize (to a assign the value to) the instance variable. Provide getName() method. Provide stubs for all the other methods and supply all the Javadoc for the class (at the top), the constructor and all four methods.

What is a stub? A stub has a method header complete with braces. If the method is void, that is all you need. If not, then you need to return a temporary dummy value: null for Strings and other objects, 0 for doubles and integers.

Here is the stub for whatDoYouNeed()

public String whatDoYouNeed()   
{      
   return null;   
}

Provide Javadoc for the class, the constructor, methods, parameters and return values.

3B draft:
3B final:

3C

In this exercise, we are going to revisit the snowman from homework2c. In that assignment you wrote a class SnowmanDrawing with a main method and did all the drawing in it. But there is a problem with that design: If you wanted to draw a second snowman (or a third or a fourth), you would have to recalculate all the coordinates and repeat all the lines of code. Not good. The solution to this problem is to create a Snowman class that models a snowman at a given (x,y) coordinate and can draw itself. Then that class can be used in an application to draw an many Snowman objects as you want. I provide you with a class SnowmanViewer which is an application that uses the Snowman class. There is not starter class for Snowman. You will write all the code. But be sure to copy SnowmanViewer from Codecheck.

Snowman has have a constructor that takes the x and y coordinates of the upper left hand corner of the rectangular part of the hat as parameters. Do not draw in the constructor.

Snowman has a draw method that can draw the Snowman at its x,y coordinates. It takes no parameters

draw method specifications:

Provide Javadoc for the class itself, the constructor and the draw method.

Remember you need to import the graphics classes into the Bluej project.

If you had trouble with hw2c, then you can look at the solution in the Modules on Canvas.

Snowman's draw method will have less that 20 lines of code. If you have a lot more than that. You are doing something wrong - even if it passes Codecheck.

SnowmanViewer  draws several Snowmans at different locations.

For the draft, provide the constructor, instance variables and a draw method that draws the hat (hatbox and brim). Provide the Javadoc

 

3C draft:
3C final: