4A
Java Wheat owns grain elevators. These grain elevators are tall cylinders use to store wheat. They are filled exactly to the top of the cylinder. Here is a picture.
We buy wheat from farmers and store it in our grain elevators. We pay $5 per cubic yard at the end of the harvest. And store the wheat until the next spring when we anticipate the price will be S7.50 a cubic yard. It cost $5000 in labor and miscellaneous expenses to store the wheat for 1 month.
You will complete the class GrainElevator
. A GrainElevator
has a constructor which takes the height and the radius of the cylinder in feet as parameters. height and width are specified in feet and in that order. You will write the constructor.
A GrainElevator
has these methods
public void setHeight(double theHeight)
- providedpublic void setRadius(double theRadius)
- providedpublic double getVolume()
gets the volume on cubic feet. Use Math.PIpublic double getBuyingPrice()
- This is the amount we pay for enough wheat to fill the grain elevator. You must use the getVolume
method in this calculation. Only calculate volume one time in your solutionpublic double getSellingPrice()
- This is the amount we get when we sell a full elevator. You must use the getVolume
method in this calculation. Only calculate volume once in your solutionpublic double getProfit(int monthsHeld)
- you must use the other methods in this calculation. Only calculate volume, buying price, and selling price in one place in your solutionProvide Javadoc for the class, the constructor, every method, every parameter and every return value..
Declare constants for the buying price, selling price and monthly expenses. You would declare the buying price this way:
public static final double BUYING_PRICE = 5.0;
Notice you will need to convert units from square feet to square yards to calculate the labor cost. Use the constant provided.
public static final int CUBIC_FEET_PER_CUBIC_YARD = 9;
For the draft: Write the constructor to initialize the instance variables. Implement the other methods as stubs. Provide all the Javadoc
Note: The Javadoc for setRadius is not complete in the Codecheck starer file. It should read like this (2/11/16)
/** * sets a new radius for this GrainElevator * @param theRadius the new radius */
4B
Things like towels, shirts, and glassware are often personalized with a person's initials (monogrammed). You are to write a class Monogram. A Monogram consists of a first name, middle initial (one letter. No period), and last name.
There is no starter file. You will write the whole class.
The Monogram
class has two constructors (This is called overloading).
public Monogram(String theFirst, String theMiddleInitial, String theLast)
initializes the instance variables with the values of the parameters. (theMiddleInitial will be exactly 1 character long)public Monogram(String theFirst, String theLast)
initializes the first and last names to the given parameters and initializes the middle initial to the empty String (two double quotes with no space like this "")Monogram
class has these methods
public String getFirst()
public String getMiddleInitial()
public String getLast()
public int characterCount()
the number of characters in the full name - not counting spacespublic String getFullName()
gets the full name with spaces separating the namespublic String getMonogram()
gets the initials of the Monogram(first initial, middle initial, last initial) with no spacesProvide full Javadoc (the class, the constructors, and the methods)
To get the first letter of a string word do this
String firstLetter = word.substring(0,1);
For the draft, provide the instance variables, the first constructor and implement getFirst
, getMiddleInitial
, and getLast
methods. Include the Javadoc for the implemented elements (class, constructor, and the three methods).
4C
In this assignment you are going to enhance the Golfer class. You will add the functionality needed to keep track of scores for games played by the golfer.
Add these methods to the Golfer class
public String getScoreRecord()
- returns a string that shows the score for each game and the average score. Assume that the number of scores will not be 0. The String will have the format belowpublic void reset()
- resets the score record to an empty string and the total and count to 0public int calculateScore(int strokes)
-gets the score for a game with the given strokes for this Golfer. strokes is the number of times the Golfer hit the ball in this game. The score is the strokes in this game minus the golfer's handicap rounded to the nearest int. For example, if a Golfer with a handicap of 10 takes 100 strokes to complete a game, his score is 90 (100 - 10)public void recordGame
(int strokes) - gets the score for this game and concatenates it to the record. Call the calculateScore
method. Do not compute the score again in this method. This method will also need to keep track of the total of all the scores so you can calculate the average later.Format of the String returned by getScoreRecord
:
Game 1: 95
Game 2: 87
Game 3: 93
Game 4: 91
Average:
91.5
Notice you print the word Game, a space, the number of this game, a colon, a space, and then the value. I should get the same output if I call getScoreRecord () twice in a row.
You will need additional instance variables in the final. Think about what the class needs to remember to accomplish its tasks. Those are your instance variables. The constructor needs to initialize them.
To add a line to the record, form a String consisting of the word "Game " + the gameNumber + ": " + score + "\n". Concatenate it to the end of the record. (Notice the newline character at the end)
You need to provide a Javadoc comment for your methods.
For the draft, write the calculateScore method.