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

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

本人完成的嘀嘀租車系統、如有欠缺希望得到大神的指點~~

package?com.imooc.item;
/**
?*?汽車類
?*?@author?MeRos
?*
?*/
public?class?Car?{
	public?int?rent;
	public?String?name;
	
	public?int?getRent()?{
		return?rent;
	}
	public?void?setRent(int?rent)?{
		this.rent?=?rent;
	}
	public?String?getName()?{
		return?name;
	}
	public?void?setName(String?name)?{
		this.name?=?name;
	}
	
}
package?com.imooc.item;

/**
?*?載客車類
?*?
?*?@author?MeRos
?*
?*/
public?class?PassagerCar?extends?Car?{
	private?int?peopleCapacity;

	public?PassagerCar(String?name,?int?rent,?int?peopleCapacity)?{
		this.name?=?name;
		this.rent?=?rent;
		this.peopleCapacity?=?peopleCapacity;
	}

	public?int?getPeopleCapacity()?{
		return?peopleCapacity;
	}

	public?void?setPeopleCapacity(int?peopleCapacity)?{
		this.peopleCapacity?=?peopleCapacity;
	}
}
package?com.imooc.item;

/**
?*?載貨車類
?*?
?*?@author?MeRos
?*
?*/
public?class?Trunk?extends?Car?{
	private?int?cargoCapacity;

	public?Trunk(String?name,?int?rent,?int?cargoCapacity)?{
		this.name?=?name;
		this.rent?=?rent;
		this.cargoCapacity?=?cargoCapacity;
	}

	public?int?getCargoCapacity()?{
		return?cargoCapacity;
	}

	public?void?setCargoCapacity(int?cargoCapacity)?{
		this.cargoCapacity?=?cargoCapacity;
	}

}
package?com.imooc.item;

/**
?*?皮卡車類
?*?
?*?@author?MeRos
?*
?*/
public?class?Pickup?extends?Car?{
	private?int?cargoCapacity;
	private?int?peopleCapacity;

	public?Pickup(String?name,?int?rent,?int?peopleCapacity,?int?cargoCapacity)?{
		this.name?=?name;
		this.rent?=?rent;
		this.peopleCapacity?=?peopleCapacity;
		this.cargoCapacity?=?cargoCapacity;
	}

	public?int?getCargoCapacity()?{
		return?cargoCapacity;
	}

	public?void?setCargoCapacity(int?cargoCapacity)?{
		this.cargoCapacity?=?cargoCapacity;
	}

	public?int?getPeopleCapacity()?{
		return?peopleCapacity;
	}

	public?void?setPeopleCapacity(int?peopleCapacity)?{
		this.peopleCapacity?=?peopleCapacity;
	}
}
package?com.imooc.item;

import?java.util.Scanner;

