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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復(fù)創(chuàng)建對象時的“錯誤:找不到符號”?

如何修復(fù)創(chuàng)建對象時的“錯誤:找不到符號”?

Qyouu 2022-09-07 16:29:15
我不明白為什么我的編譯器找不到類,考慮到我不是已經(jīng)在我的方法中做到了嗎?編譯器指向以下行:Weightpublic boolean checkWeight`Weight first = new Weight();`和`Weight second = new Weight();`public class Guard {    int stashWeight;    public Guard ( int maxWeight ) {        this.stashWeight = maxWeight;    }    public boolean checkWeight (Weight maxWeight) {        if ( maxWeight.weight >= stashWeight ) {            return true;        } else {            return false;        }    }    public static void main (String[] args ) {        Weight first = new Weight();        first.weight = 3000;        Weight second = new Weight();        second.weight = 120;        Guard grams = new Guard(450);        System.out.println("Officer, can I come in?");        boolean canFirstManGo = grams.checkWeight(first);        System.out.println(canFirstManGo);        System.out.println();        System.out.println("Officer, how about me?");        boolean canSecondManGo = grams.checkWeight(second);        System.out.println(canSecondManGo);    }}
查看完整描述

3 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗 獲得超4個贊

  1. 方法參數(shù)“maxWeight”的類型為“Weight”,Java無法找到解析程序依賴關(guān)系的定義。未能通過類路徑找到類將導(dǎo)致錯誤“找不到符號”。您可能希望定義類“Weight”并將其導(dǎo)入,就像其他人對您所做的那樣。

  2. 你真的需要“重量”類嗎?您只是將通過的論點與“警衛(wèi)”的stashWeight進(jìn)行比較。

您的公共方法可以簡單地是:


public boolean checkWeight(int maxWeight) {

        return maxWeight >= stashWeight;

}


主方法可以更新為:


public static void main(String[] args) {

    int firstWeight = 3000;

    int secondWeight = 120;


    Guard grams = new Guard(450);

    System.out.println("Officer, can I come in?");

    boolean canFirstManGo = grams.checkWeight(firstWeight);

    System.out.println(canFirstManGo);


    System.out.println();


    System.out.println("Officer, how about me?");

    boolean canSecondManGo = grams.checkWeight(secondWeight);

    System.out.println(canSecondManGo);


}


查看完整回答
反對 回復(fù) 2022-09-07
?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗 獲得超10個贊

您的代碼中缺少權(quán)重類 請參閱以下代碼


class Weight {


    public int weight;


    public int getWeight() {

        return weight;

    }


    public void setWeight(int weight) {

        this.weight = weight;

    }

}


public class Guard {


    int stashWeight;


    public Guard(int maxWeight) {

        this.stashWeight = maxWeight;

    }


    public boolean checkWeight(Weight maxWeight) {

        if (maxWeight.weight >= stashWeight) {

            return true;

        } else {

            return false;

        }

    }


    public static void main(String[] args) {

        Weight first = new Weight();

        first.weight = 3000;

        Weight second = new Weight();

        second.weight = 120;


        Guard grams = new Guard(450);

        System.out.println("Officer, can I come in?");

        boolean canFirstManGo = grams.checkWeight(first);

        System.out.println(canFirstManGo);


        System.out.println();


        System.out.println("Officer, how about me?");

        boolean canSecondManGo = grams.checkWeight(second);

        System.out.println(canSecondManGo);


    }

}

輸出


**


Officer, can I come in?

true

Officer, how about me?

false

**


查看完整回答
反對 回復(fù) 2022-09-07
?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗 獲得超3個贊

你應(yīng)該像這樣定義類:Weight


public class Weight {


    public int weight;


    public int getWeight() {

        return weight;

    }


    public void setWeight(int weight) {

        this.weight = weight;

    }

}

輸出:


Officer, can I come in?

true


Officer, how about me?

false

或者使用關(guān)鍵字導(dǎo)入您的類。Weightimport


查看完整回答
反對 回復(fù) 2022-09-07
  • 3 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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