9 Replies - 16509 Views - Last Post: 14 November 2008 - 10:56 PM Rate Topic: -----

#1 buckfan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-February 08

employee class assignment

Posted 20 March 2008 - 02:03 PM

I'm getting errors in the following code when I compile and I can't figure out how to fix it. Any help is appreciated.
[code]//java
class Employee
{
String name;
String id;
double salary;
int age;
String position;
void display()
{
System.out.println("Employee Name:"+Jack);
System.out.println("Employee Id:"+id);
System.out.printf("Salary:$%.2f\n",60000);
System.out.println("Employee Age:"+43);
System.out.println("Employee Position:"+trashman);
}
double getFedTax(double salary)
{
double fedTax=(salary-800)*.17;
return fedTax;
}
int getSsTax(int rate,double salary)
{
double ssTax = salary*(rate/100);
return ssTax;
}
int getHealthFee(int rate,double salary)
{
double healthFee = (rate/100)*salary;
return healthFee;
}
int getInsurance(int age,double salary)
{
if (age<40)
{
double insurance = salary*0.03;
return insurance;
}
if (age>=40 && age<50)
{
double insurance = salary*0.04;
return insurance;
}
if (age>=50 && age<60)
{
double insurance = salary*0.05;
return insurance;
}
if (age>60)
{
double insurance = salary*0.06;
return insurance;
}
}
double getNetPay(double salary,int age)
{
double netPay = salary-getFedTax(double salary)-getSsTax(1)- getHealthFee(3)-getInsurance(int age);[code]///my errors are here. '.class' expected and ')' expected.
[code] return netPay;
}
}[code]

The problem is Write a class Employee with the following specifications:
Fields: Name - Name of employee Id - Employee id Salary - Employee salary Age - Employee age Position - Employee title
Methods:
1. getFedTax() - Returns (int) federal tax withheld. Computed as follows:
multiply (salary - 800) by 17%.
2. getSsTax(rate) - returns (int) social security tax withheld, rate% of salary;
rate is int.
3. getHealthFee(rate) - returns(int) health coverage employee contribution,
rate% of salary; rate is int.
4. getInsurance() - returns (int) employee contribution for insurance coverage.
Amount of deduction is computed as follows:
If the employee is under 40 rate is 3% of salary, if the employee is between
40 and 50 rate is 4% of salary, and if the employee is between 50 and 60
rate is 5% of salary. If the employee is above 60 the rate is 6% of salary.
5. getNetPay() -returns (double) the net pay for the employee after deducting
from salary, the deductions: ss(1), health(3), fed_tax() and insurance

Is This A Good Question/Topic? 0
  • +

Replies To: employee class assignment

#2 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: employee class assignment

Posted 20 March 2008 - 02:14 PM

Well, I haven't tested it but the first thing that I could see was:

double netPay = salary-getFedTax(double salary)-getSsTax(1)- getHealthFee(3)-getInsurance(int age);

should be,

double netPay = salary-getFedTax(salary)-getSsTax(1)- getHealthFee(3)-getInsurance(age);


*edit: Please use code tags like this :code:

This post has been edited by letthecolorsrumble: 20 March 2008 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

#3 buckfan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-February 08

Re: employee class assignment

Posted 20 March 2008 - 03:41 PM

I changed the line you suggested and I got a whole bunch of errors. Possible loss of precision on the return ssTax; return healthFee; return insurance; lines. I've never seen that error before.
Was This Post Helpful? 0
  • +
  • -

#4 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: employee class assignment

Posted 20 March 2008 - 04:07 PM

public class Employee {
	
	String name;
	String id;
	double salary;
	int age;
	String position;
	
	void display() {
		
		System.out.println("Employee Name:"+ "Jack"); //output strings
		System.out.println("Employee Id:"+id);
		System.out.printf("Salary:$%.2f\n",60000);
		System.out.println("Employee Age:"+43);
		System.out.println("Employee Position:"+ "trashman"); //output strings
		
	}
	
	double getFedTax(double salary) {
		
		double fedTax=(salary-800)*.17;
		return fedTax;
		
	}
	
