odify your element class so that it defines a natural sorting order that arranges elements alphabetically by name. You should not implemenent your own sorting algorithm, use the data structure capabilities in Java. Hint: Implementing the Comparable interface might be useful. public class Element { int number; String name; String symbol; double mass; public Element(int number, String name, String symbol, double mass) { this.number = number; this.name = name;
Modify your element class so that it defines a natural sorting order that
arranges elements alphabetically by name. You should not implemenent your own
sorting
Comparable interface might be useful.
public class Element {
int number;
String name;
String symbol;
double mass;
public Element(int number, String name, String symbol, double mass) {
this.number = number;
this.name = name;
this.symbol = symbol;
this.mass = mass;
}
public int getNumber() {
return number;
}
public String getName() {
return name;
}
public String getSymbol() {
return symbol;
}
public double getMass() {
return mass;
}
// toString()
@Override
public String toString() {
return "Element{number=" + number +
"," + "name='" + name +
"', symbol='" + symbol +
"', Atomic Mass=" + mass + "}";
}
Step by step
Solved in 3 steps with 1 images