我怎么做的这么简陋 好多开关没有 该怎么加点好呢

来源:12-1 综合练习

Dusdii

2019-05-16 18:47

public class Car {
    private String name;
    private String color;
    private int zuo;
    private int monry;
    private int t;
    private int code;

    public Car() {

    }

    public Car(int code,String name, String color, int zuo, int monry, int t) {
        setName(name);
        setCode(code);
        setZuo(zuo);
        setColor(color);
        setT(t);
        setMonry(monry);

    }

    public String getName() {
        return name;
    }

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

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getZuo() {
        return zuo;
    }

    public void setZuo(int zuo) {
        this.zuo = zuo;
    }

    public int getT() {
        return t;
    }

    public void setT(int t) {
        this.t = t;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getMonry() {
        return monry;
    }

    @Override
    public String toString() {
        return code+"    "+name+"    "+color+"      "+zuo+"      "+monry+"      "+t;
    }

    public void setMonry(int monry) {
        this.monry = monry;
    }

    public void mycar(){
        System.out.println(code+"    "+name+"    "+color+"      "+zuo+"      "+monry+"      "+t);
    }
    }

---------------------------------------------------------------------------------------------------------------------------------------------------


import java.util.ArrayList;
import java.util.Scanner;

public class Car1 {
    public static void main(String[] args) {
        ArrayList<Car> list = new ArrayList<>();
        System.out.println("序号--品  牌 ----颜色----座位数----价格----载重");
        list =pree();
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入第一台要租用的车型编号:");
        int put0 = sc.nextInt();
        System.out.print("请输入数量:");
        int put1 = sc.nextInt();
        System.out.print("请输入天数:");
        int put2 = sc.nextInt();
        System.out.print("请输入第二台要租用的车型编号:");
        int put3 = sc.nextInt();
        System.out.print("请输入数量:");
        int put4 = sc.nextInt();
        System.out.print("请输入天数:");
        int put5 = sc.nextInt();
        System.out.println("您的租车清单:");
        System.out.println(list.get(put0-1)+" 数量:"+put1+" 天数:"+put2+"天");
        System.out.println(list.get(put3-1)+" 数量:"+put4+" 天数:"+put5+"天");
        System.out.println("总金额:"+ ((list.get(put0-1).getMonry())*put1*put2+list.get(put3-1).getMonry()*put4*put5));
    }


    public static ArrayList<Car> pree(){

            ArrayList<Car> list = new ArrayList<>();
            list.add(new Car(1, "奔驰AMG", "红色", 5, 100, 0));
            list.add(new Car(2, "宝马BWM", "白色", 5, 200, 0));
            list.add(new Car(3, "腾风TGP", "蓝色", 1, 300, 0));
            list.add(new Car(4, "华为HUV", "银色", 5, 400, 0));
            list.add(new Car(4, "东风FUR", "红色", 3, 500, 100));
            list.add(new Car(4, "长城SUV", "绿色", 5, 600, 2));

        return list;
    }
}


写回答 关注

1回答

  • Dusdii
    2019-05-16 19:00:01

    看来我不太适合学这东西 就TM这么点代码 愣是写了半天? 我感觉快放弃了

    weixin... 回复一生清贫怎敢...

    一起加油

    2019-05-18 17:09:03

    共 2 条回复 >

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

531116 学习 · 6326 问题

查看课程

相似问题