Note: in this homework, we will start deducting points

3A

Complete the ShoppingCart class which models an online shopping cart. We want to be able to add an item of a specific cost and remove an item of a specific cost. We also want to able able to get the subtotal.

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

ShoppingCart 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:

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

Complete the Parrot class. A Parrot has a name and can say various things when asked.

Provide a constructor that takes the name of the parrot 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 whatDoYouWant()

  public String whatDoYouWant()
  {
     return null;
  }

3B draft:
3B final:

3C

In this exercise, we are going to revisit the traffic light from homework2c. In that assignment you wrote a TrafficLightViewer 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 traffic light (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 TrafficLight class that models a traffic light at a given (x,y) coordinate. Then that class can be used in an application to draw TrafficLight objects. In this case, I provide you with a new TrafficLightViewer which is an application that uses the TrafficLight class. There is not starter class for TrafficLight. You will write all the code.

TrafficLight will have a constructor that takes the x and y coordinates of the upper left hand corner of the rectangular part of the traffic light as parameters. No starter this time. You provide all the code. Do not draw in the constructor

It has a draw method that can draw the TrafficLight at its x,y coordinates. In the draw method, draw a black rectangle at the x,y coordinates with a width of 20 and a height of 60. Then fill red, yellow, and green circles inside the rectangle to look like a traffic light. The upper left hand corner of the red circle will be at same x,y coordinates as the box. The circles will touch the sides of the box and each other.

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

Use the predefined colors Color.RED, Color.YELLOW, and Color.GREEN.

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

The only numbers in your code should be the 20 and the 60 for width and height.

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

TrafficLight'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.

I will provide a TrafficLightViewer to draw several TrafficLights at different locations.

For the draft, provide the constructor, instance variables and a draw method that draws the box at the specified x,y location.. Provide the javadoc

3C draft:
3C final: