为了账号安全,请及时绑定邮箱和手机立即绑定

java第二季答答租车系统

标签:
Java

/
车类Car
*/

public abstract class Car {
public String name;
public int personCapacity;//载客量
public int goodCapacity;//载货量
public int price;//租车价格

public String getName() {
    return name;
}

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

public abstract void printInfo();

}
//客车类
public class Coach extends Car {

public Coach(String name,int price,int personCapacity){
this.name=name;
this.personCapacity=personCapacity;
this.price=price;
}

public void printInfo(){
System.out.println(this.name+"\t"+this.price
+"元/天\t载客:"+this.personCapacity+"人");
}
//货车
public class Truck extends Car {

public final int personCapacity=0;//货车载客量为0

public Truck(String name,int price,int goodCapacity){
    this.name=name;
    this.price=price;
    this.goodCapacity=goodCapacity;
}

public void printInfo(){
    System.out.println(this.name+"\t"+this.price
             +"元/天\t载货:"+this.goodCapacity+"吨");
}

}
//皮卡,既能载客又能载货
public class Pk extends Car {

public Pk(String name,int price,int personCapacity,int goodCapacity){
    this.name=name;
    this.price=price;
    this.personCapacity=personCapacity;
    this.goodCapacity=goodCapacity;
}

public void printInfo(){
    System.out.println(this.name+"\t"+this.price
             +"元/天\t载客:"+this.personCapacity+"人\t载货:"+this.goodCapacity+"吨");
}

}

import java.util.Scanner;
public class Initial {

/**
 * @param args
 */
public static void main(String[] args) {

 Car[] cars={new Coach("奥迪",500,4),new Coach("马自达6",400,4)
            ,new Coach("金龙",800,20),new Pk("皮卡雪6",450,4,2)
            ,new Truck("松花江",400,4),new Truck("依维柯",1000,20)};

    Scanner sc=new Scanner(System.in);
    System.out.println("欢迎使用答答租车系统");
    System.out.println("您是否要租车?0:不是,1:是");
    int i=sc.nextInt();
    switch(i){
    case 0:{
        System.out.println("您已退出该系统");
        break;
    }
    case 1:{
        System.out.println("您可租车的车型及其价目表如下:");
        System.out.println("序号\t汽车名称\t租金\t容量");
         for(int j=0;j<cars.length;j++){
             System.out.print(j+1+"\t");
             cars[j].printInfo();
         }

        System.out.println("请输入您要租车的数量:");
        int number=sc.nextInt();

        System.out.println("奥迪的数量:");
        int number1=sc.nextInt();

        System.out.println("马自达6的数量:");
        int number2=sc.nextInt();

        System.out.println("金龙的数量:");
        int number3=sc.nextInt();

        System.out.println("皮卡雪6的数量:");
        int number4=sc.nextInt();

        System.out.println("松花江的数量:");
        int number5=sc.nextInt();

        System.out.println("依维柯的数量:");
        int number6=sc.nextInt();

        System.out.println("请输入您要租车的天数:");
        int day=sc.nextInt();
        System.out.println("您租车的金额为:"
        +(cars[0].price*number1+cars[1].price*number2
                +cars[2].price*number3+cars[3].price*number4+
                cars[4].price*number5+cars[5].price*number6)*day+"元");

        break;
    }

}

}
}

点击查看更多内容
5人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消