gpt4 book ai didi

java - 变量没有被使用,但显然是! - java

转载 作者:行者123 更新时间:2023-11-29 07:19:48 25 4
gpt4 key购买 nike

所以我遇到了一些奇怪的错误,例如类型的非法开始和在我明确调用它们时未使用的变量。现在我正在使用最新版本的 netbeans,我不是 Java 专家,但我相信我的 netbeans 可能已损坏或不确定。

就我的逻辑而言,这些 if 循环应该一切正常,因此我不打算详细介绍该程序的用途。

无论如何,这是我将突出显示错误区域的代码。

提前致谢 -Skeng-

import javax.swing.*;
import java.io.*;

public class Envelope extends Parcel {

protected char[] size = {'S','M','L'};

public Envelope(){

ImageIcon imageES = new ImageIcon ("..\\Images\\envelope-small.png");
ImageIcon imageEM = new ImageIcon ("..\\Images\\envelope-medium.png");
ImageIcon imageEL = new ImageIcon ("..\\Images\\envelope-large.png");


double ChargeS = 4.50;
double ChargeM = 8.50;
double ChargeL = 16.99;
double ChargeFinal = 0; **//Variable not being used**

if (size[0] == 'S') {
ChargeFinal = ChargeS;
} else if (size[1] == 'M') {
ChargeFinal = ChargeM;
} else if (size[2] == 'L')
ChargeFinal = ChargeL;
}

int zone = 0; //Zone will equal whatever the user selects for their parcel size
double zonecharge; //ZoneCharge will be the price depending on the zone


if (zone == 1) { **//Illegal Start of Type**
zonecharge = 0; **//Illegal Start of Type**
} else if (zone == 2) { **//Illegal Start of Type**
zonecharge = 1.5; **//Illegal Start of Type**
} else if (zone == 3) { **//Illegal Start of Type**
zonecharge = 2; **//Illegal Start of Type**
}

double EndPrice = ChargeFinal * zonecharge; **//Cannot find Symbol "ChargeFinal"**
System.out.println("Charge: £" + EndPrice); **//Illegal Start of Type**


@Override
public String toString() {
return "ID: " + idNum + "Zone: " + zone + "Charge: " + charge + "Size: " + size;
}

@Override
ImageIcon getImage() {
return image;
}
}

最佳答案

这是因为您在第一个 else if

之后缺少左括号
if (size[0] == 'S') {
ChargeFinal = ChargeS;
} else if (size[1] == 'M') {
ChargeFinal = ChargeM;
} else if (size[2] == 'L') { // ADD THIS BRACKET
ChargeFinal = ChargeL;
}

关于java - 变量没有被使用,但显然是! - java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com