手记

答答租车系统 小纪---原版与改版

car.java
package dadazuce;

public class car{
int numb;
String name;
int rent;
int peonum;
int huonum;
}

peocar.java
package dadazuce;

public class peocar extends car {
public peocar(int a,String name,int i,int t){
this.numb=a;
this.name=name;
this.rent=i;
this.peonum=t;
}
}

huocar.java
package dadazuce;

public class huocar extends car {
public huocar(int a,String name,int i,int t){
this.numb=a;
this.name=name;
this.rent=i;
this.huonum=t;
}
}

peohuocar.java
package dadazuce;

public class peohuocar extends car {
public peohuocar(int a,String name,int i,int t,int k){
this.numb=a;
this.name=name;
this.rent=i;
this.peonum=t;
this.huonum=k;
}
}

main函数
package dadazuce;
import java.util.*;
//参考编写出 答答租车系统
public class test2 {
public static void main(String[] args) {
car[] carslists={new peocar(1,"奥迪4",500,4),new peocar(2,"马自达6",400,4),new peohuocar(3,"皮卡6",450,4,2),new peocar(4,"金龙",800,20),new huocar(5,"松花江",400,4),new huocar(6,"依维柯",1000,20)};//使用对象组 为各个子类对象赋值

    System.out.println("欢迎使用答答租车系统:");
    System.out.println("您是否要租车:1.是  0.否");

    double moneysum=0;
    int peosum=0;
    int huosum=0;

    Scanner in=new Scanner(System.in);
//  int input=in.next(); 此处错误,无法从String类 转换为 int类型
    String input1=in.next();//接受输入
    if(input1.equals("1"));{//判读输入是否为1
        System.out.println("您可租车的类型及其价格表");
        System.out.println("序号\t汽车名称\t租金\t客容量\t货容量");
        for(car carslist:carslists){//数组循环输出
            System.out.println(carslist.numb+"\t"+carslist.name+"\t"+carslist.rent+"\t"+carslist.peonum+"\t"+carslist.huonum+"\t");
        }
        System.out.println("请输入您需要租车的数量");
        int number=in.nextInt();//输入的租车数量
        String carzaihuo="";//不用字符数组 用字符介入
        String carzairen="";
        for(int i=0;i<number;i++){//多少量车,每辆车选择的型号
            System.out.println("请输入第"+(i+1)+"的序号:");
            int t=in.nextInt();//输入的租车序号
            moneysum=moneysum+carslists[t-1].rent; //选取车辆的租金数
            if(t==5t==6){
            carzaihuo=carzaihuo+carslists[t-1].name;//选取车辆的名字列表单
            huosum=huosum+carslists[t-1].huonum;   //统计货车可拉取货物数
            }else if(t==1t==2t==4){
            carzairen=carzairen+carslists[t-1].name;  //统计租用汽车清单
            peosum=peosum+carslists[t-1].peonum;    //统计汽车数可乘坐人数
            }else{
            carzaihuo=carzaihuo+carslists[t-1].name;
            carzairen=carzairen+carslists[t-1].name;
            peosum=peosum+carslists[t-1].peonum;
            huosum=huosum+carslists[t-1].huonum;
            }
        }
        System.out.println("请输入租车天数:");
        int dAys=in.nextInt();
        System.out.println("您的账单:");
        System.out.println("**您租的可载人的车有:");
        System.out.println(carzairen+"共载人"+peosum+"人");
        System.out.println("**您租的可载货的车有:");
        System.out.println(carzaihuo+"共载货"+huosum+"吨");
        System.out.println("**租车总价格"+moneysum*dAys+"元");

    }else if(input1.equals("0")){
        System.out.println("感谢对答答的支持");
    }else{
        System.out.println("您的输入错误");
    }

}

}

0人推荐
随时随地看视频
慕课网APP