记录我的代码【01】租车系统

父类

package com.zuche;
/**
 * 这是一个父类。
 * 这里规定车的属性,并写了构筑本类的方法。和输出车的属性的方法。
 * @author long
 *
 */
public  class CarProperty {
    public String carP1;//车辆名称
    public  String carP2; //车辆类型
     public int carP3;//载客量
     public  int carP4;//载货量
     public int carP5; //租金每天

     public CarProperty(String newcarP1,String newcarP2,
             int newcarP3,int newcarP4,int newcarP5) {
         carP1=newcarP1;
         carP2=newcarP2;
         carP3=newcarP3;
         carP4=newcarP4;
         carP5=newcarP5;    
     }
    public String toString() {
        return carP1 + "         " + carP2 + "            " + carP3 + "        " + carP4 + "     "
                + carP5 ;
    }

}

子类

package com.zuche;
/**
 * 这是一个子类
 * @author long
 *
 */
public class HuoChe extends CarProperty {

    public HuoChe(String newcarP1, String newcarP2, int newcarP3, int newcarP4, int newcarP5) {
        super(newcarP1, newcarP2, newcarP3, newcarP4, newcarP5);
        // TODO Auto-generated constructor stub
    }




}
package com.zuche;

public class KeChe extends CarProperty {

    public KeChe(String newcarP1, String newcarP2, int newcarP3, int newcarP4, int newcarP5) {
        super(newcarP1, newcarP2, newcarP3, newcarP4, newcarP5);
        // TODO Auto-generated constructor stub
    }


}
package com.zuche;

public class PiKa extends CarProperty {

    public PiKa(String newcarP1, String newcarP2, int newcarP3, int newcarP4, int newcarP5) {
        super(newcarP1, newcarP2, newcarP3, newcarP4, newcarP5);
        // TODO Auto-generated constructor stub
    }

}

测试

package com.zuche;
import java.util.*;
/**
 * 这是一个测试类
 * @author long
 *
 */
public class Initial {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
    CarProperty huo1=new HuoChe("1,奥迪", "货车", 2, 3, 100);
    CarProperty huo2=new HuoChe("2,奥拓", "货车", 2, 2, 80);
     CarProperty ke1=new KeChe("3,宝马", "客车", 4, 0, 150);
     CarProperty ke2=new KeChe("4,一汽", "客车", 4, 0, 100);
     CarProperty pi1=new PiKa("5,五菱", "两用", 8, 2, 80);
     CarProperty pi2=new PiKa("6,奔马", "两用", 2, 3, 60);
         int  sum=0;
        int i3=0;
    System.out.println("请您选择是否租车?");
    System.out.println("1,是    2,否");
    Scanner input1=new Scanner(System.in);
      int i1=input1.nextInt();
    if(i1==1) {
        System.out.println("车辆名称   车辆类型   载客量/人   载货量/吨   租金/每天");
        System.out.println(huo1.toString());
        System.out.println(huo2.toString());
        System.out.println(ke1.toString());
        System.out.println(ke2.toString());
        System.out.println(pi1.toString());
        System.out.println(pi2.toString());
  /* System.out.println("请您选择租车数量:");
        Scanner input2=new Scanner(System.in);
          int i2=input2.nextInt();
*/    //     for(int i=1;i<i2+1;i++) {
            //  System.out.println("请输入您要租用的第"+i+"辆车的编号");
        System.out.println("请输入您要租用辆车的编号");

        Scanner input3=new Scanner(System.in);
                i3=input3.nextInt();
              switch(i3) {
              case 1:
                  sum=100;
                  break;
              case 2:
                  sum=20;
                  break;
              case 3:
                  sum=150;
                  break;
              case 4:
                  sum=100;
                  break;
              case 5:
                  sum=80;
                  break;
              case 6:
                  sum=60;
                  break;
                  default:
                      System.out.println("您输入的编号是无效的!");

              }/*if(i3<0||i3>6)
                  break;*/
                 /* }*/if(i3>0&&i3<7) {
                      System.out.println("请您选择租车数量:");
                        Scanner input2=new Scanner(System.in);
                          int i2=input2.nextInt();
           System.out.println("请输入租用的天数");
          Scanner input4=new Scanner(System.in);
          int sum1=input4.nextInt();
            sum=sum*sum1*i2;

          System.out.println("总共租车:"+i2+"辆,租用:"+sum1+"天,共需:"+sum+"元人民币。");
          }else {
              System.out.println("请重新操作!");
          } }else {
        System.out.println("感谢使用该系统!");
    }

    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值