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

第一个正式java程序!我爱哒哒租车

标签:
Java

结合几个大神的作品,终于敲完了!!!!!!
加油啦啦啦~~~~~~~

package com.carStore;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
        // TODO Auto-generated method stub
        Coach car1=new Coach("1","奥迪",500,4);
        Coach car2=new Coach("2","马自达",400,4);
        Pika car3=new Pika("3","皮卡学",450,4,2);
        Coach car4=new Coach("4","京龙",800,20);
        Truck car5=new Truck("5","松花江",400,4);
        Truck car6=new Truck("6","依维柯",1000,20);
        Scanner input=new Scanner(System.in);
        System.out.println("欢迎使用大大租车系统:");
        System.out.println("您是否需要租车:1是 0不是");
        int x=input.nextInt();
        if(x==1){
            System.out.println("您可租的车辆类型及价目表:"+"\n"+"序号 汽车名称 租金 空间");
           car1.print();
           car2.print();
           car3.print();
           car4.print();
           car5.print();
           car6.print();
           System.out.println("请输入您要租的汽车数量:(限租20辆)");
           int amount =input.nextInt();//获取用户租车数量并保存 
               int[] putnum=new int[20];
               for(int i=1;i<=amount;i++){
                   System.out.println("请输入第"+i+"辆车的序号");
                   putnum[i]=input.nextInt();
                   if(putnum[i]==1){car1.print();}
                   else if(putnum[i]==2){car2.print();}
                   else if(putnum[i]==3){car3.print();}
                    else if(putnum[i]==4){car4.print();}
                    else if(putnum[i]==5){car5.print();}
                    else if(putnum[i]==6){car6.print();}
               }
               System.out.println("请输入租车天数:");
               int days=input.nextInt();
               int[] people=new int[20];
               int snum=0;
               for(int j=1;j<=amount;j++){
                   if(putnum[j]==1){people[j]=car1.getNum();}
                   else if(putnum[j]==2){people[j]=car2.getNum();}
                   else if(putnum[j]==3){people[j]=car3.getNum();}
                   else if(putnum[j]==4){people[j]=car4.getNum();}
                   else {people[j]=0;}
                   snum=snum+people[j];
               }
               System.out.println("共可载人:"+snum);
               int[] goods=new int[20];
               int sgoods=0;
               for(int k=1;k<=amount;k++){
                   if(putnum[k]==3){goods[k]=car3.getBurden();}
                   else if(putnum[k]==5){goods[k]=car5.getBurden();}
                   else if(putnum[k]==6){goods[k]=car6.getBurden();}
                   else {goods[k]=0;}
                   sgoods+=goods[k];
               }
               System.out.println("共可载重:"+sgoods+"吨");
               int[] money=new int[20];
               int smoney=0;
               for(int m=1;m<=amount;m++){
                   if(putnum[m]==1){money[m]=car1.getMoney();}
                   else if(putnum[m]==2){money[m]=car2.getMoney();}
                   else if(putnum[m]==3){money[m]=car3.getMoney();}
                   else if(putnum[m]==4){money[m]=car4.getMoney();}
                   else if(putnum[m]==5){money[m]=car5.getMoney();}
                   else if(putnum[m]==6){money[m]=car6.getMoney();}
                   smoney+=money[m];
               }
               smoney=smoney*days;
               System.out.println("***租车总价格:");
               System.out.println(smoney+"元");
               }
           }
package com.carStore;

public abstract class Car {
    public String xuhao;
    public String name;
    public int money;
    public String getXuhao(){
        return xuhao;
    }
    public void setXuhao(String xuhao){
        this.xuhao=xuhao;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int getMoney(){
        return money;
    }
    public void setMoney(int money){
        this.money=money;
    }
    public Car(){};
    public Car(String xuhao,String name,int money){
        this.xuhao=xuhao;
        this.name=name;
        this.money=money;
    }

}
package com.carStore;

public class Coach extends Car {
   public int num;
   public int getNum(){
       return num;
   }
   public void setNum(int num){
       this.num=num;
   }
   public Coach(String xuhao,String name,int money,int num){
    this.xuhao=xuhao;
    this.name=name;
    this.money=money;
    this.num=num;
   }
    public void print() {
    System.out.println("["+xuhao+'\t'+name+'\t'+money+"元/天"+'\t'+"载人量:"+num+"人"+'\t'+"]");
    }
}
package com.carStore;

public class Truck extends Car {
    public int burden;
    public int getBurden(){
        return burden;
    }
    public void setBurden(int burden){
        this.burden=burden;
    }
    public Truck(String xuhao,String name,int money,int burden){
        this.xuhao=xuhao;
        this.name=name;
        this.money=money;
        this.burden=burden;
    }
    public void print() {
        System.out.println("["+xuhao+'\t'+name+'\t'+money+"元/天"+'\t'+"载货量:"+burden+"吨"+'\t'+"]");
    }
}
package com.carStore;

public class Pika extends Car {
       public int num;
       public int burden;
       public int getNum(){
           return num;
       }
       public void setNum(int num){
           this.num=num;
       }
       public int getBurden(){
            return burden;
        }
        public void setBurden(int burden){
            this.burden=burden;
        }
       public Pika(String xuhao,String name,int money,int num,int burden){
        this.xuhao=xuhao;
        this.name=name;
        this.money=money;
        this.num=num;
        this.burden=burden;
       }
        public void print() {
            System.out.println("["+xuhao+'\t'+name+'\t'+money+"元/天"+'\t'+"载人量:"+num+"人"+'\t'+"载货量:"+burden+"吨"+'\t'+"]");
        }
}
点击查看更多内容
TA 点赞

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消