CS46A Spring 19

3A

Complete the class Climber which represents a child's position on a climbing pole. The position can be anywhere from the bottom to the top of the pole. The pole is 10 unit high. At any point, the child can slide back to the bottom of the pole. We want to be able to have the child climb and slide. We want to be able to get his current position and his name.

What will the object need to remember? name and position on the pole - those are the instance variables.

Climber class has this constructor :

It has these methods.

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 stub for a mutator method has no body at all. A class with stubs for methods will compile, but it does not yet behave correctly. You still need to supply implementation and the correct return values. The idea is that you can implement one method at a time and test it with a tester since the class will compile and run. 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. Notice that the Javadoc says what the method will do when complete - not what the stub does.

You are given a ClimberTester class in Codecheck along with the starter for the Climber class. Copy both into your project. ClimberTester is an application with a main method. To run your application, right click on it and execute its main method.

For the draft, declare the instance variables. Then complete the constructor and the getName method

3A draft:
3A final:

3B

Write the class WaterFlask to model a a flask for carrying water - perhaps on a hike. A WaterFlask has a capacity (the largest amount the flask can hold) measured in milliliters (mL) as a int. It also has a current amount (a int).

What does the WaterFlask object need to remember? Those are the instance variables.

Provide a constructor that takes the maximum capacity as a parameter. When the WaterFlask is constructed it is filled to maximum capacity. The constructor initializes the instance variables (two of them).

Provide methods

Provide Javadoc for all methods and for the class itself. Codecheck will run CheckStyle to check that you have the correct Javadoc. You can look at this URL for some help interpreting the error messages

For the draft, provide the constructor to initialize (to a assign the value to) the instance variables. Write the getMaxCapacity method. Provide stubs for all other methods and supply the Javadoc for the constructor and all the methods. The Javadoc for the class itself is provided

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 getAmount()

public int getAmount()    
{        
    return 0;    
}

In the Javadoc, describe what the final version of the method will do, not what the stub does now.

3B draft:
3B final:

3C

In this problem, you will revisit hw2c. In that homework, you drew a circles on a graphical canvas. Our client wants to use the circles as his logo and to have several circles in different places on the Canvas. You could recalculate all the coordinates needed to draw each one, but then what if the client wants to add another or to change the locations? That's a lot of work. Fortunately object-oriented programming provides a solution - Create one class from which you can make multiple objects in different locations.

Make a Bluej project and select Project->Import ... to add the graphics files to your project. Be sure the folder you import contains the files directly and does not contain a second folder that contains the files. (See the screenshot from hw2C) Create two classes: Circles and new CirclesViewer. Copy the code in CirclesViewer from Codecheck. You should not modify CirclesViewer at all. You will write the Circles class yourself.

CirclesViewer is an application with a main method. Right click and execute its main method to see your drawing when your code is finished.

In hw2c, you hard-coded the coordinates of the upper left-hand corner of drawing as (50, 10) and calculated all the other values from those. That means the drawing is always at the same location. We want to be able to start the drawing at different locations. To do that, we will write a constructor for the class. The constructor will take the x and y coordinates of the upper, left-hand point of the first circle as parameters.

You will calculate all the other coordinates relative to that x, y. For example, the coordinates of the upper left-hand coordinate of the second circle is (x + 40, y). . You create the ellipse representing the first circle like this: Ellipse circle1 = new Ellipse (x, y, 40, 40). Now you can put the circle at any location on the Canvas.

Constructor

Method

Include Javadoc for constructor and draw method

Your drawing should follow these specifications.

It is a good idea to figure out the coordinates of each point on a piece of paper before trying to code. I did not follow my own advice. I thought this was simple enough and I was clever enough to figure out the coordinates as I coded. I was so wrong, and it cost me a lot of time.

For the draft, provide instance variables, for x and y. Write the constructor to initialize the instance variables. Add a draw method which will just draw the first circle. Write the Javadoc for the class, the constructor, and the method.


3C draft:
3C final: