Note: in this homework, we will start deducting points
3A
A golf player has a handicap - a decimal number between 0 an 40.4 that indicates how good a player he/she is. The lower the handicap, the better the player. When players of unequal ability want to compete, they subtract their handicap from their actual score (the number of times they had to hit the ball to complete the course) to get a net score. The lowest net score wins.
For this assignment, you will complete the Golfer
class. I supply the tester. Your class will not have a main method
A Golfer class has:
getName()
which returns the namegetHandicap()
that returns the handicapsetHandicap()
which will assign a new handicap to this Golfer
Provide Javadoc for the constructor and all methods in the final. The Javadoc for the class is given to you
For the draft, provide the instance variables, the constructor (which saves the instance variables) and include a stub for the getName()
method. Also supply the Javadoc for the constructor and getName()
. 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 getName()
.
public String getName() { return null; }
In the Javadoc for a stub, document what the method will do in the final version, not what it does temporarily in the draft.
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.
The Hal9000
constructor takes a String parameter of a name of the crew member it is interacting with.
It has methods:
public String getName()
which gets the name (Provided)public void setName(String newName)
which sets a new name (Provided)public String sayHello()
which returns a string consisting of "Greetings, name" where name is the name supplied in the constructor.public String sayStatus()
which returns a string consisting of "Everything is a go, name" where name is the name supplied in the constructor.public String refuseHelp(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.Supply Javadoc 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. 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.
For the draft, provide the instance variable (call it name) and write the constructor to initialize (to a assign the value to) the instance variable. Provide stubs for all the methods not provided (two are provided for you. You do the other three) and supply all the Javadoc for the constructor and all five methods.
3C
In this problem, you will revisit hw2c. In that homework, you drew the letters COAT on a graphical frame. Your client wants to use COAT as his logo and to have several COAT's in different places on the frame. 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 Coat
and CoatViewer
. Replace the code CoatViewer
with the code in Codecheck. You will write the Coat class yourself.
CoatViewer
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 (20, 10). 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 point of the C as parameters.
You will calculate all the other coordinates relative to that x,y. For example,the coordinates of the point on the left-side top are (x,y). And the coordinates of the point on right-side top of the C would then be (x + 30, y)
Constructor
ublic Coat(int theX, int theY)
Method
public void draw()
which will create the drawing as specified below. (The daw method should be able to draw the figure at any location, not just those in the the viewer)Include Javadoc for constructor and method
Your drawing should follow these specifications.
It is a good idea to figure out the coordinates of each letter before starting to draw. 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 C and the O (don't fill the O in the draft). Write the Javadoc for the class, the constructor, and the method.