In need of help urgently please!!

NOBEL

Member
Aug 2, 2000
51
0
0
The code below has one error, mind you I am not good at programming, so it is very frustrating sitting in front of the PC for 1.5 hours and can't get anything done.

Here is the error message
'class' or 'interface' expected
public void payday()


It would really help if some one could help me out (this is part of the full code, the full code is attached)





public class Staff
{
private StaffMember[] sMember;
public Staff()
{
sMember=new StaffMember[2];

Hourly t1= new Hourly ("Sam","123 Main Line","555-4569","425-652-124",9.5,0);
sMember[0]=t1;

Employee e =new Employee("Carla","456 Main Line","555-0789","123-456-786",6.5);
sMember[1]=e;

Hourly t2= new Hourly("Rob","998 Main Line","567-7754","542-326-586",8.55,2.0);
sMember[2]=t2;
}

}

public void payday()
{
double amount =0.0;
for (int i=0; i<3;i++)
{
System.out.println(sMember);
amount=sMember.pay();
if(amount==0)
System.out.println("Thanks \n");
else
System.out.println("Paid: "+amount+"\n");
System.out.println("---------------------------------------------------");
}
}
 

DT4K

Diamond Member
Jan 21, 2002
6,944
3
81
Looks like your braces are messed up so Public Void Payday() is defined outside of the class definition.

Try this instead:


public class Staff
{
private StaffMember[] sMember;
public Staff()
{
sMember=new StaffMember[2];

Hourly t1= new Hourly ("Sam","123 Main Line","555-4569","425-652-124",9.5,0);
sMember[0]=t1;

Employee e =new Employee("Carla","456 Main Line","555-0789","123-456-786",6.5);
sMember[1]=e;

Hourly t2= new Hourly("Rob","998 Main Line","567-7754","542-326-586",8.55,2.0);
sMember[2]=t2;
}

public void payday()
{
double amount =0.0;
for (int i=0; i<3;i++)
{
System.out.println(sMember);
amount=sMember.pay();
if(amount==0)
System.out.println("Thanks \n");
else
System.out.println("Paid: "+amount+"\n");
System.out.println("---------------------------------------------------");
}
}
}


EDIT: If that turns out to be the problem, don't feel bad. I spent almost an hour last night trying to figure out why my C++ code was throwing like 22 compile errors. Turns out I accidentally typed a closing brace instead of an opening brace. Somehow my eye never caught it.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Jeez, you guys need to learn to use some decent IDEs that tell you your syntax errors before you compile.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Or even one that does syntax highlighting and a brace matcher-thing, like vim.
 

DT4K

Diamond Member
Jan 21, 2002
6,944
3
81
I'm using Visual Studio 6.0 for my C++ class. Any suggestions on better ones?
I started with Dev C++ but one of the assignments required stopping at various stages of the compiling and linking process and looking at the output. Apparently, Dev C++ can't do that.