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

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

u+=((Qiche)o).getram();是什么意思

一邊看一邊寫,還是不懂u+=((Qiche)o).getram();是什么意思

正在回答

2 回答

括號里的(Qiche)是類型強轉,o是他用for in遍歷car數(shù)組里面的元素,getrom就是獲取噸數(shù)的方法咯

0 回復 有任何疑惑可以回復我~

父類

public class Car {
?protected int xuhao;
?protected String name;
?protected int money;
?public Car(int xuhao,String name,int money)
?{
??this.xuhao=xuhao;
??this.name=name;
??this.money=money;
??
?}

?public void leixing() {
??
??System.out.println(xuhao+"\t"+name+"\t"+money+"元/天");
?}
}

貨車類

public class Huoche extends Car {
?private int rom;
?public Huoche(int xuhao,String name,int money,int rom)
?{
??super(xuhao,name,money);
??
??this.rom=rom;?
?}
?public void leixing(){
??
??System.out.println(xuhao+"\t"+name+"\t"+money+"元/天"+"\t"+"載貨"+rom+"噸");
?}
public int getrom(){
??
??return rom;
?}
}

汽車類

public class Qiche extends Car {
?private int ram;
?public Qiche(int xuhao,String name,int money,int ram)
?{
??super(xuhao,name,money);
?
??this.ram=ram;?
?}
?public void leixing(){
??
??System.out.println(xuhao+"\t"+name+"\t"+money+"元/天"+"\t"+"載人"+ram+"人");
?}
public int getram(){
??
??return ram;
?}

皮卡類
}

public class Pika extends Car {
?private int ram;
?private int rom;
?public Pika(int xuhao,String name,int money,int ram,int rom)
?{
??super(xuhao,name,money);
??this.ram=ram;?
??????? this.rom=rom;
?}
?public void leixing(){
??
??System.out.println(xuhao+"\t"+name+"\t"+money+"元/天"+"\t"+"載人"+ram+"載貨"+rom+"噸");
?}
public int getram(){
??
??return ram;
?}
public int getrom(){
?
?return rom;
}
}

主類

import java.util.Scanner;

public class Main {

?public static void main(String[] args) {
??
??Main kehu = new Main();
??Car[]? xinghao = new Car[6];
??xinghao[0] =new Qiche(1,"奧迪A4",500,4);
??xinghao[1] =new Qiche(2,"馬自達6",400,4);
??xinghao[2] =new Pika(3,"皮卡雪6",450,4,2);
??xinghao[3] =new Qiche(4,"金龍",800,20);
??xinghao[4] =new Huoche(5,"松花江",400,4);
??xinghao[5] =new Huoche(6,"依維柯",1000,20);
? System.out.println("歡迎使用答答租車系統(tǒng)");
? System.out.println("您是否要租車:1是"+"\t"+"2否");
????? Scanner in =new Scanner(System.in);
????? int i = in.nextInt();
????? if(i==1)
????? {
??? ? System.out.println("您可租車的類型及其價格表");
??? ? System.out.println("序號"+"\t"+"汽車名稱"+"\t"+"租金"+"\t"+"容量");
??? ?xinghao[0].leixing();
??? ?xinghao[1].leixing();
??? ?xinghao[2].leixing();
??? ?xinghao[3].leixing();
??? ?xinghao[4].leixing();
??? ?xinghao[5].leixing();
??? ?System.out.println("請選擇您要租的汽車數(shù)量");
??????? int j = in.nextInt();
?????? Car[] f = new Car[j];
????? for(int s=0;s<j;s++)
????? {
??? ?? System.out.println("請輸入第"+(s+1)+"輛車的序號:");
??? ?? int c=in.nextInt();
??? ?? f[s]=xinghao[c-1];
????? }
????? System.out.println("請輸入租車天數(shù):");
????? int d=in.nextInt();
????? int u=0;
????? System.out.println("您的賬單有:");
????? System.out.println("**********載人車有:");
????? for(Car o:f)
????? {
??? ?? if(o.xuhao==1||o.xuhao==2||o.xuhao==4)
??? ?? {
??? ??? System.out.print(o.name);
??? ??? u+=((Qiche)o).getram();
??? ???
??? ?? }else if(o.xuhao==3)
??? ?? {
??? ??? System.out.print(o.name);
??? ??? u+=((Pika)o).getram();
??? ?
??? ?? }
????? }
????? System.out.println("總載客人數(shù)"+u+"人");?
???? System.out.println("\n**********載貨車有:");
????? int h =0;
????? for(Car y:f)
????? {
??? ?? if(y.xuhao==5||y.xuhao==6)
??? ?? {
??? ??? System.out.print(y.name);
??? ??? h+=((Huoche)y).getrom();
??? ???
??? ?? }else if(y.xuhao==3)
??? ?? {
??? ??? System.out.print(y.name);
??? ?? h+=((Pika)y).getrom();
??? ?? }
??? ?
????? }? System.out.println("總載貨數(shù)"+h+"噸");
????? double qian=0;
????? for(Car e:f){
????? qian+=e.money;
????? }
????? qian=qian*d;

????? System.out.print("\n*****租車總金額:"+qian);
?}
? else
????? {
??? ?System.out.println("歡迎下次使用");
?????
????? }
?}

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531092    人
  • 解答問題       6276    個

課程升級!以終為始告別枯燥,在開發(fā)和重構中體會Java面向對象編程的奧妙

進入課程

u+=((Qiche)o).getram();是什么意思

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號