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

Java入门第二季最后一节

标签:
Java

父类

public class Car {
	public String CarModels; //序号
	public String CarName;  //车名
	public int CarRent; //日租金
	public int CarSeat; //车载人数
	public double CarryCargo;  //载货量
	
	public Car(){}
	public Car(String CarModels,String CarName,int CarRent,int CarSeat,double CarryCarge){
		this.CarModels=CarModels;
		this.CarName=CarName;
		this.CarRent=CarRent;
		this.CarSeat=CarSeat;
		this.CarryCargo=CarryCarge;
	}
	
	public String getCarModels() {
		return CarModels;
	}
	public void setCarModels(String carModels) {
		CarModels = carModels;
	}
	public String getCarName() {
		return CarName;
	}
	public void setCarName(String carName) {
		CarName = carName;
	}
	public int getCarRent() {
		return CarRent;
	}
	public void setCarRent(int carRent) {
		CarRent = carRent;
	}
	public int getCarSeat() {
		return CarSeat;
	}
	public void setCarSeat(int carSeat) {
		CarSeat = carSeat;
	}
	public double getCarryCargo() {
		return CarryCargo;
	}
	public void setCarryCargo(double carryCargo) {
		CarryCargo = carryCargo;
	}
	
}

货车类

public class Truck extends Car {
	public Truck(String CarModels,String CarName,int CarRent,double CarryCarge){
		this.setCarModels(CarModels); //车型
		this.setCarName(CarName); //车名
		this.setCarRent(CarRent); //日租金
		this.setCarryCargo(CarryCarge); //载货量
	}
	@Override
    public String toString() {
        return  " "+CarModels +
                "\t" + CarName +
                "\t\t"+CarRent +"元/日\t\t"+
                "载货" + CarryCargo +"吨"
                 ;
    }
}


皮卡类

public class Pick extends Car {
	public Pick(String CarModels,String CarName,int CarRent,int CarSeat,double CarryCarge){
		this.setCarModels(CarModels); //车型
		this.setCarName(CarName); //车名
		this.setCarRent(CarRent); //日租金
		this.setCarryCargo(CarryCarge); //载货量
		this.setCarSeat(CarSeat); //载人数
	}
	@Override
    public String toString() {
        return  " "+CarModels +
                "\t" + CarName +
                "\t\t"+CarRent +"元/日\t\t"+
                "载人:"+ CarSeat +"人 "+
                "载货:" + CarryCargo +"吨"
                 ;
    }
}

轿车类

public class Landdaulet extends Car {
	public Landdaulet(String CarModels,String CarName,int CarRent,int CarSeat){
		this.setCarModels(CarModels); //车型
		this.setCarName(CarName); //车名
		this.setCarRent(CarRent); //日租金
		this.setCarSeat(CarSeat); //载人数
	}
	@Override
    public String toString() {
        return  " "+CarModels +
                "\t" + CarName +
                "\t\t"+CarRent +"元/日\t\t"+
                "载人:"+ CarSeat +"人 ";
    }
}

主程序

import java.util.Scanner;

//主程序
public class Main {
	
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Car[] cars={
				new Landdaulet("1.", "奥迪A4", 500, 4),
				new Landdaulet("2.", "马自达6", 400, 4),
				new Pick("3.", "皮卡雪6", 450, 4, 2),
				new Landdaulet("4.", "金龙", 800, 20),
				new Truck("5.", "松花江", 400, 4),
				new Truck("6.", "依维柯", 900, 20)
				
		};
		int priece=0; //账单
		System.out.println("欢迎使用答答租车系统:");
		System.out.println("您是否要租车:1是  0否");
		Scanner sca=new Scanner(System.in);
		int shifou=sca.nextInt();
		if(shifou!=1){
			System.out.println("感谢使用,欢迎下次光临");
		}else{
			System.out.println("您可租车的类型及其价目表:");
			System.out.println("序号\t汽车名称\t\t租金\t\t容量");
			for(int i=0;i<cars.length;i++){
				System.out.println(cars[i]);
			}
			System.out.println("请输入您要租汽车的数目:");
			int carnum=sca.nextInt();
			for(int i=0;i<carnum;i++){
				System.out.println("请输入第"+(i+1)+"辆车的序号:");
				int carn=sca.nextInt();
				priece+=cars[carn-1].CarRent;
			}
			System.out.println("请输入租车天数:");
			int day=sca.nextInt();
			System.out.println("您的账单:"+priece*day+"元");
		}
	}

}
点击查看更多内容
1人点赞

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消