課程
/后端開發(fā)
/Java
/Java入門第二季 升級(jí)版
?? 我 最后系統(tǒng)還是有點(diǎn)懵不會(huì)寫 有現(xiàn)成的給我參考嗎?各位大佬?
2018-08-12
源自:Java入門第二季 升級(jí)版 12-2
正在回答
import?java.util.ArrayList; import?java.util.Scanner; class?SCar?{ ????int?number; ????String?name; ????int?money; ????SCar(int?number,?String?name,?int?money)?{ ????????this.number?=?number; ????????this.name?=?name; ????????this.money?=?money; ????} } class?Car?extends?SCar?{ ????int?person; ????Car(int?number,?String?name,?int?money,?int?person)?{ ????????super(number,?name,?money); ????????this.person?=?person; ????} ????public?String?toString()?{ ????????return?"車輛編號(hào):"?+?number?+?"\t?車型:"?+?name?+?"\t??每天租金:"?+?money?+?"\t?可載人數(shù):"?+?person?; ????} } class?Pick?extends?Car?{ ????int?goods; ????Pick(int?number,?String?name,?int?money,?int?person,?int?goods)?{ ????????super(number,?name,?money,?person); ????????this.goods?=?goods; ????} ????public?String?toString()?{ ????????return?"車輛編號(hào):"?+?number?+?"\t?車型:"?+?name?+?"\t??每天租金"?+?money?+?"\t?可載人數(shù):"?+?person?+?"\t?可載貨物噸數(shù):"?+?goods; ????} } class?Turck?extends?SCar?{ ????int?goods; ????Turck(int?number,?String?name,?int?money,?int?goods)?{ ????????super(number,?name,?money); ????????this.goods?=?goods; ????} ????public?String?toString()?{ ????????return?"車輛編號(hào):"?+?number?+?"\t?車型:"?+?name?+?"\t??每天租金:"?+?money?+?"\t?可載貨物噸數(shù):"?+?goods; ????} } public?class?LianXi?{ ????public?static?void?main(String[]?args)?{ ????????System.out.println("歡迎來到Dehy租車系統(tǒng)"); ????????System.out.println("是否進(jìn)入租車系統(tǒng):1-是???0-否"); ????????Scanner?scanner?=?new?Scanner(System.in); ????????int?sc?=?scanner.nextInt(); ????????if?(sc?==?0)?{ ????????????scanner.close(); ????????????return; ????????} ????????if?(sc?==?1)?{ ????????????System.out.println("可租用車輛信息"); ????????????Car?c1?=?new?Car(1,?"奧迪",?800,?4); ????????????Turck?t1?=?new?Turck(2,?"長(zhǎng)安",?1000,?10); ????????????Pick?p1?=?new?Pick(3,?"福特猛禽",?800,?4,?1); ????????????System.out.println("車輛編號(hào):"?+?c1.number?+?"\t車型:"?+?c1.name?+?"\t每天租金:"?+?c1.money?+?"\t\t可載人數(shù):"?+?c1.person); ????????????System.out.println("車輛編號(hào):"?+?t1.number?+?"\t車型:"?+?t1.name?+?"\t每天租金:"?+?t1.money?+?"\t\t可載貨物噸數(shù):"?+?t1.goods); ????????????System.out.println("車輛編號(hào):"?+?p1.number?+?"\t車型:"?+?p1.name?+?"\t每天租金:"?+?p1.money?+?"\t\t可載人數(shù):"?+?p1.person?+?"\t?可載貨物噸數(shù):"?+?p1.goods); ????????????System.out.println("請(qǐng)輸入您需要租車數(shù)量"); ????????????Scanner?scanner1?=?new?Scanner(System.in); ????????????int?sc1?=?scanner1.nextInt(); ????????????ArrayList<Car>?list?=?new?ArrayList(); ????????????ArrayList<Turck>?list1?=?new?ArrayList(); ????????????ArrayList<Pick>?list2?=?new?ArrayList(); ????????????ArrayList?list3?=?new?ArrayList(); ????????????int?money1?=?0; ????????????for?(int?i1?=?0;?i1?<?sc1;?i1++)?{ ????????????????System.out.println("請(qǐng)輸入車輛編號(hào)"); ????????????????Scanner?scanner2?=?new?Scanner(System.in); ????????????????int?sc2?=?scanner2.nextInt(); ????????????????System.out.println("租用車輛信息"); ????????????????if?(sc2?==?1)?{ ????????????????????System.out.println("車輛編號(hào):"?+?c1.number?+?"\t車型:"?+?c1.name?+?"\t租金:"?+?c1.money?+?"\t\t可載人數(shù):"?+?c1.person); ????????????????????list.add(c1); ????????????????????list3.addAll(list); ????????????????????money1?=?money1?+?c1.money; ????????????????}?else?if?(sc2?==?2)?{ ????????????????????System.out.println("車輛編號(hào):"?+?t1.number?+?"\t車型:"?+?t1.name?+?"\t租金:"?+?t1.money?+?"\t\t可載人數(shù):"?+?t1.goods); ????????????????????list1.add(t1); ????????????????????list3.addAll(list1); ????????????????????money1?=?money1?+?t1.money; ????????????????}?else?if?(sc2?==?3)?{ ????????????????????System.out.println("車輛編號(hào):"?+?p1.number?+?"\t車型:"?+?p1.name?+?"\t租金:"?+?p1.money?+?"\t\t可載人數(shù):"?+?p1.person?+?"\t?可載貨物噸數(shù):"?+?p1.goods); ????????????????????list2.add(p1); ????????????????????list3.addAll(list2); ????????????????????money1?=?money1?+?p1.money; ????????????????}?else?{ ????????????????????System.out.println("輸入有誤,請(qǐng)重新輸入車輛編號(hào)!?如想退出程序請(qǐng)輸入:0"); ????????????????????System.out.println("請(qǐng)輸入車輛編號(hào)"); ????????????????????Scanner?scanner3?=?new?Scanner(System.in); ????????????????????int?sc3?=?scanner3.nextInt(); ????????????????????System.out.println("租用車輛信息"); ????????????????????if?(sc3?==?1)?{ ????????????????????????System.out.println("車輛編號(hào):"?+?c1.number?+?"\t車型:"?+?c1.name?+?"\t租金:"?+?c1.money?+?"\t\t可載人數(shù):"?+?c1.person); ????????????????????????list.add(c1); ????????????????????????list3.addAll(list); ????????????????????????money1?=?money1?+?c1.money; ????????????????????}?else?if?(sc3?==?2)?{ ????????????????????????System.out.println("車輛編號(hào):"?+?t1.number?+?"\t車型:"?+?t1.name?+?"\t租金:"?+?t1.money?+?"\t\t可載人數(shù):"?+?t1.goods); ????????????????????????list1.add(t1); ????????????????????????list3.addAll(list1); ????????????????????????money1?=?money1?+?t1.money; ????????????????????}?else?if?(sc3?==?3)?{ ????????????????????????System.out.println("車輛編號(hào):"?+?p1.number?+?"\t車型:"?+?p1.name?+?"\t租金:"?+?p1.money?+?"\t\t可載人數(shù):"?+?p1.person?+?"\t?可載貨物噸數(shù):"?+?p1.goods); ????????????????????????list2.add(p1); ????????????????????????list3.addAll(list2); ????????????????????????money1?=?money1?+?p1.money; ????????????????????}?else?{ ????????????????????????scanner3.close(); ????????????????????????return; ????????????????????} ????????????????} ????????????} ????????????System.out.println("請(qǐng)輸入租車天數(shù)"); ????????????Scanner?scanner3?=?new?Scanner(System.in); ????????????int?sc3?=?scanner3.nextInt(); ????????????scanner3.close(); ????????????int?money4?=?money1?*?sc3; ????????????System.out.println("租賃信息如下:"); ????????????StringBuilder?sb?=?new?StringBuilder(); ????????????for?(int?i?=?0;?i?<?list3.size();?i++)?{ ????????????????sb.append(list3.get(i)+"\r\n"); ????????????} ????????????String?str?=?sb.toString(); ????????????System.out.println(str); ????????????System.out.println("租用車輛天數(shù):"?+?sc3); ????????????System.out.println("租車所需金額:"?+?money4); ????????} ????} }
qq_一夕暮光_0 提問者
壹酒酒柒 回復(fù) qq_一夕暮光_0 提問者
慕函數(shù)2666850
package zuche;
import java.util.Scanner;
public class Test {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自動(dòng)生成的方法存根
System.out.println("? ? ? ? ? ? ? ? ***歡迎來到速運(yùn)租車***");
System.out.println("請(qǐng)問您是否要租車?");
System.out.println("1:我想要租車? ? ? ? ?2:我逛逛看? ? ? ? ? 3:我點(diǎn)錯(cuò)了");
boolean a = true;
while(a) {
int b = input.nextInt();
switch(b) {
case 1:
System.out.println("請(qǐng)問你需要什么類型的車?");
System.out.println("1:客車? ? ? ? 2:貨車? ? ? ? ? 3:既能拉貨又能拉客? ? ? ? 4:返回上級(jí)菜單");
boolean c = true;
while(c) {
int d = input.nextInt();
switch(d) {
Keche k = new Keche();
k.zaike();
c = false ;
break ;
case 2:
Huoche h = new Huoche();
h.lahuo();
case 3:
Zonghe z = new Zonghe();
z.zaike();
z.lahuo();
case 4:
Test.main(args);
c = false ;?
break ;?
default:
}
a = false;
break;
Ggk g = new Ggk();
g.xinxi();
System.out.println("退出程序!");
System.out.println("請(qǐng)輸入‘1’或者‘2’!");
我沒有
舉報(bào)
課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙
5 回答有人有最后一題的代碼嗎
2 回答請(qǐng)問最后一個(gè)項(xiàng)目的代碼哪有嗎
2 回答最后項(xiàng)目的代碼
3 回答最后項(xiàng)目代碼
1 回答最后項(xiàng)目代碼
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-08-23
2018-09-12
package zuche;
import java.util.Scanner;
public class Test {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自動(dòng)生成的方法存根
System.out.println("? ? ? ? ? ? ? ? ***歡迎來到速運(yùn)租車***");
System.out.println("請(qǐng)問您是否要租車?");
System.out.println("1:我想要租車? ? ? ? ?2:我逛逛看? ? ? ? ? 3:我點(diǎn)錯(cuò)了");
boolean a = true;
while(a) {
int b = input.nextInt();
switch(b) {
case 1:
System.out.println("請(qǐng)問你需要什么類型的車?");
System.out.println("1:客車? ? ? ? 2:貨車? ? ? ? ? 3:既能拉貨又能拉客? ? ? ? 4:返回上級(jí)菜單");
boolean c = true;
while(c) {
int d = input.nextInt();
switch(d) {
case 1:
Keche k = new Keche();
k.zaike();
c = false ;
break ;
case 2:
Huoche h = new Huoche();
h.lahuo();
c = false ;
break ;
case 3:
Zonghe z = new Zonghe();
z.zaike();
z.lahuo();
c = false ;
break ;
case 4:
Test.main(args);
c = false ;?
break ;?
default:
System.out.println("請(qǐng)問你需要什么類型的車?");
System.out.println("1:客車? ? ? ? 2:貨車? ? ? ? ? 3:既能拉貨又能拉客? ? ? ? 4:返回上級(jí)菜單");
}
}
a = false;
break;
case 2:
Ggk g = new Ggk();
g.xinxi();
a = false;
break;
case 3:
System.out.println("退出程序!");
a = false;
break;
default:
System.out.println("請(qǐng)輸入‘1’或者‘2’!");
}
}
}
}
2018-08-13
我沒有