[Java入门第二季练习]答答租车系统

package com.ddzuche;

public  class Car {
    protected int num;
    protected String name ;
    protected int rental;
    protected int peopleNum;
    protected int weight;
    public  int getNum(){
        return num;
    }
    public  String getName(){
        return name;
    }
    public  int getRental(){
        return rental;
    }
    public  int getPeopleNum(){
        return peopleNum;
    }
    public int getWeight(){
        return weight;
    }
    public void setName(String name){
        this.name=name;
    }
    public void setRental(int rental){
        this.rental=rental;
    }
    public void setPeopleNum(int  peopleNum){
        this.peopleNum=peopleNum;  
    }
    public void setWeight(int weight){
        this.weight=weight;
    }
    public void setNum(int num){
        this.weight=num;
    }
             
}
package com.ddzuche;

public class PassengerCar extends Car {
    public PassengerCar(int m_num, String m_name, int m_rental,int m_peopleNum ){
        this.num=m_num;
        this.name=m_name;
        this.peopleNum=m_peopleNum;
        this.rental=m_rental;        
    }
}
package com.ddzuche;

public class Pickup extends Car {
    public Pickup(int m_num, String m_name,  int m_rental, int m_peopleNum,int m_weight){
        this.num=m_num;
        this.name=m_name;
        this.peopleNum=m_peopleNum;
        this.rental=m_rental;    
        this.weight=m_weight;
    }
}
package com.ddzuche;

public class Trunk extends Car {
    public Trunk(int m_num, String m_name, int m_rental,int m_weight){
        this.num=m_num;
        this.name=m_name;
        this.weight=m_weight;
        this.rental=m_rental;    
}
}
package com.ddzuche; 
import java.util.Scanner;
import java.util.Arrays;
public class Demo {

    public static void main(String[] args) {
        // TODO Auto-generated method stubt
       Car[] cars={new PassengerCar(1,"奥迪A4",500,3),
                   new Trunk(2,"东风200",500,10),
                   new Pickup(3,"皮卡",300,3,5),
                   new PassengerCar(4,"奥迪A6",600,3),
                   new PassengerCar(5,"丰田",300,3),
                   new Trunk(6,"解放60",500,12),
                   new Pickup(7,"皮卡200",600,4,8)};
       System.out.println("*****欢迎使用答答租车系统******");  
       System.out.println("您是否要租车:1是    0否");
       Scanner scan =new Scanner(System.in);
       int input=scan.nextInt();
       if(input==1){
           System.out.println("您可租车的类型及其价目表");  
           System.out.println("序号"+"\t汽车名称"+"\t租金"+"\t载客"+"\t载货"); 
           for(int i=0;i<=6;i++){
               System.out.println(cars[i].getNum()+"\t"+cars[i].getName()+"\t"+cars[i].getRental()+"\t"+cars[i].getPeopleNum()+"\t"+cars[i].getWeight());
           }
           int totalPrice=0;
           int rentdays=0;
           String[] pc= new String[5];
           String[] tc= new String[4];
           int n=0;
           int m=0;
           System.out.println("请输入你要租车的数量");
           int carsNum=scan.nextInt();
           for (int j=0;j<carsNum;j++){
               System.out.println("请输入第"+(j+1)+"辆车的序号");
               int carNum=scan.nextInt();
               totalPrice+=cars[carNum-1].getRental();
               if(cars[carNum-1].peopleNum>0){
                   pc[n]=cars[carNum-1].getName();
                   n=n+1;   
               }
               if(cars[carNum-1].weight>0){
                   tc[m]=cars[carNum-1].getName();
                   m=m+1;   
               }
           }
               
            System.out.println("请输入租车时间:");   
            rentdays=scan.nextInt();
            scan.close();
            System.out.println("您的账单:");   
            System.out.println("*****可载人的车有*****");   
            System.out.println(Arrays.toString(pc));        
            System.out.println("*****可载货的车有*****"); 
            System.out.println(Arrays.toString(tc));    
            System.out.println("租车总价格为;"+totalPrice*rentdays);        
           }
       }      
    }

 

  

转载于:https://www.cnblogs.com/wjlcoder/p/5977313.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值