Java入门租车系统练习

//父类,车辆
package com.imooc;
public class automobile {
 private int NO;
 private String name;
 private int seat;//座位数(载人数)
 private int load;//载重量
 private float price;
/**
*生成getter方法
*/
 public int getNO() {
  return NO;
 }
 public void setNO(int nO) {
  NO = nO;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getSeat() {
  return seat;
 }
 public void setSeat(int seat) {
  this.seat = seat;
 }
 public int getLoad() {
  return load;
 }
 public void setLoad(int load) {
  this.load = load;
 }
 public float getPrice() {
  return price;
 }
 public void setPrice(float price) {
  this.price = price;
 }
}
package com.imooc;
//********************小轿车****************************
public class Car extends automobile {
 private int NO;
 private String name;
 private int seat;//座位数(载人数)
 private float price;

 public Car(int NO,String name,int seat,float price) {
  this.NO=NO;
  this.name=name;
  this.seat=seat;
  this.price=price;
 }
/**
*生成setter,getter方法
*/

 public int getNO() {
  return NO;
 }
 public void setNO(int nO) {
  NO = nO;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getSeat() {
  return seat;
 }
 public void setSeat(int seat) {
  this.seat = seat;
 }
 public float getPrice() {
  return price;
 }
 public void setPrice(float price) {
  this.price = price;
 }
}
package com.imooc;
//********************客车****************************
public class bus extends automobile {
 private int NO;
 private String name;
 private int seat;//座位数(载人数)
 private float price;
 public bus(int NO,String name,int seat,float price) {
  this.NO=NO;
  this.name=name;
  this.seat=seat;
  this.price=price;
 }
 public int getNO() {
  return NO;
 }
 public void setNO(int nO) {
  NO = nO;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getSeat() {
  return seat;
 }
 public void setSeat(int seat) {
  this.seat = seat;
 }
 public float getPrice() {
  return price;
 }
 public void setPrice(float price) {
  this.price = price;
 }
}
package com.imooc;
//********************皮卡****************************
public class pickup extends automobile {
 private int NO;
 private String name;
 private int seat;//座位数(载人数)
 private int load;
 private float price;
 public pickup(int NO,String name,int seat, int load,float price) {
  this.NO=NO;
  this.name=name;
  this.seat=seat;
  this.load=load;
  this.price=price;
 }
 
 public int getNO() {
  return NO;
 }
 public void setNO(int nO) {
  NO = nO;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getSeat() {
  return seat;
 }
 public void setSeat(int seat) {
  this.seat = seat;
 }
 public int getLoad() {
  return load;
 }
 public void setLoad(int load) {
  this.load = load;
 }
 public float getPrice() {
  return price;
 }
 public void setPrice(float price) {
  this.price = price;
 }
 
}
//********************大货车****************************
package com.imooc;
public class truck extends automobile {
 private int NO;
 private String name;
 private int load;
 private float price;
 public truck(int NO,String name, int load,float price) {
  this.NO=NO;
  this.name=name;
  this.load=load;
  this.price=price;
 }
 public int getNO() {
  return NO;
 }
 public void setNO(int nO) {
  NO = nO;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getLoad() {
  return load;
 }
 public void setLoad(int load) {
  this.load = load;
 }
 public float getPrice() {
  return price;
 }
 public void setPrice(float price) {
  this.price = price;
 }
}
//****************************main方法*******************************************
package com.imooc;
import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
  
  System.out.println("欢迎来到答答租车系统!");
  System.out.println("请问您是否需要租车?是:1,否:2\n");
  @SuppressWarnings("resource")
  Scanner Scan=new Scanner(System.in);
  int a=Scan.nextInt();
  if(a==1)
  {
   int i=0;
   System.out.println("以下是可租用车辆信息及价格:");
   System.out.println("序号"+"\t"+"汽车名称"+"\t"+"载客数"+"\t"+"载货量(吨)"+"\t"+"租金(元/天)");
   automobile [] Information= {new Car(1,"宝马x5",4,500),new Car(2,"马自达6",6,400),
     new bus(3,"宇通客车",19,800),new pickup(4,"皮卡雪",4,2,550),new truck(5,"金龙",20,1000)};
   for(i=0;i<5;i++)
   {
    System.out.println(Information[i].getNO()+"\t"+Information[i].getName()+"\t"+Information[i].getSeat()+"\t"
      +Information[i].getLoad()+"\t"+Information[i].getPrice());
    //System.out.println("\n");
   }
   System.out.println("请输入您想要租的车辆数:");
   int b=Scan.nextInt();//车辆数b
   int j=0;
   int [] count=new int[b];
   for(j=0;j<b;j++)
   {
    System.out.println("请输入您想租用的车辆序号:");
    int c=Scan.nextInt();
    
    count[j]=c-1;
   }
   System.out.println("请输入您想要租的天数:");
   int days=Scan.nextInt();
   int Price=0,sumPerson=0,sumLoad=0;//分别为价格,人数,载重
   int m;
   for(j=0;j<b;j++)
   {
    m=count[j];
    Price+=Information[m].getPrice();
    sumPerson+=Information[m].getSeat();
    sumLoad+=Information[m].getLoad();
   }
   int sumPrice;
   sumPrice=Price*days;
   System.out.println("这是您的租车信息统计:");
   System.out.println("您租的车共可以乘坐的人数:"+sumPerson);
   System.out.println("您租的车共载重(吨):"+sumLoad);
   System.out.println("您应付的金额(元):"+sumPrice);
   System.out.println("感谢您的使用,预祝您用车愉快!");
  }else if(a==2)
  {
   System.out.println("这里有车的信息,请您看一下,需要租车的话一定要来哦!");
   int i=0;
   System.out.println("以下是可租用车辆信息及价格:");
   System.out.println("序号"+"\t"+"汽车名称"+"\t"+"载客数"+"\t"+"载货量(吨)"+"\t"+"租金(元/天)");
   automobile [] Information= {new Car(1,"宝马x5",4,500),new Car(2,"马自达6",6,400),
     new bus(3,"宇通客车",19,800),new pickup(4,"皮卡雪",4,2,550),new truck(5,"金龙",20,1000)};
   for(i=0;i<5;i++)
   {
    System.out.println(Information[i].getNO()+"\t"+Information[i].getName()+"\t"+Information[i].getSeat()+"\t"
      +Information[i].getLoad()+"\t        "+Information[i].getPrice());
   }
  }else
  {
   System.out.println("您输入的信息有误,请重新输入!是:1,否:2");
  }
 }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值