开发者

Variables not being used but clearly are! - Java

So I'm getting some odd errors such as illegal start of type and variable's that are not being used when I am clearly calling them. Now I'm using the latest version of netbeans and I'm no expert at Java but I believe that my netbeans may be corrupted or something not to sure.

As far as my logic goes with these if loops everything should be ok hence the reason I'm not going to go into too much detail about what the program is being used for.

Anyway here's the code I will highlight the area's with the errors.

Thanks in Advance Regards -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;
}
}


It's because you're missing a opening bracket after the first 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;
    }


You've got a missing brace at the end of this line:

    } else if (size[2] == 'L')

As a result, the brace two lines later terminates the constructor, and the "Illegal start of type" warnings are coming because the next block of code is outside of any method. You can't have statements at class scope, of course!


} else if (size[2] == 'L')
    ChargeFinal = ChargeL;
}  // <-- move this bracket to the end of the constructor 

has an extra bracket, that is closing the constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