Program 4 – Diamond

25.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . png solution files instantly, after Payment


5/5 - (1 vote)
A diamond is 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 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
Run the diamond program with the driver provided online 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 to turn in:
– Soft copy of the script command (using Blackboard)
– Soft copy of the program (submit your .java file using Blackboard)