亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

參考了很多的大神的代碼,有些地方看不懂,我用一個上午的時間用自己的能夠理解的代碼寫的,通俗易懂些,但是有很多不足,希望大神指點,提多多的意見!

public??class?Car?{
	private?int?carNumber;
	private?String?carName;
	private?int?carRentMoney;
	
	public?int?getCarNumber()?{
		return?carNumber;
	}
	public?void?setCarNumber(int?carNumber)?{
		this.carNumber?=?carNumber;
	}
	public?String?getCarName()?{
		return?carName;
	}
	public?void?setCarName(String?carName)?{
		this.carName?=?carName;
	}
	public?int?getCarRentMoney()?{
		return?carRentMoney;
	}
	public?void?setCarRentMoney(int?carRentMoney)?{
		this.carRentMoney?=?carRentMoney;
	}
}

public?class?passengerCar?extends?Car?{
	private?int?CarCapacity;
	public?passengerCar(int?carNumber,String?carName,int?carRentMoney,int?carCapacity){
		this.setCarNumber(carNumber);
		this.setCarName(carName);
		this.setCarRentMoney(carRentMoney);
		CarCapacity?=?carCapacity;
	}

	public?int?getCarCapacity()?{
		return?CarCapacity;
	}

	public?void?setCarCapacity(int?carCapacity)?{
		CarCapacity?=?carCapacity;
	}
}

public?class?pickUp?extends?Car?{
	private?int?CarCapacity;
	private?int?CarCarry;
	
	public?pickUp(int?carNumber,String?carName,int?carRentMoney,int?CarCapacity,int?CarCarry){
		this.setCarNumber(carNumber);
		this.setCarName(carName);
		this.setCarRentMoney(carRentMoney);
		this.CarCapacity?=?CarCapacity;
		this.CarCarry?=?CarCarry;
		
	}
	public?int?getCarCapacity()?{
		return?CarCapacity;
	}
	public?void?setCarCapacity(int?carCapacity)?{
		CarCapacity?=?carCapacity;
	}
	public?int?getCarCarry()?{
		return?CarCarry;
	}
	public?void?setCarCarry(int?carCarry)?{
		CarCarry?=?carCarry;
	}

}

public?class?trunkCar?extends?Car?{
	private?int?CarCarry;
	
	public?trunkCar(int?carNumber,String?carName,int?carRentMoney,int?CarCarry){
		this.setCarNumber(carNumber);
		this.setCarName(carName);
		this.setCarRentMoney(carRentMoney);
		this.CarCarry?=?CarCarry;
		
	}
	public?int?getCarCarry()?{
		return?CarCarry;
	}

	public?void?setCarCarry(int?carCarry)?{
		CarCarry?=?carCarry;
	}
}

import?java.util.Scanner;
public?class?Test?{

	/**
	?*?@param?args
	?*/
	public?static?void?main(String[]?args)?{
		//?TODO?Auto-generated?method?stub
		System.out.println("歡迎使用答答租車系統:");
		System.out.println("你是否要租車???1是????2否");
		Scanner?s?=?new?Scanner(System.in);
		int??k?=?s.nextInt();
		if(k?==?1){
			System.out.println("您可租車的類型及其價格表:");
			Car?RentCar[]?=?{new?passengerCar(1,"奧迪A4",500,4),new?passengerCar(2,"馬自達6",400,4),new?pickUp(3,"皮卡雪6",450,4,2),new?passengerCar(4,"金龍",800,20),new?trunkCar(5,"松花江",400,4),new?trunkCar(6,"依維柯",1000,20)};
			System.out.println("序號"+"\t"+"汽車名稱"+"\t"+"\t"+"租金"+"\t"+"容量");
			for(int?i?=?0;?i?<?6;?i++){
				////若RentCar[i]它是客車類型的實例,則打印出客車應該有的屬性值,這里注意強轉,否則不會出現
				if(RentCar[i]?instanceof?passengerCar){
				System.out.println(RentCar[i].getCarNumber()+"\t"+RentCar[i].getCarName()+"\t"+"\t"+RentCar[i].getCarRentMoney()+"/天"+"\t"+"載人:"+((passengerCar)RentCar[i]).getCarCapacity()+"人");//將Car類型強制轉換成passengerCar類,得到passegerCard的屬性
				}
				if(RentCar[i]?instanceof?pickUp){
					System.out.println(RentCar[i].getCarNumber()+"\t"+RentCar[i].getCarName()+"\t"+"\t"+RentCar[i].getCarRentMoney()+"/天"+"\t"+"載人:"+((pickUp)RentCar[i]).getCarCapacity()+"人??載貨:"+((pickUp)RentCar[i]).getCarCarry()+"噸");
				}
				if(RentCar[i]?instanceof?trunkCar){
					System.out.println(RentCar[i].getCarNumber()+"\t"+RentCar[i].getCarName()+"\t"+"\t"+RentCar[i].getCarRentMoney()+"/天"+"\t"+"載人:"+((trunkCar)RentCar[i]).getCarCarry()+"噸");
				}
			}
			System.out.println("請輸入您要租汽車的數量:");
			//已經有Scanner對象,直接調用
			int?totalNum?=?s.nextInt();
			int?sum?=?0;
			for(int?j?=?1;?j?<=?totalNum;?j++){
				System.out.println("請輸入第"+j+"輛車的序號");
				int?q?=?s.nextInt();
				switch(q){
				case?1:
					?RentCar[0].getCarRentMoney();
				case?2:
					RentCar[1].getCarRentMoney();
				case?3:
					RentCar[2].getCarRentMoney();
				case?4:
					RentCar[3].getCarRentMoney();
				case?5:
					RentCar[4].getCarRentMoney();
				case?6:
					RentCar[5].getCarRentMoney();
				}
				sum?=?sum?+?RentCar[q-1].getCarRentMoney();
			}
				System.out.println("請輸入租車的天數:");
				int?day?=?s.nextInt();
				System.out.println("您的賬單:");
				System.out.println(sum?*?day);
				
			
			
		}
		

	}

}


正在回答

1 回答

怎么截圖的啊?寫得不錯!

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

參考了很多的大神的代碼,有些地方看不懂,我用一個上午的時間用自己的能夠理解的代碼寫的,通俗易懂些,但是有很多不足,希望大神指點,提多多的意見!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號