Note: in this homework, we will start deducting points if your code is not formatted properly. In Bluej when the workbench has the focus, click Edit / Auto Layout to format your code

3A

In this problem you will write a class ElectricCar to model an electric car with a specified driving range. The class will need to remember three things:

  1. the maximum number of miles the electric car can go when fully charged
  2. the number of miles the electric car can go at the curent charge level
  3. the make of the car (Leaf, Fit, Tessla, etc)

The way a class remembers data is by declaring and using instance variables. Call the instance variables maxRange, currentRange, and make. Those should be the only three instance variables

The ElectricCar constructor takes the make and the number of miles this car can go when fully charged (maxRange) as a parameter. It sets an instance variables equal to these arguments. It also initializes current range to 0. That is, the car is uncharged when created.

An ElectricCar has one constructor and these methods.

At this point in your programming career, assume the car never tries to drive when there is not enouch charge. We will have to cover if statements to be able to handle this properly.

The methods and constructor are provided as stubs in the starter file. A stub has a method header and a body with no implementation. The stub for an accessor method returns 0 for numbers or null for objects like strings. A class with stubs for methods will compile, but you will need to supply implementation and the correct return values. The idea is that you can implement one method at a time and test it since the class will compile. This technique is frequently used in development of applications.

Javadoc is also provided for this class. Study how it is done so you can write the required javadoc in the next problem

For the draft, declare the three instance variables. Then complete the constructor and getMaxRange methods.

3A draft:
3A final:

3B

In this problem you will write a class CreditCard that models a credit card. The CreditCard starts with a balance of 0

CreditCard has a constructor and these methods:

Think about what information needs to be remembered and define instance variables to remember that information. Do not use any unnecessary instance variables. For instance, do not have instance variables for payment and charge amounts. Those will be local variables.

For the draft, implement the constructor and all the methods as stubs. Include javadoc for the class, constructor, and each method. Your class should compile and run with the tester even though the return values will not be accurate. You will lose points if you do not include javadoc. You will declare the instance variables in the final version.

Javadoc for the class might look like this:

/**  
*   Models a credit card that can make charges and payments  
*/

3B draft:
3B final:

3C

In this exercise, we are going to revisit the stairs from homework2c. In that assignment you wrote a StairsViewer 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 stairs at a different location, 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 Stairs class that models a stairs at a given (x,y) coordinate and that knows how to draw itself on the canvas (It has a draw method)

Stairs will have a constructor that takes the x and y coordinates of the upper left hand corner of the top step as parameters. Think about what the object needs to remember. That will be the instance variables.

No starter this time. You provide all the code. You will need to import the graphics package.

Your drawing should follow these specifications.

Stairs has a draw method that can draw the Stairs at its x, y coordinates. The code in Stairs' draw method will be similar to the code in the main method of StairsViewer except you will use variables x and y rather than hard coding the coordinates as numbers. (NOTE: the draw method should only draw one flight of stairs). It should work if I change the tester to draw the Stairs at a different location.

For the draft, provide the instance variables and write the constructor. In the draw() method, draw the top step.

Fill the rectangles. Do not use the Rectangle's draw() method. This will guarantee that Codecheck will correctly evaluate your code.

3C draft:
3C final: