阅读背景:

如何从arraylist输出值

来源:互联网 

My program is:

我的计划是:

public class Vehicle {

    String colors[] = {"Red", "White", "Blue", "black", "Silver"};
    private String name;
    private String model;
    double cost_price;
    int year;
    int quantity;
    double selling_price;
    String registration_no;

    Vehicle(String name, String model, int year, double cost_price) {
        this.name = name;
        this.model = model;
        this.year = year;
        this.cost_price = cost_price;
        this.quantity = 0;
        this.selling_price = 0;
    }

    Vehicle(String name, String model, int quantity, double cost_price, String registration_no) {
        this.name = name;
        this.model = model;
        this.quantity = quantity;
        this.cost_price = cost_price;
        this.selling_price = cost_price;
        this.registration_no = registration_no;
    }

    public void setname(String name) {
        this.name = name;
    }

    public void setmodel(String model) {
        this.model = model;
    }

    public String getname() {
        return name;
    }

    public String getmodel() {
        return model;
    }

    public double calSellingPrice(int markup) {

        return cost_price + ((cost_price * markup) / 100);
    }

    public int updateQuantity(int amount) {

        return quantity;
    }

    public String tostring() {
    }
    /**
     * @param args the command line arguments
     */
}

class Vehicletest {

    public static void main(String[] args) {
        // TODO code application logic here

        Vehicle v1 = new Vehicle("Ferrari", "Enzo", 2011, 250000);
        v1 = new Vehicle("Ferrari", "Enzo", 6, 250000, "PK07LVD");
        Vehicle v2 = new Vehicle("Audi", "R8", 2008, 550000);
        v2 = new Vehicle("Audi", "R8", 9, 550000, "ADDY104");
        Vehicle v3 = new Vehicle("RangeRover", "Evoque", 2010, 578000);
        v3 = new Vehicle("RangeRover", "Evoque", 3, 578000, "OHZ2692");
        Vehicle v4 = new Vehicle("Lamborghine", "Aventador", 2013, 980000);
        v4 = new Vehicle("Lamborghine", "Aventador", 5, 980000, "BB03813");
        Vehicle v5 = new Vehicle("Porsche", "Carrera", 2006, 675000);
        v5 = new Vehicle("Porsche", "Carrera", 15, 675000, "BD51SMR");
        ArrayList uwiMotors = new ArrayList();

        uwiMotors.add(v1);
        uwiMotors.add(v2);
        uwiMotors.add(v3);
        uwiMotors.add(v4);
        uwiMotors.add(v5);
        System.out.println(v1.colors);
        System.out.println(v1.cost_price);
        System.out.println(v1.quantity);
        System.out.println(v1.registration_no);
        System.out.println(v1.selling_price);
        System.out.println(v1.year);

        for (int i = 0; i < uwiMotors.size(); i++) {
            System.out.println(uwiMotors.get(i));


        }
    }
}
public class Vehicle 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: