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

答答租车系统项目作业

Ba啦啦啦
关注TA
已关注
手记 1
粉丝 0
获赞 8

//父类
package com.project;

public class Didi {
public String name;
public int take;
public int ton;
public double rentm;
public int rentsum;

public int getRentsum() {
    return rentsum;
}

public void setRentsum(int rentsum) {
    this.rentsum = rentsum;
}

public void Didi(String name,int take,int ton,double rentm){

}

public String getName() {
    return name;
}

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

public int getTake() {
    return take;
}

public void setTake(int take) {
    this.take = take;
}

public int getTon() {
    return ton;
}

public void setTon(int ton) {
    this.ton = ton;
}

public double getRentm() {
    return rentm;
}

public void setRentm(double rentm) {
    this.rentm = rentm;
}

}


//载人车类
package com.project;

public class Car extends Didi {
public String name;
public int take;
public double rentm;
public int rentsum;

public int getRentsum() {
    return rentsum;
}
public void setRentsum(int rentsum) {
    this.rentsum = rentsum;
}

public Car(String name,double rentm,int take){
    this.name=name;
    this.take=take;
    this.rentm=rentm;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getTake() {
    return take;
}
public void setTake(int take) {
    this.take = take;
}
public double getRentm() {
    return rentm;
}
public void setRentm(double rentm) {
    this.rentm = rentm;
}

}


//货车类
package com.project;

public class Truck extends Didi {
public String name;
public int ton;
public double rentm;
public int rentsum;

public int getRentsum() {
    return rentsum;
}
public void setRentsum(int rentsum) {
    this.rentsum = rentsum;
}

public Truck(String name,double rentm,int ton){
    this.name=name;
    this.ton=ton;
    this.rentm=rentm;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getTon() {
    return ton;
}
public void setTon(int ton) {
    this.ton = ton;
}
public double getRentm() {
    return rentm;
}
public void setRentm(double rentm) {
    this.rentm = rentm;
}

}


//皮卡类
package com.project;

public class PickUp extends Didi {
public String name;
public int take;
public int ton;
public double rentm;
public int rentsum;

public int getRentsum() {
    return rentsum;
}
public void setRentsum(int rentsum) {
    this.rentsum = rentsum;
}

public PickUp(String name,double rentm,int take,int ton){
    this.name=name;
    this.take=take;
    this.ton=ton;
    this.rentm=rentm;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getTake() {
    return take;
}
public void setTake(int take) {
    this.take = take;
}
public int getTon() {
    return ton;
}
public void setTon(int ton) {
    this.ton = ton;
}
public double getRentm() {
    return rentm;
}
public void setRentm(double rentm) {
    this.rentm = rentm;
}

}


main方法
package com.project;
import java.util.Scanner;

public class Initial {

public static void main(String[] args) {
    // TODO 自动生成的方法存根
Scanner input=new Scanner(System.in);
Initial it=new Initial();
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是 0否");

do{
    int isof=input.nextInt();
    if(isof==0){
        System.out.println("欢迎您下次光临!");
        break;
    }
    else if(isof==1){
        System.out.println("您可租车的类型及其价目表:");
        System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"\t"+"容量");
        it.test();
        break;
    }else{
        System.out.println("您的输入有误,请重新输入:");
        continue;
    }
}while(true);
}
public void test(){
        Scanner input=new Scanner(System.in);
        Didi[] carForRent={new Car("奥迪A4",500,4),new Car("马自达6",400,4),new PickUp("皮卡雪6",450,4,2),
                           new Car("金龙",800,20),new Truck("松花江",400,4),new Truck("依维柯",1000,20)};
        int i=1;
        for(Didi rentCar:carForRent){
            if(rentCar instanceof Car){
                System.out.println(i+"\t"+rentCar.getName()+"\t"+rentCar.getRentm()+"元/天"+"\t"+"载人:"+rentCar.getTake()+"人");
                i++;
            }
            else if(rentCar instanceof Truck){
                System.out.println(i+"\t"+rentCar.getName()+"\t"+rentCar.getRentm()+"元/天"+"\t"+"载货:"+rentCar.getTon()+"吨");
                i++;
            }
            else{
                System.out.println(i+"\t"+rentCar.getName()+"\t"+rentCar.getRentm()+"元/天"+"\t"+"载人:"+rentCar.getTake()+"人"+" 载货:"+rentCar.getTon()+"吨");
                i++;
            }
        }
        double money=0;
        int mem1=0,mem2=0,mem3=0,mem4=0,mem5=0,mem6=0;
            System.out.println("请输入你要租车的数量:");
            int a=input.nextInt();
            for(int b=1;b<=a;b++){
                System.out.println("请输入第"+b+"辆车的序号:");
                int c=input.nextInt();
                switch(c){
                case 1: ++mem1;
                        carForRent[0].setRentsum(mem1);
                        break;
                case 2: ++mem2;
                        carForRent[1].setRentsum(mem2);
                        break;
                case 3:++mem3;
                        carForRent[2].setRentsum(mem3);
                        break;
                case 4:++mem4;
                        carForRent[3].setRentsum(mem4);
                        break;
                case 5:++mem5;
                        carForRent[4].setRentsum(mem5);
                        break;
                case 6:++mem6;
                        carForRent[5].setRentsum(mem6);
                        break;

                }
            }
            System.out.println("请输入租车天数:");
            int day=input.nextInt();
            System.out.println("你的账单:");
            System.out.println("***可载人的车有:");
            int take=0;
            for(int d=0;d<6;d++){
                if(carForRent[d].getRentsum()>0&&carForRent[d].getTake()>0){
                    System.out.print(carForRent[d].getName()+"x"+carForRent[d].getRentsum()+"  ");
                    take=take+carForRent[d].getRentsum()*carForRent[d].getTake();
                }
            }
            if(take>0){
                System.out.println("共载人:"+take+"人");
            }else System.out.println("无可载人的车");

            System.out.println("***可载货的车有:");
            int ton=0;
            for(int d=0;d<6;d++){
                if(carForRent[d].getRentsum()>0&&carForRent[d].getTon()>0){
                    System.out.print(carForRent[d].getName()+"x"+carForRent[d].getRentsum()+"  ");
                    ton=ton+carForRent[d].getRentsum()*carForRent[d].getTon();
                }
            }
            if(ton>0){
                System.out.println("共载货:"+ton+"吨");
            }else System.out.println("无可载货的车");
        for(int d=0;d<6;d++){
            money+=carForRent[d].getRentm()*carForRent[d].getRentsum()*day;
        }
        System.out.println("***租车总价格:"+money+"元");
        }
}
打开App,阅读手记
5人推荐
发表评论
随时随地看视频慕课网APP