我寫的答答打車,歡迎指導(dǎo)
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
// TODO 自動(dòng)生成的方法存根
? ? ? ?Peoplecar car1=new Peoplecar("奧迪A4",500,4,0);
? ? ? ?Peoplecar car2=new Peoplecar("馬自達(dá)6",400,4,0);
? ? ? ?Pickup ? ?car3=new Pickup("皮卡雪6",450,4,2);
? ? ? ?Peoplecar car4=new Peoplecar("金龍",800,20,0);
? ? ? ?Goodscar ?car5=new Goodscar("松花江",400,0,4);
? ? ? ?Goodscar ?car6=new Goodscar("依維柯",1000,0,20);
? ? ? ?Scanner input=new Scanner(System.in);
? ? ? ?System.out.println("歡迎使用答答租車系統(tǒng):您是否要租車:1是 0否");
? ? ? ?int choose=input.nextInt();//輸入1或者0選擇
? ? ? ?if(choose==1){
? ? ?System.out.println("您可租車類型及其價(jià)目表:");
? ? ?System.out.println("序號(hào)\t汽車名稱\t租金\t\t容量");
? ? ?System.out.println(1+"\t"+car1.getCarName()+"\t"+car1.getPrice()+"元/天"+"\t"+car1.getBusLoad()+"人"+"\t"+car1.getCarGo()+"噸");
? ? ?System.out.println(2+"\t"+car2.getCarName()+"\t"+car2.getPrice()+"元/天"+"\t"+car2.getBusLoad()+"人"+"\t"+car2.getCarGo()+"噸");
? ? ?System.out.println(3+"\t"+car3.getCarName()+"\t"+car3.getPrice()+"元/天"+"\t"+car3.getBusLoad()+"人"+"\t"+car3.getCarGo()+"噸");
? ? ?System.out.println(4+"\t"+car4.getCarName()+"\t"+car4.getPrice()+"元/天"+"\t"+car4.getBusLoad()+"人"+"\t"+car4.getCarGo()+"噸");
? ? ?System.out.println(5+"\t"+car5.getCarName()+"\t"+car5.getPrice()+"元/天"+"\t"+car5.getBusLoad()+"人"+"\t"+car5.getCarGo()+"噸");
? ? ?System.out.println(6+"\t"+car6.getCarName()+"\t"+car6.getPrice()+"元/天"+"\t"+car6.getBusLoad()+"人"+"\t"+car6.getCarGo()+"噸");
? ? ? ? ?System.out.println("請(qǐng)輸入你要租車的數(shù)量:");
? ? ? ? ?int score=input.nextInt();//輸入要租用的數(shù)量信息
? ? ? ? ?String nsum1="";//初始化屬性
? ? ? ? ?String nsum2="";//初始化屬性?
? ? ? ? ?String nsum3="";//初始化屬性
? ? ? ? ?String nsum4="";//初始化屬性
? ? ? ? ?String nsum5="";//初始化屬性
? ? ? ? ?String nsum6="";//初始化屬性
? ? ? ? ?int psum=0;//初始化屬性
? ? ? ? ?double hsum=0;//初始化屬性
? ? ? ? ?double jsum=0;//初始化屬性
? ? ? ? ?for(int i=1;i<=score;i++){
? ? ? ? //通過(guò)租用數(shù)量信息score定義循環(huán)的最大值
? ? ? ? System.out.println("請(qǐng)輸入第"+i+"輛車的序號(hào)");
? ? ? ? int a=input.nextInt();//通過(guò)輸入選擇合適值與入口匹配運(yùn)算
? ? ? ? if(a>=1&&a<=6){
? ? ? ? ? ? ? if(a==1){//輸入值等于1時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum1=car1.getCarName();
? ? ? ? ? ? ? jsum+=car1.getPrice();
? ? ? ? ? ? ? ? ? psum+=car1.getBusLoad();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? if(a==2){//輸入值等于2時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum2=car2.getCarName();
? ? ? ? ? ? ? jsum+=car2.getPrice();
? ? ? ? ? ? ? ? ? psum+=car2.getBusLoad();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? if(a==3){//輸入值等于3時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum3=car3.getCarName();
? ? ? ? ? ? ? jsum+=car3.getPrice();
? ? ? ? ? ? ? ? ? psum+=car3.getBusLoad();
? ? ? ? ? ? ? ? ? hsum+=car3.getCarGo();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? if(a==4){//輸入值等于4時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum4=car4.getCarName();
? ? ? ? ? ? ? jsum+=car4.getPrice();
? ? ? ? ? ? ? ? ? psum+=car4.getBusLoad();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? if(a==5){//輸入值等于5時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum5=car5.getCarName();
? ? ? ? ? ? ? jsum+=car5.getPrice();
? ? ? ? ? ? ? ? ? hsum+=car5.getCarGo();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? if(a==6){//輸入值等于6時(shí)執(zhí)行下面語(yǔ)句
? ? ? ? ? ? ? nsum6=car6.getCarName();
? ? ? ? ? ? ? ? ? jsum+=car6.getPrice();
? ? ? ? ? ? ? ? ? hsum+=car6.getCarGo();
? ? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? System.out.println("輸入值有錯(cuò)誤!");
? ? ? ? System.exit(0);//退出所有程序
? ? ? ? }
? ? ? ? ? ? ? }
? ? ? ? ?System.out.println("請(qǐng)輸入租車天數(shù):");
? ? ? ? ?int b=input.nextInt();//租用天數(shù)并賦值給b
? ? ? ? ?System.out.println("您的賬單:");
? ? ? ? ?System.out.println("***可載人的車有:");
? ? ? ? ?//在此輸出只要執(zhí)行過(guò)的再次賦值的載人車輛名稱
? ? ? ? ?System.out.println(nsum1+"\t"+nsum2+"\t"+nsum3+"\t"+nsum4);
? ? ? ? ?System.out.println("共載人:"+psum+"人");
? ? ? ? ?System.out.println("***載貨的車有:");
? ? ? ? ?//在此輸出只要執(zhí)行過(guò)的再次賦值的載貨車輛名稱
? ? ? ? ?System.out.println(nsum3+"\t"+nsum5+"\t"+nsum6);
? ? ? ? ?//因?yàn)槊看味荚谙嗉?,所以最后循環(huán)出來(lái)的就是總量
? ? ? ? ?System.out.println("共載貨:"+hsum+"噸");
? ? ? ? ?jsum=jsum*b;//因?yàn)閮r(jià)格每次循環(huán)沒(méi)有清零,所以一直相加一起,再此處乘以天數(shù)即可
? ? ? ? ?System.out.println("***租車總價(jià)格:"+jsum+"元");
? ? ? ? ?}
? ? ? ? ?if(choose==0){
? ? ? System.out.println("正在退出系統(tǒng),歡迎下次再來(lái)!");
? ? ? ?}else{
? ? ? System.out.println("您輸入的值有誤!"); ? ??
? ? ? ?}
}
}
作者: 慕粉小蝸牛?
完整鏈接:http://idcbgp.cn/article/8889
來(lái)源:慕課網(wǎng)
本文原創(chuàng)發(fā)布于慕課網(wǎng) ,禁止轉(zhuǎn)載
2016-06-13
? ? ? ?Scanner input=new Scanner(System.in);
? ? ? ?System.out.println("歡迎使用答答租車系統(tǒng):您是否要租車:1是 0否");
? ? ? ?int choose=input.nextInt();//輸入1或者0選擇
這里String類型可以直接轉(zhuǎn)換成int型嗎?
2016-08-08
對(duì)象建議寫出數(shù)組形式,不用寫那么多的引用,之后的遍歷直接一個(gè)for()循環(huán)就可以了,比較簡(jiǎn)潔。
2016-07-16
if else 里面有點(diǎn)小問(wèn)題
2016-07-15
看錯(cuò)了
2016-07-15
你這樣寫要是a=50,你怎么辦
2016-06-16
和我寫的還挺像的,哈哈
問(wèn)一句,下面句代碼什么意思? 感覺(jué)有點(diǎn)不太對(duì)勁哦~
?//在此輸出只要執(zhí)行過(guò)的再次賦值的載人車輛名稱
? ? ? ? ?System.out.println(nsum1+"\t"+nsum2+"\t"+nsum3+"\t"+nsum4);
2016-06-08
厲害!