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

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

我是小白,參考別人自己寫的,求更簡潔的

package?ZhuCheXiTong;
?//定義抽象車的父類
?public?abstract?class?Car?{??
??public?int?id;???????????//定義車輛序號??
??public?String?name;??????//車輛的名稱???
??public?double?price;?????//定義價格???
??public?int?busload;??????//載客量???
??public?int?weigth;???????//載重量
??public?int?getId()?{????????//封裝對象	
????????return?id;
??}
??public?void?setId(int?id)?{
??	this.id?=?id;
??}
??public?String?getName()?{	
????????return?name;
??}
??public?void?setName(String?name)?{
??	this.name?=?name;
??}
??public?double?getPrice()?{
??	return?price;
??}
??public?void?setPrice(double?price)?{	
????????this.price?=?price;
??}
??public?int?getBusload()?{
??	return?busload;
??}
??public?void?setBusload(int?busload)?{	
????????this.busload?=?busload;
??}
??public?int?getWeigth()?{	
????????return?weigth;
??}
??public?void?setWeigth(int?weigth)?{
??	this.weigth?=?weigth;
??}
??public?Car(){??????????????????//無參構(gòu)造	
????}?
??public?Car(int?id,String?name,double?price,int?busload,int?weigth){	?
????this.id=id;??	???
????this.name=name;??????????????//有參構(gòu)造	??
????this.price=price;	???
????this.busload=busload;	??
????this.weigth=weigth;
?????}???
??public?abtract?void?show();??????//定義抽象方法}
?????//定義可以載人的車
??class?Busload?extends?Car{	
??public?Busload(){		//無參構(gòu)造	}	
??public?Busload(int?id,String?name,double?price,int?busload){
??//?super();		
??this.id=id;??		
??this.name=name;		
??this.price=price;		
??this.busload=busload;	
??}	
??public?void?show(){		
??System.out.println(id+"\t"+name+"\t"+price+"元/天??"+"\t載人:"+busload+"人");	
??}
??}
??//定義可以載貨的車
??class?Weigth?extends?Car{	
??public?Weigth(){			}	
??public?Weigth(int?id,String?name,double?price,int?weigth){
??//		super();		
?????this.id=id;		
?????this.name=name;		
?????this.price=price;		
?????this.weigth=weigth;	
??}	
??public?void?show(){		
??System.out.println(id+"\t"+name+"\t"+price+"元/天??"+"\t載貨:"+weigth+"噸");	
??}
??}
??//定義即可載人也可以載貨
??class?Pick?extends?Car{	
??public?Pick(){			}	
??public?Pick(int?id,String?name,double?price,int?busload,int?weigth){		
??super(id,name,price,busload,weigth);?????//直接使用父類的變量
??//		this.id=id;
??//		this.name=name;
??//		this.price=price;???????
??//		this.busload=busload;
??//		this.weigth=weigth;	
??}	
??public?void?show(){		
??System.out.println(id+"\t"+name+"\t"+price+"元/天??"+"\t載人:"+busload+"人"+",載貨:"+weigth+"噸");	
??}
??}
??
??package?ZhuCheXiTong;
??import?java.util.Scanner;
??//測試租車系統(tǒng)
??public?class?Test?{	
??public?static?void?main(String[]?args)?{		
??//?TODO?Auto-generated?method?stub??????
??Car[]?car=????	?
???{????		?
???new?Busload(1,"奧迪A4",500,4),????		
???new?Busload(2,"馬自達",400,4),????		
???new?Pick(3,"皮卡雪",450,4,2),????		?
???new?Busload(4,"金龍",800,20),????		?
???new?Weigth(5,"松花江",400,4),????		?
???new?Weigth(6,"依維柯",1000,20),??????????
???};????????
???double?sumprice=0;????????
???int?sumbusload=0;????????
???int?sumweigth=0;????????
???Scanner?in=new?Scanner(System.in);????????
???System.out.println("歡迎使用嗒嗒租車系統(tǒng):\n你是否要租車:1-是???0-否");????????
???int?number=in.nextInt();????????
???if(number==1){????????
???System.out.println("可供選擇的車型有:");????????
???System.out.println("序號\t汽車名稱\t租金\t\t容量");???????
????for(Car?cr:car){????????	
????cr.show();?????//遍歷所有的車情況???????
????}????????????
????System.out.println("請你輸入要租汽車的數(shù)量:");???????
????int?num=in.nextInt();????????
????int?flag;??
????int?ID[]=new?int[num];??//用于存儲車的序號??????
????for(int?i=0;i<num;i++){????????	
????System.out.println("請輸入第"+(i+1)+"個車輛的序號:");????????????
????flag=in.nextInt();????????	
????if(flag>6||flag<0){???????????????????????
??????//防止出入超出車序號的車????????		
????System.out.println("你輸入的車序號有誤!");??????????????????		
????System.out.println("請輸入第"+(i+1)+"個車輛的序號:");????????????	
????flag=in.nextInt();????????	
????}????????	???????	?
????sumprice=sumprice+car[flag-1].price;??????//選了多少輛計算每輛車和的價錢???
????ID[i]=flag;???????//獲取要的車序號????
????}????????
????System.out.println("請你輸入要租汽車的天數(shù):");????????
????int?ff=in.nextInt();????????
????System.out.println("統(tǒng)計完成正在生成你的賬單\n你的賬單如下:\n***可載人的車有***");????????
????for(int?i=0;i<num;i++){????????	
????if(car[ID[i]-1].busload!=0){????????		
????sumbusload=sumbusload+car[ID[i]-1].busload;??????//計算能載多少人????????		
????System.out.print("\t"+car[ID[i]-1].name);????????
????	}????????
????	}????????
????System.out.println("\t\t共載"+sumbusload+"人");???????
????System.out.println("***可載貨的車有***");???????
?????for(int?i=0;i<num;i++){????????	
?????if(car[ID[i]-1].weigth!=0){???????//判斷只要是載貨不為0就可以載貨????????		
?????sumweigth=sumweigth+car[ID[i]-1].weigth;????????//計算能載多少貨????????		
?????System.out.print("\t"+car[ID[i]-1].name);????????	
?????}???????
??????}???????
???????System.out.println("\t\t共載"+sumweigth+"噸");????????????????
???????System.out.println("***租出車總價格為:"+sumprice*ff);???????
???????}????????
???????else{????????	
???????System.out.println("退出系統(tǒng)!希望你下次能用租車系統(tǒng)!");???????
????????}	
????????}??
???????????}


正在回答

5 回答

package com.imooc;

import com.imooc.Car;



import java.util.Scanner;


public class Home {


? //測試租車系統(tǒng)?

? public static void main(String[] args) {? ? ??

? // TODO Auto-generated method stub? ? ??

? Car[] car=? ? ??

? ?{? ? ? ? ??

? ?new Busload(1,"奧迪A4",500,4),? ? ? ??

? ?new Busload(2,"馬自達",400,4),? ? ? ? ?

? ?new Pick(3,"皮卡雪",450,4,2),? ? ? ? ? ??

? ?new Busload(4,"金龍",800,20),? ? ? ? ? ?

? ?new Weigth(5,"松花江",400,4),? ? ? ? ? ??

? ?new Weigth(6,"依維柯",1000,20),? ? ? ? ??

? ?};??

?

? ?double sumprice=0;? ? ? ??

? ?int sumbusload=0;? ? ? ??

? ?int sumweigth=0;? ? ? ??

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

? ?System.out.println("歡迎使用嗒嗒租車系統(tǒng):\n你是否要租車:1-是? ?0-否");? ? ? ??

? ?int number=in.nextInt();? ? ? ??

? ?if(number==1){? ? ? ??

? ?System.out.println("可供選擇的車型有:");? ? ? ??

? ?System.out.println("序號\t汽車名稱\t租金\t\t容量");? ? ? ?

? ? for(Car cr:car){? ? ? ? ??

? ? cr.show();? ? ?//遍歷所有的車情況? ? ? ?

? ? }? ? ? ? ? ??

? ? System.out.pr


intln("請你輸入要租汽車的數(shù)量:");? ? ? ?

? ? int num=in.nextInt();? ? ? ??

? ? int flag;??

? ? int ID[]=new int[num];? //用于存儲車的序號? ? ??

? ? for(int i=0;i<num;i++){? ? ? ??

? ? System.out.println("請輸入第"+(i+1)+"個車輛的序號:");? ? ? ? ? ??

? ? flag=in.nextInt();? ? ? ? ?

? ? if(flag>6||flag<0){? ? ? ? ? ? ? ? ? ? ? ?

? ? ? //防止出入超出車序號的車? ? ? ? ? ? ??

? ? System.out.println("你輸入的車序號有誤!");? ? ? ? ? ? ? ? ? ? ? ??

? ? System.out.println("請輸入第"+(i+1)+"個車輛的序號:");? ? ? ? ? ??

? ? flag=in.nextInt();? ? ? ? ?

? ? }? ? ? ? ? ? ? ? ? ? ?

? ? sumprice=sumprice+car[flag-1].price;? ? ? //選了多少輛計算每輛車和的價錢? ?

? ? ID[i]=flag;? ? ? ?//獲取要的車序號? ??

? ? }? ? ? ??

? ? System.out.println("請你輸入要租汽車的天數(shù):");? ? ? ??

? ? int ff=in.nextInt();? ? ? ??

? ? System.out.println("統(tǒng)計完成正在生成你的賬單\n你的賬單如下:\n***可載人的車有***");? ? ? ??

? ? for(int i=0;i<num;i++){? ? ? ??

? ? if(car[ID[i]-1].busload!=0){? ? ? ? ? ? ? ?

? ? sumbusload=sumbusload+car[ID[i]-1].busload;? ? ? //計算能載多少人? ? ? ? ? ? ? ?

? ? System.out.print("\t"+car[ID[i]-1].name);? ? ? ??

? ? ? ? }? ? ? ??

? ? ? ? }? ? ? ??

? ? System.out.println("\t\t共載"+sumbusload+"人");? ? ? ?

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

? ? ?for(int i=0;i<num;i++){? ? ? ? ??

? ? ?if(car[ID[i]-1].weigth!=0){? ? ? ?//判斷只要是載貨不為0就可以載貨? ? ? ? ? ? ? ?

? ? ?sumweigth=sumweigth+car[ID[i]-1].weigth;? ? ? ? //計算能載多少貨? ? ? ? ? ??

? ? ?System.out.print("\t"+car[ID[i]-1].name);? ? ? ??

? ? ?}? ? ? ?

? ? ? }? ? ? ?

? ? ? ?System.out.println("\t\t共載"+sumweigth+"噸");? ? ? ? ? ? ? ??

? ? ? ?System.out.println("***租出車總價格為:"+sumprice*ff);? ? ? ?

? ? ? ?}? ? ? ??

? ? ? ?else{? ? ? ??

? ? ? ?System.out.println("退出系統(tǒng)!希望你下次能用租車系統(tǒng)!");? ? ? ?

? ? ? ? }??

? ? ? ? }??

? ? ? ? ? ?}



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

LMH300913

為什么我的程序報錯 Busload cannot be resolved to a type Weigth cannot be resolved to a type
2019-08-16 回復(fù) 有任何疑惑可以回復(fù)我~
#2

LMH300913

把子類單獨建class文件放進去就不報錯了 和父類寫在一起就報錯
2019-08-16 回復(fù) 有任何疑惑可以回復(fù)我~

https://img1.sycdn.imooc.com//5d327df20001727304680196.jpg請問這一段是匿名內(nèi)部類嗎?

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

請問這里面的無參構(gòu)造方法的作用是什么?

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

qq_慕標(biāo)3598189

如果你的子類中構(gòu)造函方法,沒有使用super來繼承父類,那么你需要在父類中寫一個無參構(gòu)造方法。因為子類會自動調(diào)用父類的構(gòu)造方法。如果你在子類中用super來繼承,而且不是自動繼承,那么你就不需要再父類中寫一個無參構(gòu)造方法。
2019-07-21 回復(fù) 有任何疑惑可以回復(fù)我~

private被繼承到子類后是無效的,子類可以進行修改使用

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

car類里面的屬性用private會比較好(java封裝的特性)

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

廖____

說錯了,private被繼承過去后子類沒法使用
2019-07-18 回復(fù) 有任何疑惑可以回復(fù)我~
#2

廖____

但是用public感覺就不用get和set方法,好像多此一舉。個人理解不知道對不對
2019-07-18 回復(fù) 有任何疑惑可以回復(fù)我~
#3

學(xué)飛奮斗的小鳥 提問者 回復(fù) 廖____

是的,這只是為了使用熟悉一下封裝,其實是可以不寫的
2019-07-18 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

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

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

進入課程

我是小白,參考別人自己寫的,求更簡潔的

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

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

幫助反饋 APP下載

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

公眾號

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