	int getSsTax(int rate,double salary) {
		
		double ssTax = salary*(rate/100);
		return (int)ssTax;  //casting to int from double to have the correct return type
		//are you sure you want to return int for all the methods?
	}
	
	int getHealthFee(int rate,double salary) {
		
		double healthFee = (rate/100)*salary;
		return (int)healthFee;
		
	}
	
	int getInsurance(int age,double salary) {
		
		if (age<40) {
			
			double insurance = salary*0.03;
			return (int)insurance;
			
		}
		if (age>=40 && age<50) {
			
			double insurance = salary*0.04;
			return (int)insurance;
			
		}
		if (age>=50 && age<60) {
			
			double insurance = salary*0.05;
			return (int)insurance;
			
		}
		else {  //changed to else to have a return value if the above expressions are not true
			
			double insurance = salary*0.06;
			return (int)insurance;
			
		}
		
	}
	
	double getNetPay(double salary,int age) {
		
		//need to pass the exact number of parameters, as defined, to the methods you want to use
		double netPay = salary-getFedTax(salary)-getSsTax(2, salary)-
						getHealthFee(3, salary)-getInsurance(age, salary); 
		return netPay;
		
	}
}



Try this code, although there are many things you might want/need to change for the correct display and functionality of the program.
Was This Post Helpful? 0
  • +
  • -

#5 buckfan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-February 08

Re: employee class assignment

Posted 22 March 2008 - 08:52 PM

The program compiles without errors, but when executed says "Exception in thread "main" java.lang.NoSuchMethodError:main." Something is wrong with the main???

View Postletthecolorsrumble, on 20 Mar, 2008 - 04:07 PM, said:

public class Employee {
	
	String name;
	String id;
	double salary;
	int age;
	String position;
	
	void display() {
		
		System.out.println("Employee Name:"+ "Jack"); //output strings
		System.out.println("Employee Id:"+id);
		System.out.printf("Salary:$%.2f\n",60000);
		System.out.println("Employee Age:"+43);
		System.out.println("Employee Position:"+ "trashman"); //output strings
		
	}
	
	double getFedTax(double salary) {
		
		double fedTax=(salary-800)*.17;
		return fedTax;
		
	}
	
	int getSsTax(int rate,double salary) {
		
		double ssTax = salary*(rate/100);
		return (int)ssTax;  //casting to int from double to have the correct return type
		//are you sure you want to return int for all the methods?
	}
	
	int getHealthFee(int rate,double salary) {
		
		double healthFee = (rate/100)*salary;
		return (int)healthFee;
		
	}
	
	int getInsurance(int age,double salary) {
		
		if (age<40) {
			
			double insurance = salary*0.03;
			return (int)insurance;
			
		}
		if (age>=40 && age<50) {
			
			double insurance = salary*0.04;
			return (int)insurance;
			
		}
		if (age>=50 && age<60) {
			
			double insurance = salary*0.05;
			return (int)insurance;
			
		}
		else {  //changed to else to have a return value if the above expressions are not true
			
			double insurance = salary*0.06;
			return (int)insurance;
			
		}
		
	}
	
	double getNetPay(double salary,int age) {
		
		//need to pass the exact number of parameters, as defined, to the methods you want to use
		double netPay = salary-getFedTax(salary)-getSsTax(2, salary)-
						getHealthFee(3, salary)-getInsurance(age, salary); 
		return netPay;
		
	}
}



Try this code, although there are many things you might want/need to change for the correct display and functionality of the program.

Was This Post Helpful? 0
  • +
  • -

#6 buckfan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-February 08

Re: employee class assignment

Posted 23 March 2008 - 05:56 PM

Anybody out there?
Was This Post Helpful? 0
  • +
  • -

#7 jjdoll83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-October 08

Re: employee class assignment

Posted 11 November 2008 - 04:04 AM

I have the same code as you did and got the same error.

--------------------Configuration: <Default>--------------------
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.

