The Artima Developer Community
Sponsored Link

Java Answers Forum
Need Help with an "illegal start of expression"

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

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
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 3:00 PM
Reply to this message Reply
Advertisement
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 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 3:21 PM
Reply to this message Reply
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 11, 2003 1:32 AM
Reply to this message Reply
> 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
Topic: Can't access protected members of base class Previous Topic   Next Topic Topic: Packet Sniffing


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us