Access over 35 million academic & study documents

A diamond is a stone which is usually valued based on its size, clar

Content type
User Generated
Rating
Showing Page:
1/10
A diamond is a stone which is usually valued based on its
size, clarity, and color, and can be cut in many different
styles. Write a program titled \"YourLastName_Diamond\"
that represents the information gathered of a diamond and
implements the comparable interface.
Your program will have the following instance variables:
- stockNumber contains the identifying string of the
diamond.
- carot contains a double for the size of the diamond.
- clarity contains a string with the clarity grade of the
diamond.
- color contains a char with the color grade of the
diamond.
- cut contains a string with the name of the diamond\'s
cut.
Your program will have the following instance methods:
- getStock(), getCarot(), getClarity(), getColor(), getCut()
which will return their corresponding variable.
- toString() a descriptive method of the diamond class
which generally covers all the instance variables.
- compareTo(Diamond other) compares two diamonds
and returns an int value so that better diamonds are to the
left of poor diamonds when sorted. This means that
goodDiamond.compareTo(poorDiamond) returns a negative
value.
- A constructor method for the class which takes in a
string, double, string, char, and string as arguments in
order to initialize one of each of the instance variables
given above.
Use the following guidelines for the instance variables and
methods above:
The size of a diamond is measured in carots, usually less
than 5.0. The clarity grade of a diamond is given as a two
or three letter code, FL, IF, VVS1, VVS2, VS1, VS2, SI1,
SI2, I1, I2, I3. FL (flawless) is the best, I3 is the worst. The

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/10
color grade is a one letter code, D through Z. D is the best,
Z is the worst. The cut is the name of the pattern the
diamond has been cut into.
The method compareTo() is written so that diamonds are
ordered first by carot, then by clarity OR color, whichever
is better for the particular diamond. Since there are 23
grades of color, but only 11 grades of clarity, regard the
first two color grades as equal in grade to the first grade of
clarity, the next two color grades equal in grade to the
second grade of clarity, and so on. In comparing the codes
for clarity, you will need a series of if statements.
Run the diamond program with the driver provided ( named
DiamondTester.java) and capture all interaction in a file
using the script command. (Modify the driver for
\"YourName_Diamond\" to be used in place of Diamond in
the main method)
What should be turned in:
- Soft copy of the results using the script command
- Soft copy of the programs
Solution
/* Diamond.java */
import java.util.*;
import java.lang.*;
import java.io.*;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/10

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 10 pages?
Access Now
Unformatted Attachment Preview
A diamond is a stone which is usually valued based on its size, clarity, and color, and can be cut in many different styles. Write a program titled \"YourLastName_Diamond\" that represents the information gathered of a diamond and implements the comparable interface. Your program will have the following instance variables: - stockNumber – contains the identifying string of the diamond. - carot – contains a double for the size of the diamond. - clarity – contains a string with the clarity grade of the diamond. - color – contains a char with the color grade of the diamond. - cut – contains a string with the name of the diamond \'s cut. Your program will have the following instance methods: - getStock(), getCarot(), getClarity(), getColor(), getCut() which will return their corresponding variable. - toString() – a descriptive method of the diamond class which generally covers all the instance variables. - compareTo(Diamond other) – compares two diamonds and returns an int value so that better diamonds a re to the left of poor diamonds when sorted. This means that goodDiamond.compareTo(poorDiamond) returns a negative value. - A constructor method for the class which takes in a string, double, string, char, and string as arguments in order to initialize one of each of the instance variables given above. Use the following guidelines for the instance variables and methods above: The size of a diamond is measured in carots, usually less than 5.0. The clarity grade of a ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Goes above and beyond expectations!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents