vehicle.java
来自「AutoSale Interface」· Java 代码 · 共 66 行
JAVA
66 行
package autosale;import java.io.*;import java.util.*;public abstract class Vehicle implements Comparable, Printable, Serializable { private String registration; private String brand; private String model; private int price; public abstract int getInsurancePrice(); public int compareTo(Object obj) { Vehicle v = (Vehicle)obj; return this.getRegistration().compareTo(v.getRegistration()); } /* //Order by price instead public int compareTo(Object obj) { Vehicle v = (Vehicle)obj; return this.price - v.price; }*/ public String getRegistration() { return registration; } public String getBrand() { return brand; } public String getModel() { return model; } public int getPrice() { return price; } protected Vehicle() { Scanner sc = new Scanner(System.in); System.out.println("Enter registration:"); registration = sc.nextLine(); System.out.println("Enter brand:"); brand = sc.nextLine(); System.out.println("Enter model:"); model = sc.nextLine(); System.out.println("Enter price:"); price = sc.nextInt(); } public void print() { System.out.println(this.getClass().getSimpleName()); System.out.println(registration); System.out.println(brand); System.out.println(model); System.out.println(price); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?