A diamond is stone which is usually valued based on its size, clarity, and color
ID: 3567532 • Letter: A
Question
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:
Your program will have the following instance methods:
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 statements.
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)
Driver:
Explanation / Answer
import java.util.Arrays;
public class Diamond implements Comparable<Auddete_Diamond>{
private String stockNumber;
private double carot;
private String clarity;
private char color;
private String cut;
public Diamond(String stockNumber, double carot, String clarity,
char color, String cut) {
super();
this.stockNumber = stockNumber;
this.carot = carot;
this.clarity = clarity;
this.color = color;
this.cut = cut;
}
public String getStockNumber() {
return stockNumber;
}
?
?
?
public double getCarot() {
return carot;
}
?
?
?
public String getClarity() {
return clarity;
}
?
?
?
public char getColor() {
return color;
}
?
?
?
public String getCut() {
return cut;
}
public String toString()
{
return "Stock No :"+this.getStockNumber()+" Carot :"+this.getCarot()+" Clarity :"+this.getClarity()+" Color :"+this.getColor()+" Cut :"+this.getCut();
}
?
?
@Override
public int compareTo(Auddete_Diamond diamond) {
if(this.getCarot()>diamond.getCarot())
return -1;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.