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

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

我寫到這不知道咋辦,如何才能輸出載人載貨的車名 求助大佬

package?com.答答租車系統(tǒng);
import?java.util.*;
public?class?Car?{???//父類
	public?int?id;
	public?String?name;
	public?String?price;
	public?Car(int?id,String?name,String?price)?{
		this.id=id;
		this.name=name;
		this.price=price;
		System.out.print(id+"\t"+name+"\t"+price+"\t");
		}
	
	}
	
	
public?class?Huocar?extends?Car??{//?子類貨車
????public?String?zaihuo;
????public?Huocar(int?id,String?name,String?price,String?zaihuo)?{
		super(id,name,price);
		this.zaihuo=zaihuo;
		System.out.println(zaihuo+"\t");
	}
}

public?class?Kecar?extends?Car??{//子類客車
	public?String?zairen;
????public?Kecar(int?id,String?name,String?price,String?zairen)?{
	super(id,name,price);
	this.zairen=zairen;
	System.out.println(zairen+"\t");
}

}


public?class?Picar?extends?Car??{//子類皮卡
????public?String?zaihuo;	
	public?String?zairen;	
	public?Picar(int?id,String?name,String?price,String?zairen,?String?zaihuo	)?{
		super(id,name,price);
		this.zaihuo=zaihuo;
		this.zairen=zairen;
		System.out.print(zairen+"\t");
		System.out.println(zaihuo+"\t");
	}
}

public?class?Main?{
????????public?static?void?main(String[]?args)?{
		System.out.println("歡迎使用答答租車系統(tǒng)");
		System.out.println("您是否需要租車?:??1是???0否");
		Scanner?input=new?Scanner(System.in);
		int?judge1=input.nextInt();//獲取輸入值
		if(judge1==1)
		{
			System.out.println("序號\t車輛名稱\t?租車價格\t?容量\t");
			Car?car[]=?{new?Kecar(1,"奧迪A4","500元/天","載人:4人"),
			new?Kecar(2,"馬自達(dá)6","400元/天","載人:4人"),
			new?Picar(3,"皮卡雪","450元/天","載人:4人","載重:2噸"),
			new?Kecar(4,"金龍","800元/天","載人:20人"),
			new?Huocar(5,"松花江","400元/天","載重:4噸"),
			new?Huocar(6,"依維柯","1000元/天","載重:20噸")};//構(gòu)造方法輸出信息
			/*System.out.println("序號"+"\t"+"車輛名稱"+"\t"+"租車價格"+"\t"+"?容量"+"\t");
			Car?car1=new?Kecar(1,"奧迪A4","500元/天","載人:4人");
			Car?car2=new?Kecar(2,"馬自達(dá)6","400元/天","載人:4人");
			Car?car3=new?Picar(3,"皮卡雪","450元/天","載人:4人","載重:2噸");
			Car?car4=new?Kecar(4,"金龍","800元/天","載人:20人");
			Car?car5=new?Huocar(5,"松花江","400元/天","載重:4噸");
			Car?car6=new?Huocar(6,"依維柯","1000元/天","載重:20噸");*/
		}else
		{
			System.out.println("如有需要?dú)g迎您的使用,再見");
			System.exit(0);
		}
		System.out.println("請輸入您要租汽車的數(shù)量");
		int?sum=input.nextInt();
		int?s;
		String?zr[]=new?String[sum];
		int?weight=0;//計(jì)算總載重
		int?peosum=0;//計(jì)算總?cè)藬?shù)
		int?monsum=0;//計(jì)算總錢數(shù)
		for(int?i=0;i<sum;i++)?{
			System.out.println("請輸入第"+(i+1)+"輛租車的序號");
			?s=input.nextInt();??//保存各輛車
			?switch?(s)?{
			?case?1:?peosum=peosum+4;monsum=monsum+500;zr[i]="奧迪A4";continue;
			?case?2:?peosum=peosum+4;monsum=monsum+400;zr[i]="馬自達(dá)6";continue;
			?case?3:?peosum=peosum+4;monsum=monsum+450;zr[i]="皮卡雪6";weight=weight+2;continue;
			?case?4:?peosum=peosum+20;monsum=monsum+800;zr[i]="金龍";continue;
			?case?5:?monsum=monsum+400;weight=weight+4;zr[i]="松花江";continue;
			?case?6:?monsum=monsum+1000;weight=weight+20;zr[i]="依維柯";continue;
			?
			?}
					}
		System.out.println("請輸入您要租車的天數(shù)");
			int?daysum=input.nextInt();
			int?monsums=daysum*monsum;//總金額
		????
			System.out.println("您的賬單");
			System.out.println("****可載人的車有"+"\n"+"??共載人?:"+peosum);
			System.out.println("****可載貨的車有"+"\n"+"??共載貨??:"+weight+"噸");
			System.out.println("****租車總價格?:?"?+??monsums);
			System.out.println("歡迎再次使用");
			}

}


