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

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

面向?qū)ο蟮牧?xí)題

package demo.faceobj;
import java.util.*;
public class test {

?? ?public static void main(String[] args) {
?? ??? ?int pSum=0;//總?cè)藬?shù)
?? ??? ?int oSum=0;//總貨物量
?? ??? ?double sumMon=0;//總金額
?? ??? ?Car[] crent={new peCar("奧迪",500,4),new peCar("馬自達(dá)",400,4),new pickCar("皮卡",450,4,2),new
?? ??? ??? ??? ?peCar("金龍",800,20),new obCar("松花江",400,4),new obCar("依維河",1000,20)};
?? ??? ?System.out.println("歡迎使用租車系統(tǒng):");
?? ??? ?System.out.println("您是否需要租車:1是 0否");
?? ??? ?Scanner input=new Scanner(System.in);
?? ??? ?int n=input.nextInt();
?? ??? ?if(n==1){
?? ??? ??? ?System.out.println("您可租車的類型及其價目表:");
?? ??? ??? ?System.out.println("序號"+"\t"+"汽車名稱"+"\t"+"租金"+"\t"+"容量");
?? ??? ??? ?for(int i=0;i<crent.length;i++){
?? ??? ??? ??? ?System.out.print(i+1+".\t");
?? ??? ??? ??? ?crent[i].print();
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?
?? ??? ??? ?System.out.println("請輸入要租車的數(shù)量:");
?? ??? ??? ?int num=input.nextInt();
?? ??? ??? ?int [] x=new int[num];//用以保存車序的數(shù)組

?? ??? ??? ?for(int i=0;i<num;i++){
?? ??? ??? ??? ?System.out.println("請輸入第"+(i+1)+"量車的序號:");
?? ??? ??? ??? ?int Cnum=input.nextInt();
?? ??? ??? ??? ?int innum=Cnum-1;
?? ??? ??? ??? ?x[i]=innum;?? ?
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?
?? ??? ??? ?System.out.println("請輸入租車天數(shù):");
?? ??? ??? ?int Day=input.nextInt();
?? ??? ??? ?
?? ??? ??? ?System.out.println("您的賬單:");
?? ??? ??? ?System.out.println("***可載人的車有:");
?? ??? ??? ?for(int i=0;i<x.length;i++){
?? ??? ??? ??? ?if(x[i]==0||x[i]==1||x[i]==2||x[i]==3){
?? ??? ??? ??? ??? ?System.out.print(crent[x[i]].name+"\t");
?? ??? ??? ??? ??? ?pSum+=crent[x[i]].pnum;
?? ??? ??? ??? ??? ?sumMon+=crent[x[i]].mon;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?System.out.println("共載人:"+pSum+"人");
?? ??? ??? ?System.out.println("***可載貨的車有:");
?? ??? ??? ?for(int i=0;i<x.length;i++){
?? ??? ??? ??? ?if(x[i]==2||x[i]==4||x[i]==5){
?? ??? ??? ??? ??? ?System.out.print(crent[x[i]].name+"\t");
?? ??? ??? ??? ??? ?oSum+=crent[x[i]].onum;
?? ??? ??? ??? ??? ?sumMon+=crent[x[i]].mon;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?for(int i=0;i<x.length;i++){
?? ??? ??? ??? ?if(x[i]==2){
?? ??? ??? ??? ??? ?sumMon=sumMon-crent[x[i]].mon;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?System.out.println("共載貨:"+oSum+"噸");
?? ??? ??? ?
?? ??? ??? ?
?? ??? ??? ?sumMon*=Day;
?? ??? ??? ?System.out.print("***租車總價格:"+sumMon);
?? ??? ??? ?
?? ??? ?}else{
?? ??? ??? ?System.out.println("退出系統(tǒng)");
?? ??? ?}
?? ?}
}

關(guān)于面向?qū)ο髢?nèi)容最后的一個習(xí)題。然后我這個代碼我覺得輸出的代碼寫的不好,有沒大神能幫忙改正一下,而且這個存在BUG,如果選的車輛序號是同一輛最后會輸出多個相同車名,如果要更改就需要增加一段代碼進(jìn)行判斷是否有重復(fù)車序,所以我希望能有更簡便的代碼有沒可以分享相互學(xué)習(xí)學(xué)習(xí),萬分感謝。

正在回答

2 回答

package demo.faceobj;

public abstract class Car {
?? ?public String name;
?? ?public int mon;
?? ?public int pnum;
?? ?public int onum;
?? ?public Car(){
?? ??? ?this.name=null;
?? ??? ?this.mon=0;
?? ??? ?this.pnum=0;
?? ??? ?this.onum=0;
?? ?}
?? ?public abstract void print();
}
***************
package demo.faceobj;

public class peCar extends Car {
?? ?public peCar(String newname,int newmon,int newpnum){
?? ??? ?this.name=newname;
?? ??? ?this.mon=newmon;
?? ??? ?this.pnum=newpnum;
?? ?}
?? ?public void print(){
?? ??? ?System.out.println(name+"\t"+mon+"元/天"+"\t"+"載人:"+pnum+"人");
?? ?}
}
*************
package demo.faceobj;

public class obCar extends Car {
?? ?public obCar(String newname,int newmon,int newonum){
?? ??? ?this.name=newname;
?? ??? ?this.mon=newmon;
?? ??? ?this.onum=newonum;
?? ?}
?? ?public void print(){
?? ??? ?System.out.println(name+"\t"+mon+"元/天"+"\t"+"載貨:"+onum+"噸");
?? ?}
}
****************

package demo.faceobj;

public class pickCar extends Car {
?? ?public pickCar(String newname,int newmon,int newpnum,int newonum){
?? ??? ?this.name=newname;
?? ??? ?this.mon=newmon;
?? ??? ?this.pnum=newpnum;
?? ??? ?this.onum=newonum;
?? ?}
?? ?public void print(){
?? ??? ?System.out.println(name+"\t"+mon+"元/天"+"\t"+"載人:"+pnum+"? 載貨:"+onum+"噸");
?? ?}
}

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

我不是大神哈,但是你能把其他幾個子class粘出來一下嗎?不然得自己編。

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

柒_夜4080291 提問者

額額,疏忽了。字?jǐn)?shù)太多不能直接回復(fù),貼在下面了。麻煩了,謝謝。
2016-11-15 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

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

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

進(jìn)入課程

面向?qū)ο蟮牧?xí)題

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

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

幫助反饋 APP下載

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

公眾號

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