[code]class Employee {

String name;
String id;
double salary;
int age;
String position;

void display() {

System.out.println("Employee Name:"+ "Jack"); //output strings
System.out.println("Employee Id:"+id);
System.out.printf("Salary:$%.2f\n",60000);
System.out.println("Employee Age:"+43);
System.out.println("Employee Position:"+ "trashman"); //output strings

}

double getFedTax(double salary) {

double fedTax=(salary-800)*.17;
return fedTax;

}

int getSsTax(int rate,double salary) {

double ssTax = salary*(rate/100);
return (int)ssTax; //casting to int from double to have the correct return type
//are you sure you want to return int for all the methods?
}

int getHealthFee(int rate,double salary) {

double healthFee = (rate/100)*salary;
return (int)healthFee;

}

int getInsurance(int age,double salary) {

if (age<40) {

double insurance = salary*0.03;
return (int)insurance;

}
if (age>=40 && age<50) {

double insurance = salary*0.04;
return (int)insurance;

}
if (age>=50 && age<60) {

double insurance = salary*0.05;
return (int)insurance;

}
else { //changed to else to have a return value if the above expressions are not true

double insurance = salary*0.06;
return (int)insurance;

}

}

double getNetPay(double salary,int age) {

//need to pass the exact number of parameters, as defined, to the methods you want to use
double netPay = salary-getFedTax(salary)-getSsTax(2, salary)-
getHealthFee(3, salary)-getInsurance(age, salary);
return netPay;

}
}[code]

Does anyone have any suggestions on this, I am totally lost on it and can't see what is wrong.
Was This Post Helpful? 0
  • +
  • -

#8 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: employee class assignment

Posted 11 November 2008 - 04:10 AM

Please use the code tags properly, you forgot the '/' in the end-tag.

By the way, did you write any code on your own or did you steal the code from the previous posts?

This post has been edited by Gloin: 11 November 2008 - 04:15 AM

Was This Post Helpful? 0
  • +
  • -

#9 ham0423  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-November 08

Re: employee class assignment

Posted 13 November 2008 - 06:09 PM

My code is pretty similar to the one above and I get the same error. It compiles correctly but I get an error that says:

java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.


I can't find anymore problems on this code so any help on finding where its wrong would be awesome.

class Employee {
	
	String name;
	String id;
	double salary;
	int age;
	String position;
	
	  
	double getFedTax(double salary) {
		
		double fedTax=(salary-800)*.17;
		return fedTax;
		
	}
	
	int getSsTax(int rate,double salary) {
		
		double ssTax = salary*(rate/100);
		return (int)ssTax;  
	}
	
	int getHealthFee(int rate,double salary) {
		
		double healthFee = (rate/100)*salary;
		return (int)healthFee;
		
	}
	
	int getInsurance(int age,double salary) {
		
		if (age<40) {
			
			double insurance = salary*0.03;
			return (int)insurance;
			
		}
		if (age>=40 && age<50) {
			
			double insurance = salary*0.04;
			return (int)insurance;
			
		}
		if (age>=50 && age<60) {
			
			double insurance = salary*0.05;
			return (int)insurance;
			
		}
		else {  
			
			double insurance = salary*0.06;
			return (int)insurance;
			
		}
		
	}
	
	double getNetPay(double salary,int age) {
		
		double netPay = salary-getFedTax(salary)-getSsTax(2, salary)-
						getHealthFee(3, salary)-getInsurance(age, salary);
		return netPay;
		
	}
	
	  void display() {
		
		System.out.println("Employee Name:"+ "Larry"); 
		System.out.println("Employee Id:"+id);
		System.out.printf("Salary:$%.2f\n",55000);
		System.out.println("Employee Age:"+48);
		System.out.println("Employee Position:"+ "helpdesk"); 
		
	}
} 

Was This Post Helpful? 0
  • +
  • -

#10 cj2525  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 14-March 08

Re: employee class assignment

Posted 14 November 2008 - 10:56 PM

Try writing a class with a main method included. The code for an application will not run without a main method.


[quote name='ham0423' date='13 Nov, 2008 - 05:09 PM' post='464108']
My code is pretty similar to the one above and I get the same error. It compiles correctly but I get an error that says:

java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1