CS46A Fall 19

3A

Complete the class AustrailianBeardedDragon which represents an Australian bearded dragon. The Australian bearded dragon can climb a tree. In our case the tree is 10 feet tall. The dragon's position can be anywhere from the bottom (0) to the top of the tree (10). At any point, the dragon can slide back to the bottom of the tree. The dragoon takes steps of 1 foot each. Also the dragon has a gender, either male or female. In a quirk of nature this reptile sometimes changes gender!

Note that Austrailian is missplelled. You will need to use this spelling for Codecheck to work.

We want to be able to have the dragon climb and slide. We want to be able to get and set its gender as well as get its current position

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

AustrailianBeardedDragon 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 AustrailianBeardedDragonTester class in Codecheck along with the starter for the AustrailianBeardedDragon class. Copy both into your project. AustrailianBeardedDragonTester 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 getGender method. Implement the getPosition method to return 0.

3A draft:
3A final:

3B

A Powerwall is an electricity storage unit for home use. Solar panels charge the Powerwall (add electricity to it) during the day in sunny weather. At night or in cloudy weather, the Powerwall releases electric back to the house to be used. This is an oversimplification of the process, but it that is the basic idea used in this problem.

Write a class Powerwall to model one of these electricity storage units. A Powerwall has a capacity (the largest amount of electricity that the unit can hold) measured in kilowatt hours (kwh) as a int. It has the current amount of electricity stored in the battery (a int).

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

Provide a constructor that takes the maximum capacity as a parameter. When the Powerwall 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 instance variables and the constructor to initialize (to a assign values to) the instance variables. Write the getMaxCapacity method. Provide stubs for all other methods. Supply the Javadoc for the constructor, all the methods, and the class itself.

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

public int getCurrentCharge()    
{        
    return 0;    
}

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

There is no starter file, but you are given a PowerwallTester. Copy it into your project. To run your program, right click on Powerwall and execute its main method.

3B draft:
3B final:

3C

In this problem, you will revisit hw2c. In that homework, you drew a a railroad crossing signal on a graphical canvas. Our client wants to use the railroad crossing signal as his logo and to have several signals 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: RailroadCrossingSignal and RailroadCrossingSignalViewer. Copy the code in RailroadSignalCrossingViewer from Codecheck. You should not modify RailroadCrossingSignalViewer at all. You will write the RailroadCrossingSignal class yourself. (typo corrected 9/10 - reload your page or clear your cache)

RailroadCrossingSignalViewer 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, 30) 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 left 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 right circle is (x + 40 + 20, 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 by specifying the x, y coordinates.

Constructor

Methods

Include Javadoc for the class itself, the 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.

Note: Your draw() method should only draw one circle and should be able to draw it at any location.

3C draft:
3C final: