继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

达达租车系统,欢迎给出建议

fang19970312
关注TA
已关注
手记 1
粉丝 2
获赞 25
package car;

 class Car {
int number;
 String name;
 int price;
    int loadPeople;
 int loadGoods;

    public void setModel(int n,String name,int p,int lp,int lg){
        number=n;
        this.name=name;
        price=p;
        loadPeople=lp;
        loadGoods=lg;
    }
    public int  getNum(){
        return number;
    }
    public String getName(){
        return name;
    }
    public int getPrice(){
        return price;
    }
    public int getLp(){
        return loadPeople;
    }
    public int getLg(){
        return loadGoods;
    }
}

class saloonCar extends Car{

    public void setModel(int n,String name,int p,int lp){
        number=n;
        this.name=name;
        price=p;
        loadPeople=lp;
    }   

}
class Pickup extends Car{
    public void setModel(int n,String name,int p,int lp,int lg){
        number=n;
        this.name=name;
        price=p;
        loadPeople=lp;
        loadGoods=lg;
    }
}
class trunk extends Car{
    public void setModel(int n,String name,int p,int lg){

        number=n;
        this.name=name;
        price=p;
        loadGoods=lg;
    }
}
package car;
import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int i = 0;
        System.out.println("欢迎使用租车系统!");
        System.out.println("是否租车:租车输入1,不租输入2");
        Scanner s = new Scanner(System.in);
        i = s.nextInt();
        if (i == 1) {
            saloonCar Pcar[] = new saloonCar[3];
            Pickup pk = new Pickup();
            trunk tr[] = new trunk[2];
            for (int ti = 0; ti < 2; ti++) {
                tr[ti] = new trunk();
            }
            for (int j = 0; j < 3; j++) {
                Pcar[j] = new saloonCar();
            }
            Pcar[0].setModel(1, "奥迪A4", 500, 4);
            Pcar[1].setModel(2, "马自达6", 400, 4);
            Pcar[2].setModel(3, "金龙", 800, 20);
            pk.setModel(4, "皮卡雪6", 450, 4, 2);
            tr[0].setModel(5, "松花江", 400, 4);
            tr[1].setModel(6, "依维柯", 1000, 20);
            System.out.printf("序号\t汽车名称\t租金\t\t容量\t\n");

            System.out.println(Pcar[0].getNum() + ".\t" + Pcar[0].getName() + "\t" + Pcar[0].getPrice() + "元/天\t"
                    + "载人:" + Pcar[0].getLp() + "人");
            System.out.println(Pcar[1].getNum() + ".\t" + Pcar[1].getName() + "\t" + Pcar[1].getPrice() + "元/天\t"
                    + "载人:" + Pcar[1].getLp() + "人");
            System.out.println(Pcar[2].getNum() + ".\t" + Pcar[2].getName() + "\t\t" + Pcar[2].getPrice() + "元/天\t"
                    + "载人:" + Pcar[2].getLp() + "人");
            System.out.println(pk.getNum() + ".\t" + pk.getName() + "\t" + pk.getPrice() + "元/天\t" + "载人:" + pk.getLp()
                    + "人  " + "载货:" + pk.getLg() + "吨");
            System.out.println(tr[0].getNum() + ".\t" + tr[0].getName() + "\t" + tr[0].getPrice() + "元/天\t" + "载货:"
                    + tr[0].getLg() + "吨");
            System.out.println(tr[1].getNum() + ".\t" + tr[1].getName() + "\t" + tr[1].getPrice() + "元/天 " + "载货:"
                    + tr[1].getLg() + "吨");
            System.out.println("请输入您要租汽车的数量:");
            Scanner s2 = new Scanner(System.in);
            int am = s2.nextInt();
            int Acar[] = new int[am];
            for (int j = 0; j < am; j++) {
                System.out.println("请输入第" + (j + 1) + "辆车的序号");
                Scanner s3 = new Scanner(System.in);
                Acar[j] = s3.nextInt();
            }
            System.out.println("请输入租车天数:");
            Scanner s4 = new Scanner(System.in);
            int day = s2.nextInt();
            int price=0;
            //***************************************************
            System.out.println("***可载人的车有:");
            int presult=0;
            for (int j = 0; j < am; j++) {
                for (int lj = 0; lj < 3; lj++) {
                    if (Acar[j] == Pcar[lj].getNum()) {
                        System.out.printf(Pcar[lj].getName() + "\t");
                        presult+=Pcar[lj].getLp();
                        price+=Pcar[lj].getPrice()*day;
                    }
                }
                if (Acar[j] == pk.getNum()) {
                    System.out.printf(pk.getName() + "\t");
                    presult+=pk.getLp();

                }
            }
            System.out.println("共载人:"+presult);
            //*****************************************************************//
                System.out.println("***可载货的车有:");
                int gresult=0;
                for (int j1 = 0; j1 < am; j1++) {
                    if (Acar[j1] == pk.getNum()) {
                        System.out.printf(pk.getName() + "\t");
                        gresult+=pk.getLg();

                    }
                    if (Acar[j1] == tr[0].getNum()) {
                        System.out.printf(tr[0].getName() + "\t");
                        gresult+=tr[0].getLg();
                        price+=tr[0].getPrice()*day;
                    }
                    if (Acar[j1] == tr[1].getNum()) {
                        System.out.printf(tr[1].getName() + "\t");
                        gresult+=tr[1].getLg();
                        price+=tr[1].getPrice()*day;
                    }
                }
                System.out.println("共载货:"+gresult);
            // ***************************************************************************
                for(int pkm=0;pkm<am;pkm++){
                    if(Acar[pkm]==pk.getNum()){
                        price+=pk.getPrice()*day;
                    }
                }
                System.out.println("租车总价格为:"+price);
            }

        if (i == 2) {
            System.out.println("感谢使用");
        }

    }

}

欢迎大神给出建议,小白一个

打开App,阅读手记
19人推荐
发表评论
随时随地看视频慕课网APP

热门评论

执行成功了吗?看着有点晕

没有对属性进行封装,getter和setter就是多余的了

没用private修饰,getter没有意义吧。http://www.imooc.com/article/17384  来看看我的,欢迎指教

查看全部评论