第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

自己寫(xiě)的,基礎(chǔ)知識(shí)掌握的很差,大神幫忙看看

package didizuche;

import java.util.*;


public class Test {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("歡迎使用滴滴租車(chē)系統(tǒng)"+"\n"+"您是否要租車(chē):1是 0否");

Scanner judge=new Scanner(System.in);

int a=judge.nextInt();

if(a==1){

System.out.println("您可租車(chē)的類型及價(jià)目表"+"\n"+"序號(hào)"+"\t"+"汽車(chē)名稱"+"\t"+"租金"+"\t"+"容量");

? ? ? ? ? ? Car test1=new Aodi();test1.car();

? ? ? ? ? ? Car test2=new Mazida();test2.car();

? ? ? ? ? ? Car test3=new Pikaxue();test3.car();

? ? ? ? ? ? Car test4=new Jinlong();test4.car();

? ? ? ? ? ? Car test5=new Songhuajia();test5.car();

? ? ? ? ? ? Car test6=new Yiweike();test6.car();

? ? ? ? ? ? System.out.println("請(qǐng)輸入你要租汽車(chē)的數(shù)量");

? ? ? ? ? ? Scanner amount=new Scanner(System.in);

? ? ? ? ? ? int b=amount.nextInt();

? ? ? ? ? ? int c;int allpeople=0;int allthing=0;int allprice=0;String Person=null;String Cars=null;

? ? ? ? ? ? for(int i=1;i<=b;i++){ ? ? ? ? ?

? ? ? ? ? ? do{

? ? ? ? ? ? System.out.println("請(qǐng)輸入第"+i+"輛車(chē)的序號(hào):");

? ? ? ? ? ? ? ?Scanner xuhao=new Scanner(System.in);

? ? ? ? ? ? ? ?c=xuhao.nextInt();

? ? ? ? ? ? }while(c<1||c>6);

? ? ? ? ? ? if(c==1){

? ? ? ? ? ? allpeople+=4;allthing+=0;allprice+=500;Person+="奧迪A4";

? ? ? ? ? ? }else if(c==2){

? ? ? ? ? ? allpeople+=4;allprice+=400;Person+="馬自達(dá)6";

? ? ? ? ? ? }else if(c==3){

? ? ? ? ? ? allpeople+=4;allthing+=2;allprice+=450;Person+="皮卡雪6";Cars+="皮卡雪6";

? ? ? ? ? ? }else if(c==4){

? ? ? ? ? ? allpeople+=20;;allprice+=800;Person+="金龍";

? ? ? ? ? ? }else if(c==5){

? ? ? ? ? ? allthing=4;allprice+=400;Cars+="松花江";

? ? ? ? ? ? }else{

? ? ? ? ? ? allthing+=20;allprice+=1000;Cars+="依維柯";

? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? System.out.println("請(qǐng)輸入要租的天數(shù):");

? ? ? ? ? ? Scanner days=new Scanner(System.in);

? ? ? ? ? ? int d=days.nextInt();

? ? ? ? ? ? System.out.println("你的賬單"+"\n"+"***可載人的車(chē)有:"+"\n"+Person+"\t"+"共載人:"+allpeople+"人");

? ? ? ? ? ? System.out.println("***載貨的車(chē)有:"+"\n"+Cars+"\t"+"共載貨:"+allthing+"噸");

? ? ? ? ? ? System.out.println("***租車(chē)總價(jià)格:"+allprice*d+"元");

}


? ? ? ??

}


}


正在回答

3 回答

String Person = null;?String Cars=null; ? Cars賦值null ,在拼接字符串的時(shí)候 就是 "null" ,應(yīng)該賦值為"",這樣在拼接車(chē)名字的時(shí)候不會(huì)出現(xiàn)null了;

if (c == 1) {

allpeople += 4;

allthing += 0;

allprice += 500;

Person += "奧迪A4";

}

車(chē)的屬性到成員變量了這里就不用手動(dòng)加 常量了。直接加對(duì)象的成員變量就好了;



1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

bartqq 提問(wèn)者

非常感謝!
2016-06-20 回復(fù) 有任何疑惑可以回復(fù)我~
#2

bartqq 提問(wèn)者

怎么加對(duì)象的成員變量啊。。。
2016-06-20 回復(fù) 有任何疑惑可以回復(fù)我~
#3

ybdt1201

感謝,非常感謝
2016-07-02 回復(fù) 有任何疑惑可以回復(fù)我~
import?java.util.*;

public?class?Test?{

	public?static?void?main(String[]?args)?{
		//所有車(chē)放在這里,可以根據(jù)序號(hào)取對(duì)應(yīng)的車(chē)
		List<Car>?cars?=?new?ArrayList<Car>();
		Car?aodi?=?new?Aodi();
		cars.add(aodi);
		Car?mazida?=?new?Mazida();
		cars.add(mazida);
		Car?pikaxue?=?new?Pikaxue();
		cars.add(pikaxue);
		Car?jinlong?=?new?Jinlong();
		cars.add(jinlong);
		Car?songhuajia?=?new?Songhuajia();
		cars.add(songhuajia);
		Car?yiweike?=?new?Yiweike();
		cars.add(yiweike);
		
		System.out.println("歡迎使用滴滴租車(chē)系統(tǒng)"?+?"\n"?+?"您是否要租車(chē):1是?0否");
		Scanner?judge?=?new?Scanner(System.in);
		int?a?=?judge.nextInt();
		if?(a?==?1)?{
			System.out.println("您可租車(chē)的類型及價(jià)目表"?+?"\n"?+?"序號(hào)"?+?"\t"?+?"汽車(chē)名稱"?+?"\t"?+?"租金"?+?"\t"?+?"容量");
			aodi.car(1);
			mazida.car(2);
			pikaxue.car(3);
			jinlong.car(4);
			songhuajia.car(5);
			yiweike.car(6);
????????????System.out.println("請(qǐng)輸入你要租汽車(chē)的數(shù)量");
????????????Scanner?amount=new?Scanner(System.in);
????????????int?b=amount.nextInt();
			int?c;
			int?allpeople?=?0;
			int?allthing?=?0;
			int?allprice?=?0;
			String?Person?=?"";
			String?Cars?=?"";
????????????for(int?i=1;i<=b;i++){??????????
				do?{
					System.out.println("請(qǐng)輸入第"?+?i?+?"輛車(chē)的序號(hào):");
					Scanner?xuhao?=?new?Scanner(System.in);
					c?=?xuhao.nextInt();
				}while(c<1||c>6);
				
				//根據(jù)序號(hào)在List中取相應(yīng)的車(chē)
				Car?cc?=?cars.get(c-1);
				//如果該車(chē)能裝人
				if(cc.people>0){
					allpeople+=cc.people;
					Person?+=?cc.name+"?";
				}
				//如果該車(chē)能裝貨
				if(cc.thing>0){
					allthing+=cc.thing;
					Cars?+=?cc.name+"?";
				}
				allprice?+=?cc.price;
????????????}
????????????System.out.println("請(qǐng)輸入要租的天數(shù):");
????????????Scanner?days=new?Scanner(System.in);
????????????int?d=days.nextInt();
????????????System.out.println("你的賬單"+"\n"+"***可載人的車(chē)有:"+"\n"+Person+"\t"+"共載人:"+allpeople+"人");
????????????System.out.println("***載貨的車(chē)有:"+"\n"+Cars+"\t"+"共載貨:"+allthing+"噸");
????????????System.out.println("***租車(chē)總價(jià)格:"+allprice*d+"元");
		}
	}
}
	
