不太瞭解如何以問題的方式實現此功能。這裏是問題可比較的界面作業
創建一個實現Comparable接口的類Bike。您應該在自行車類,顏色,價格,製造商,型號和評級中具有以下屬性。您應該根據價格進行比較。使用公差值0.0001比較它們。編寫一個主驅動程序,通過在控制檯收集信息的地方創建自行車來測試程序。
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Program3 {
public static void main(String[] args) {
Bike b1 = new Bike(300,"red","schwin","mountain crusher",8.6);
Bike b2 = new Bike(500,"black","cassio","road dominator",12.5);
Bike b3 = new Bike(200,"blue","rolex","blue diamond",4.3);
Bike b4 = new Bike(1524500,"silver","military","spy bike",143.2);
List<Bike> bike = new ArrayList<Bike>();
bike.add(b1);
bike.add(b2);
bike.add(b3);
bike.add(b4);
System.out.println(bike);
Collections.sort(bike);
System.out.println(bike);
public class Bike {
private int price;
private String color,brand,model;
private double rating;
public Bike(int price, String color, String brand, String model, double rating) {
this.price=price;
this.color=color;
this.brand=brand;
this.model=model;
this.rating=rating;
}
}
你想讓我們對此做些什麼? –
只是希望一些方向都是 – user2974899
關鍵詞「功課」。我們通常不會做你的功課。抱歉。 – Tdorno