正在回答

4 回答

你所租的車的車名放在了String zr[sum]這個數(shù)組中,可以輸出zr[]這個數(shù)組中的值從而輸出車名。由于你把車分成了載人和載貨的所以要在輸出車名的同時進(jìn)行劃分,這個可以使用String中間涉及判斷語句,所以要改的話需要把最終的倒數(shù)三,四syso都改一下。

代碼部分:System.out.println("您的賬單:");

? ? ? ? ? ? ? ? ? System.out.println("****可載人的車有:");

? ? ? ? ? ? ? ? ? for(int i=0;i<sum;i++)

? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ?if(zr[i]==Car[0].name||zr[i]==Car[1].name||zr[i]==Car[2].name||zr[i]==Car[3].name)

? ? ? ? ? ? ? ? ? ? ? ?System.out.println(zr[i]);

? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ?System.out.println("\n共載人:"+peosum);

? ? ? ? ? ? ? ? ?System.out.println("****可載貨的車有:");

? ? ? ? ? ? ? ? ? for(int i=0;i<sum;i++)

? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ??if(zr[i]==Car[2].name||zr[i]==Car[4].name||zr[i]==Car[5].name)

? ? ? ? ? ? ? ? ? ??System.out.println(zr[i]);

? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ?System.out.println("\n共載貨:"+weight+"噸");

直接寫的,沒有用編譯器,可能存在一些細(xì)節(jié)問題,思路是這樣的。這是最直接的方法,但是個人不推薦這樣做,比較String變量不如比較int變量。

比較int變量的思路:zr數(shù)組改為int數(shù)組,switch循環(huán)中將車子的序號存進(jìn)zr數(shù)組中,或者刪除這一步在輸入租車序號后將序號存進(jìn)zr數(shù)組中,之后使用if語句和Car數(shù)組中id屬性比較,相等的話輸出Car數(shù)組中的name屬性(也就是車名)。

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

qq_枯笑_0 提問者

謝謝大神,我也看過一些慕友的代碼,每次看到 if ( * instanceof *)這個用判斷類型這里我就看不懂了
2017-08-06 回復(fù) 有任何疑惑可以回復(fù)我~
#2

qq_枯笑_0 提問者

再次感謝大神,我在這個問題都糾結(jié)一天了,感覺瞬間豁然開朗
2017-08-06 回復(fù) 有任何疑惑可以回復(fù)我~
#3

qq_枯笑_0 提問者

我還有個問題請教下,就是按照這樣寫輸出來就可能包含兩個相同的名字,如果我租的車都是一樣的,那最后結(jié)果就會出現(xiàn)重復(fù)
2017-08-07 回復(fù) 有任何疑惑可以回復(fù)我~

應(yīng)用List

CarProperty.java//父類

package zuchexitong;


public class CarProperty {

public String carName;//車輛名稱

public String carType;//車輛類型

public int carZaiKe;//載客量

public int carZaiHuo;//載貨量

public int carZuJin;//每天租金

public CarProperty(){

}

//構(gòu)造方法

public CarProperty(String carN,String carT,int carZk,int carZh,int carZj){

carName=carN;

carType=carT;

carZaiKe=carZk;

carZaiHuo=carZh;

carZuJin=carZj;

}

}

HuoChe.java//子類

package zuchexitong;


public class HuoChe extends CarProperty{


}

