Note: Starting in this homework, we deduct points:
3A
Complete the GroceryBill class which models the checkout process at a grocery store. You are given starter code and a GroceryBillTester class which creates a GroceryBill and calls its methods. Copy both into Bluej.
In this class, we want to be able to add the cost of an item to the bill and remove a specific amount from the bill. We also want to able able to get the subtotal.
What does the class need to remember? That is the instance variable. What data type should it be (int, double, String)?
GroceryBill has a no-argument constructor which initializes the instance variable (subtotal) to 0. Remember that a constructor has the same name as the class.
It has the following methods:
public void add(double amount) adds this cost to the subtotal for this GroceryBillpublic void remove(double amount) subtracts this cost from the subtotal for this GroceryBillpublic double getSubtotal() gets the subtotal for this GroceryBillProvide Javadoc for the class, the constructor, methods, parameters and return values. Codecheck will run StyleCheck to tell you if your Javadoc is correctly formatted.
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
3B
HAL 9000 is a fictional character in Arthur C. Clarke's 2001: A Space Odyssey. HAL (Heuristically programmed ALgorithmic computer) is a AI (artificial intelligence) computer that controls the systems of the spacecraft and interacts with the ship's crew.
In this assignment you will finish the Hal9000 class. You are also provided with a tester that uses the class and calls its methods. Copy both the starter code and the tester.
The Hal9000 needs to remember the name of the crew member it is interacting with. This is the instance variable. The constructor takes a String parameter of the crew member's name and assigns it to the instance variable.
It has methods:
public String getName() which gets the name of the crew memberpublic void setName(String newName) which sets a new name for the crew memberpublic String greetCrewMember() which returns a string consisting of "Welcome, name" where name is the name supplied in the constructor.public String doCommand(String whatToDo) which returns a string consisting of "I am sorry, name. I can't " + whatToDo where name is the name supplied in the constructor and whatToDo is the parameter for this method.Supply Javadoc for the class, 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. You will learn about that in lesson 4, but I can tell you now. 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.
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 doCommand()
{
return null;
}
In the Javadoc, describe what the final version of the method will do, not what the stub does now.
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.
What does the class need to remember? Its starting coordinates. So those are the instance variables
Snowman has a constructor that takes the x and y coordinates of the upper left hand corner of the rectangular part of the hat as parameters and stores them in the instance variables. 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 use 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