	class?Car{
		String?name?=?"";
		int?people?=?0;
		int?thing?=?0;
		float?price?=?0;
		
		public?void?car(int?index){
			System.out.println(index?+?"\t"?+?name?+?"\t"?+?price?+?"\t"?+?people?+?"人"?+?thing?+?"貨");
		}
	}

	class?Aodi?extends?Car{{
		name?=?"奧迪A4";
		people?=?4;
		thing?=?0;
		price?=?500;
	}}
	class?Mazida?extends?Car{{
		name?=?"馬自達(dá)6";
		people?=?4;
		thing?=?0;
		price?=?400;
	}}
	class?Pikaxue?extends?Car{{
		name?=?"皮卡雪6";
		people?=?4;
		thing?=?2;
		price?=?450;
	}}
	class?Jinlong?extends?Car{{
		name?=?"金龍";
		people?=?20;
		thing?=?0;
		price?=?800;
	}}
	class?Songhuajia?extends?Car{{
		name?=?"松花江";
		people?=?0;
		thing?=?4;
		price?=?400;
	}}
	class?Yiweike?extends?Car{{
		name?=?"依維柯";
		people?=?20;
		thing?=?0;
		price?=?1000;
	}}


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

bartqq 提問(wèn)者

哇,非常感謝啊
2016-06-21 回復(fù) 有任何疑惑可以回復(fù)我~
#2

qq_隨想之風(fēng)_03202251

List<Car> cars = new ArrayList<Car>();不太理解這個(gè)
2016-06-26 回復(fù) 有任何疑惑可以回復(fù)我~
#3

bartqq 提問(wèn)者 回復(fù) qq_隨想之風(fēng)_03202251

這個(gè)慕課沒(méi)教,不過(guò)在網(wǎng)上能搜到ArrayList的使用方法
2016-06-28 回復(fù) 有任何疑惑可以回復(fù)我~
#4

Mr夏之后 回復(fù) qq_隨想之風(fēng)_03202251

List 是一個(gè)集合框架 <car>指定一個(gè)范型 ,arraylist是List的一種常用的實(shí)現(xiàn)方式. 這里使用List 能夠很方便的存儲(chǔ)所有的Car,也能夠方便的找到需要的Car . 繼續(xù)往后面學(xué)習(xí),你就能看到 Map List 這些常用集合框架
2016-06-30 回復(fù) 有任何疑惑可以回復(fù)我~
查看1條回復(fù)

//以?shī)W迪為例

public static class Aodi extends Car {

String name = "奧迪A4"; //車(chē)的名字

int people = 4; //容納人數(shù)

int thing = 0; //容納貨物數(shù)量

float price = 500; //價(jià)格

@Override

public void car() {

System.out.println("1" + "\t" + name + "\t" + price + "\t" + people + "人" + thing + "貨");

}

}



這樣在選車(chē)的時(shí)候 ?就可以寫(xiě)成

if (c == 1) {

allpeople += ((Aodi)test1).getPeople();

allthing += ((Aodi)test1).getThing();

allprice += ((Aodi)test1).getPrice();

Person += ((Aodi)test1).getName();

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門(mén)第二季 升級(jí)版
  • 參與學(xué)習(xí)       531220    人
  • 解答問(wèn)題       6327    個(gè)

課程升級(jí)!以終為始告別枯燥,在開(kāi)發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

自己寫(xiě)的,基礎(chǔ)知識(shí)掌握的很差,大神幫忙看看

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)