KeChe.java//子類

package zuchexitong;


public class KeChe extends CarProperty{



}

PiKar.java//子類

package zuchexitong;


public class PiKar extends CarProperty{

}

Test//測試類


package zuchexitong;


import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Scanner;


import com.CarProperty;


import test.Course;

/**

?* 應(yīng)用了list的方法調(diào)用

?* 需要添加的有List的變量

?* 定義泛型

?* 構(gòu)造類的構(gòu)造器

?* 添加testAdd方法

?* 添加testForEach方法

?* @author Administrator

?*

?*/

public class Test2 {

public List<CarProperty> carProperties;

public Test2(){//構(gòu)造器

carProperties=new ArrayList<CarProperty>();

}

public void testAdd(){

CarProperty[] cars={new CarProperty("1,奧迪", "貨車", 2, 3, 100),new CarProperty("2,大眾", "貨車", 2, 2, 80),

new CarProperty("3,寶馬", "客車", 4, 0, 150),new CarProperty("4,一汽", "客車", 4, 0, 100),

new CarProperty("5,五菱", "兩用", 8, 2, 250),new CarProperty("6,奔馳", "兩用", 2, 3, 160)};

carProperties.addAll(Arrays.asList(cars));

CarProperty temp=(CarProperty)carProperties.get(0);

CarProperty temp2=(CarProperty)carProperties.get(0);

CarProperty temp3=(CarProperty)carProperties.get(2);

CarProperty temp4=(CarProperty)carProperties.get(3);

CarProperty temp5=(CarProperty)carProperties.get(2);

CarProperty temp6=(CarProperty)carProperties.get(3);

}

public void testForEach(){

for(Object obj:carProperties){

CarProperty cr=(CarProperty)obj;

System.out.println("課程:"+cr.carName+"\t"+cr.carType+"\t"+

cr.carZaiHuo+"\t"+cr.carZaiKe+"\t"+cr.carZuJin);

}

}

public static void main(String[] args) {

Test2 t2=new Test2();


int sum=0;

System.out.println("請選擇是否租車?(1,是 ? 2,否):");

Scanner input=new Scanner(System.in);

int zchy=input.nextInt();

if (zchy==1) {

System.out.println("車輛名稱\t車輛類型\t載客量/人\t載貨量/噸\t租金/每天");

t2.testAdd();

t2.testForEach();

System.out.println("請選擇租車數(shù)量:");

Scanner input2=new Scanner(System.in);

int zcsl=input2.nextInt();

for (int i = 1; i < zcsl+1; i++) {

System.out.println("請輸入要租用的第幾輛車的編號:");

Scanner input3=new Scanner(System.in);

int zcbh=input3.nextInt();

switch (zcbh) {

case 1:

sum+=100;

break;

case 2:

sum+=80;

break;

case 3:

sum+=150;

break;

case 4:

sum+=100;

break;

case 5:

sum+=250;

break;

case 6:

sum+=160;

break;


default:

System.out.println("輸入錯誤,請重新輸入!");

break;

}

System.out.println("請輸入租用天數(shù):");

Scanner input4=new Scanner(System.in);

int zcts=input4.nextInt();

sum=sum*zcts;

System.out.println("總租車輛數(shù):"+zcsl+"輛\t租用天數(shù):"+zcts+"天\t總金額:¥"+sum);

}

}

}

}



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

在比較String變量的過程中最好使用equals(); 函數(shù)

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

你想輸出哪種形式的呢?如果想單純的想輸出租的車的名字可以的話可以將zr[]數(shù)值中的值先進(jìn)行處理,剔除相同的值。然后再進(jìn)入for循環(huán)輸出。

剔除方法:將zr[]數(shù)組中的值依次與之后的值相比較,相同的時候?qū)r[]當(dāng)前值賦值為空,然后之后的數(shù)組序號前移。

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

qq_枯笑_0 提問者

我這樣寫出來,有一個問題運(yùn)行會出現(xiàn)一堆哈希碼
2017-08-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

我寫到這不知道咋辦,如何才能輸出載人載貨的車名 求助大佬

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

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

幫助反饋 APP下載

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

公眾號

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