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

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

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

package didizuche;

import java.util.*;


public class Test {


public static void main(String[] args) {

// TODO Auto-generated method stub

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

Scanner judge=new Scanner(System.in);

int a=judge.nextInt();

if(a==1){

System.out.println("您可租車的類型及價目表"+"\n"+"序號"+"\t"+"汽車名稱"+"\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("請輸入你要租汽車的數(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("請輸入第"+i+"輛車的序號:");

? ? ? ? ? ? ? ?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+="馬自達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("請輸入要租的天數(shù):");

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

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

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

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

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

}


? ? ? ??

}


}


正在回答

3 回答

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

if (c == 1) {

allpeople += 4;

allthing += 0;

allprice += 500;

Person += "奧迪A4";

}

車的屬性到成員變量了這里就不用手動加 常量了。直接加對象的成員變量就好了;



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

bartqq 提問者

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

bartqq 提問者

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

ybdt1201

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

public?class?Test?{

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

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

qq_隨想之風(fēng)_03202251

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

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

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

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

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

//以奧迪為例

public static class Aodi extends Car {

String name = "奧迪A4"; //車的名字

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

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

float price = 500; //價格

@Override

public void car() {

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

}

}



這樣在選車的時候 ?就可以寫成

if (c == 1) {

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

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

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

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

}


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

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學(xué)習(xí)       531100    人
  • 解答問題       6280    個

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

進入課程

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

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

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

幫助反饋 APP下載

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

公眾號

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