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

Java工程师面向对象6.2哒哒打车系统代码

标签:
Java

//父类
package com.dada;

public class Vehicle
{
private int number, rent, capacityMan, capacityCargo;
private String brandName;

public Vehicle(int number, String brandName, int rent, int capacityMan, int capacityCargo)
{
this.number=number;
this.brandName=brandName;
this.rent=rent;
this.capacityMan=capacityMan;
this.capacityCargo=capacityCargo;

}
public int getNumber()
{
return number;
}
public int getRent()
{
return rent;
}
public int getCapacityMan()
{
return capacityMan;

}public int getCapacityCargo()
{
return capacityCargo;
}

public String getBrandName()
{
return brandName;
}

}
//子类1
package com.dada;

public class ForMan extends Vehicle
{

public ForMan(int number, String brandName, int rent, int capacityMan, int capacityCargo)
{
    super(number, brandName, rent, capacityMan, capacityCargo);
    // TODO Auto-generated constructor stub

    System.out.println(number+"\t"+brandName+"\t"+rent+"\tMan:"+capacityMan);
}

}
//子类2
package com.dada;

public class ForCargo extends Vehicle
{

public ForCargo(int number, String brandName, int rent, int capacityMan, int capacityCargo)
{
    super(number, brandName, rent, capacityMan, capacityCargo);
    // TODO Auto-generated constructor stub

    System.out.println(number+"\t"+brandName+"\t"+rent+"\tCargo:"+capacityCargo);

}

}
//子类3
package com.dada;

public class ForBoth extends Vehicle
{

public ForBoth(int number, String brandName, int rent, int capacityMan, int capacityCargo)
{
    super(number, brandName, rent, capacityMan, capacityCargo);

    System.out.println(number+"\t"+brandName+"\t"+rent+"\tMan:"+capacityMan+"\tCargo:"+capacityCargo);
}

}

//main中代码实现
package com.dada;
import java.util.*;
public class DadaTest
{

public static void main(String[] args)
{

   System.out.println("Welcome to DADA System! Would you like rent a car today? Choose 1 for Yes and 0 for exit.");
   Scanner scan=new Scanner(System.in);
   int input=scan.nextInt();
   if(input==1)
   {
       System.out.println("***The List of Cars and Rent as below***");
       System.out.println("No.\tBrand\tRent\tCapacity");
       Vehicle []All={new ForMan(1, "AudiA4", 500, 4,0),
               new ForMan(2, "Mazda6", 400, 4,0), 
               new ForBoth(3,"Pika6",450,4,2),
               new ForMan(4,"Jinlong",800,20,0),
               new ForCargo(5,"Shj", 400,0,4), 
               new ForCargo(6,"Ivike", 1000, 0, 20)}; 

       System.out.println("Please input the number of your cars");
       int inputNumber=scan.nextInt();
       int load=0;
       int loads=0;
       int price=0;
       int prices=0;
       String brands=" ";
       String brandss=" ";

       for(int i=1;i<=inputNumber;i++)
       {
           System.out.print("Please input the "+i+" car's No.:");
           int number=scan.nextInt();

           //price=price+(All[number-1].getRent());
           //brands=brands+(All[number-1].getBrandName());
           //load=load+(All[number-1].getCapacityMan()+All[number-1].getCapacityCargo());
           if(number==1number==2number==3number==4)
           {
               brands=brands+(All[number-1].getBrandName());
               load=load+(All[number-1].getCapacityMan());
               price=price+(All[number-1].getRent());
           }
           if(number==3number==5number==6)
           {
               brandss=brandss+(All[number-1].getBrandName());
               loads=loads+(All[number-1].getCapacityCargo());
               prices=prices+(All[number-1].getRent());
           }
           if(number==3)
           {
               prices=0;
           }
       }
       System.out.println("Please days: ");
       int day=scan.nextInt();

       System.out.println("Your bill: ");
       System.out.println("***Forman: "+brands+"\tTotal\t"+load+" people");
       System.out.println("***Forcargo: "+brandss+"\tTotal\t"+loads+" cargo");
       System.out.println("The total price is:\t"+(prices+price)*day);
    }

   if(input==0)
   {
       System.out.println("See you next time!");
   }
}

}

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

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消