public?class?Test?{

	public?static?void?main(String[]?args)?{
		double?totalMoney?=?0;?//?汽車總單價
		int?totalPerson?=?0;?//?總載人數
		double?totalCargo?=?0;?//?總載貨量
		StringBuffer?perMessage?=?new?StringBuffer();?//?動態字符串數組存儲載人的車輛名
		StringBuffer?cargoMessage?=?new?StringBuffer();?//?動態字符串數組存儲載物的車輛名
		Car[]?cars?=?{?new?PassagerCar("奧迪A4",?500,?4),
				new?PassagerCar("馬自達6",?400,?4),?new?Pickup("皮卡雪",?450,?4,?2),
				new?PassagerCar("金龍",?800,?20),?new?Trunk("松花江",?400,?4),
				new?Trunk("依維柯",?1000,?20)?};
		System.out.println("歡迎使用嘀嘀租車系統:");
		System.out.println("您是否要租車:1.是??0.否");
		Scanner?input?=?new?Scanner(System.in);
		int?isNot?=?input.nextInt();
		if?(isNot?==?1)?{
			System.out.println("您可租車的類型及其價目表:");
			System.out.println("序號\t汽車名稱\t租金\t\t容量");
			int?i?=?1;
			for?(Car?currentCar?:?cars)?{?//?遍歷輸出所有車輛信息
				if?(currentCar?instanceof?PassagerCar)?{
					System.out.println(i?+?"."?+?"\t"?+?currentCar.getName()
							+?"\t"?+?currentCar.getRent()?+?"元/天?"?+?"\t"
							+?"載人:"
							+?((PassagerCar)?currentCar).getPeopleCapacity()
							+?"人");
				}
				if?(currentCar?instanceof?Trunk)?{
					System.out.println(i?+?"."?+?"\t"?+?currentCar.getName()
							+?"\t"?+?currentCar.getRent()?+?"元/天?"?+?"\t"
							+?"載貨:"?+?((Trunk)?currentCar).getCargoCapacity()
							+?"噸");
				}
				if?(currentCar?instanceof?Pickup)?{
					System.out.println(i?+?"."?+?"\t"?+?currentCar.getName()
							+?"\t"?+?currentCar.getRent()?+?"元/天?"?+?"\t"
							+?"載人:"?+?((Pickup)?currentCar).getPeopleCapacity()
							+?"人?載貨:"
							+?((Pickup)?currentCar).getCargoCapacity()?+?"噸");
				}
				i++;
			}

			System.out.println("請輸入您要租汽車的數量:");
			int?num?=?input.nextInt();

			for?(int?j?=?0;?j?<?num;?j++)?{
				System.out.println("請輸入第"?+?(j?+?1)?+?"輛車的序號:");
				int?serialNum?=?input.nextInt();
				boolean?checkNum?=?false;
				while?(!checkNum)?{
					for?(int?k?=?0;?k?<?cars.length;?k++)?{
						if?(serialNum?==?k?+?1)?{
							checkNum?=?true;
							break;
						}

					}
					if?(!checkNum)?{
						System.out.println("您輸入的序號不存在,請重新輸入:");
						serialNum?=?input.nextInt();
					}
				}
				serialNum?=?serialNum?-?1;

				//?獲取不同車型的相關信息
				if?(cars[serialNum]?instanceof?PassagerCar)?{
					totalPerson?+=?((PassagerCar)?cars[serialNum])
							.getPeopleCapacity();
					totalMoney?+=?((PassagerCar)?cars[serialNum]).getRent();
					perMessage.append(cars[serialNum].getName()?+?"?");
				}
				if?(cars[serialNum]?instanceof?Trunk)?{
					totalCargo?+=?((Trunk)?cars[serialNum]).getCargoCapacity();
					totalMoney?+=?((Trunk)?cars[serialNum]).getRent();
					cargoMessage.append(cars[serialNum].getName()?+?"?");
				}
				if?(cars[serialNum]?instanceof?Pickup)?{
					totalPerson?+=?((Pickup)?cars[serialNum])
							.getPeopleCapacity();
					totalCargo?+=?((Pickup)?cars[serialNum]).getCargoCapacity();
					totalMoney?+=?((Pickup)?cars[serialNum]).getRent();
					perMessage.append(cars[serialNum].getName()?+?"?");
					cargoMessage.append(cars[serialNum].getName()?+?"?");
				}
			}

			System.out.println("請輸入租車天數:");
			int?days?=?input.nextInt();
			System.out.println("您的賬單:");
			System.out.println("**可載人的車有:");
			System.out.println(perMessage?+?"\t共載人:"?+?totalPerson?+?"人");
			System.out.println("**可載貨的車有:");
			System.out.println(cargoMessage?+?"\t共載貨:"?+?totalCargo?+?"噸");
			System.out.println("**租車總價格:"?+?(totalMoney?*?days)?+?"元");
		}
	}

}


正在回答

2 回答

做的很不錯。我只做了一部分 ╮(╯▽╰)╭。

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

在哪可以找到Java界面編程的視頻?

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

碼農_鑫森淼焱垚 提問者

你可以學學后面的Java Web、
2015-08-16 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

本人完成的嘀嘀租車系統、如有欠缺希望得到大神的指點~~

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

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

幫助反饋 APP下載

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

公眾號

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