Need Help with an "illegal start of expression"

2 replies on 1 page. Most recent reply: Nov 10, 2003 10:32 PM by Birendar S Waldiya

 Previous Topic Next Topic
 Flat View: This topic has 2 replies on 1 page
 Eric Posts: 1 Nickname: narush Registered: Nov, 2003
Need Help with an "illegal start of expression" Posted: Nov 10, 2003 12:00 PM
I am in the first few weeks of a beginners java course.

I have written a class that will call the class that I am having the problem with. I keep getting these "illegal start of expression" error and cant get rid of them without commenting them out.

Any assistance would be great.

TIA,
Eric

Sorry I couldnt get the curly braces to line up to aid the readablity factor on this forum, any suggessions?

`// Program written by: Eric R.// Date program written: 11/06/03// Program Name: Calculatepublic class Calculate{ //attibutes double hrRate = 5.00; double otRate; double regPay; long hrWork; float otWork; float totalHours; double otPay; double totalPay; long Amin; //constructor public Calculate (long Amin){ this.Amin = Amin; } // methods public double getPay(){ return this.totalPay; } public void setPay(long Amin){ this.totalPay = Amin; } public long getAmin(){ return this.Amin; } { { hrWork = (Amin / 60); } public static final NumberFormat getCurrencyInstance() if(hrWork < 8) { regPay = hrWork * hrRate; otPay = 0.00; } else if(hrWork > 8) { regPay = 8 * hrRate; otPay = (hrWork - 8) * 1.5 * hrRate; } else if(hrWork < .15) { System.out.println("You worked 0 hours therefore you earned 0 pay "); System.exit(0); } //totalPay = (regPay + otPay); //System.out.println("Total Pay: " + this.totalPay + " dollars"); /* public void display() { System.out.println("Total Pay: " + this.totalPay + " dollars"); System.out.println(" "); }*/ }}`

 Kishori Sharan Posts: 211 Nickname: kishori Registered: Feb, 2002
Re: Need Help with an "illegal start of expression" Posted: Nov 10, 2003 12:21 PM
I have cleaned the code so that you don't have extra braces. This code compiles fine. I have made getCurrencyInstance() method non-static because you are using some instance variables inside. I don't know what you are trying to do. So, just go through your logic again and compile it after every change so that you know which code is giving you problem.
```// Program written by: Eric R.
// Date program written: 11/06/03
// Program Name: Calculate

import java.text.*;

public class Calculate {

//attibutes
double hrRate = 5.00;
double otRate;
double regPay;
long hrWork;
float otWork;
float totalHours;
double otPay;
double totalPay;
long Amin;

//constructor
public Calculate (long Amin){
this.Amin = Amin;
}

// methods
public double getPay(){
return this.totalPay;
}

public void setPay(long Amin){
this.totalPay = Amin;
}

public long getAmin(){
return this.Amin;

}

public final NumberFormat getCurrencyInstance( ) {

if(hrWork < 8)	{
regPay = hrWork * hrRate;
otPay = 0.00;
}
else if(hrWork > 8)	{
regPay = 8 * hrRate;
otPay = (hrWork - 8) * 1.5 * hrRate;
}
else if(hrWork < .15) {
System.out.println("You worked 0 hours therefore you earned 0 pay ");
System.exit(0);
}
// You need to return what you intended to return here
// I have just returned null so that the code compiles fine
return null;
}
}

```

 Birendar S Waldiya Posts: 21 Nickname: ebiren Registered: Nov, 2003
Re: Need Help with an "illegal start of expression" Posted: Nov 10, 2003 10:32 PM
> I am in the first few weeks of a beginners java course.
>
> I have written a class that will call the class that I am
> having the problem with. I keep getting these "illegal
> start of expression" error and cant get rid of them
> without commenting them out.
>
> Any assistance would be great.
>
> TIA,
> Eric
>
> Sorry I couldnt get the curly braces to line up to aid the
> readablity factor on this forum, any suggessions?
>
>
```>
> // Program written by: Eric R.
> // Date program written: 11/06/03
> // Program Name: Calculate
>
> public class Calculate
> {
>
> //attibutes
> double hrRate = 5.00;
> double otRate;
> double regPay;
> long hrWork;
> float otWork;
> float totalHours;
> double otPay;
> double totalPay;
> long Amin;
>
> //constructor
> public Calculate (long Amin){
> this.Amin = Amin;
> }
>
> // methods
> public double getPay(){
> return this.totalPay;
> }
> public void setPay(long Amin){
> this.totalPay = Amin;
> }
> public long getAmin(){
> return this.Amin;
> }
>
> {
> {
> hrWork = (Amin / 60);
> }
>
> public static final NumberFormat getCurrencyInstance()
>
> if(hrWork < 8)
> {
> regPay = hrWork * hrRate;
> otPay = 0.00;
> }
> else if(hrWork > 8)
> {
> regPay = 8 * hrRate;
> otPay = (hrWork - 8) * 1.5 * hrRate;
> }
> else if(hrWork < .15)
> {
> System.out.println("You worked 0 hours therefore you
> u earned 0 pay ");
> System.exit(0);
> }
>
> //totalPay = (regPay + otPay);
> //System.out.println("Total Pay: " + this.totalPay + "
> + " dollars");
>
> /*	public void display() {
> System.out.println("Total Pay: " + this.totalPay + "
> " dollars");
> System.out.println(" ");
> }*/
> }
> }
>
```

Can you please properly match the bracket and braces ..
and use the Formating guide lines ginev in this site
ie use
```
```
tag and put your code inside this tag..

 Flat View: This topic has 2 replies on 1 page
 Previous Topic Next Topic