Results 1 to 5 of 5
Thread: Methods and Objects.
- 05-15-2011, 08:36 PM #1
Member
- Join Date
- Sep 2010
- Location
- Southwest Missouri
- Posts
- 97
- Rep Power
- 0
Methods and Objects.
I am having trouble writing a program with multiple methods and objects and I was hoping someone might be able to tell me where I am going wrong. Here is the scenario.
I have to write a program with an Employee class, a main method with two objects, emp1 and emp2, and the following 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.
Here is what I have come up with but it doesn't compile.
I receive dozens of error messages, the first being " '.class' expected" error message at line 51, which is the getFedtax methodJava Code://create Employee class public class Employee { //create main method public static void main(String[] args) { //declare variables String name; String position; int id; int salary; int age; //create employee 1 object Employee emp1 = new Employee(); emp1.name = "John"; emp1.id = 12345; emp1.salary = 60000; emp1.age = 45; emp1.position = "Developer"; emp1.getFedTax(); emp1.getSsTax(rate); emp1.getHealthFee(rate); emp1.getInsurance(); emp1.display(); //create employee 2 object Employee emp2 = new Employee(); emp2.name = "George"; emp2.id = 67890; emp2.salary =75000; emp2.age = 52; emp2.position = "Manager"; emp2.getFedTax(fedTax); emp2.getSsTax(rate); emp2.getHealthFee(rate); emp2.getInsurance(contribution); emp2.display(); } //returns federal tax double getFedTax(){ return int fedTax = double (salary - 800) * 0.17; } //returns social security tax double getSsTax(rate){ return int rate = double salary * 0.075; } //returns health coverage employee contribution double getHealthFee(rate){ return int rate = double salary * 0.05; } //return employee contribution for insurance coverage double getInsurance(contribution){ if (age < 40) return int contribution = double 0.03 * salary; if (age >= 40 && age < 50) return int contribution = double 0.04 * salary; if (age >= 50 && age < 60) return int contribution = double 0.05 * salary; if (age >= 60) return int contribution = double 0.06 * salary; } void display{ } }
-
Sorry, but that code is full of so many errors that I recommend that you completely scrap it and start over, but if you do, remember to compile early and often (after adding each line of code), and not to add any new code until the current code compiles without error.
- 05-15-2011, 09:01 PM #3
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Hi,
Have you ever been programming in Java (or any other programming language ) ? I do not know what IDE you use to compile your programs but try to use Ecllipse that should explain you your all errors .. there is too much of them in the program you send to explain...
P
- 05-15-2011, 09:07 PM #4
Member
- Join Date
- Sep 2010
- Location
- Southwest Missouri
- Posts
- 97
- Rep Power
- 0
OK. Thank you. I will begin again.
- 05-15-2011, 09:07 PM #5
Member
- Join Date
- Sep 2010
- Location
- Southwest Missouri
- Posts
- 97
- Rep Power
- 0
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
Problem passing objects as parameters to remote methods via RMI
By nicoeschpiko in forum New To JavaReplies: 1Last Post: 02-03-2011, 05:43 PM -
creating objects by methods automatically
By thedarlington in forum New To JavaReplies: 13Last Post: 02-07-2010, 10:48 PM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:36 AM -
read txt file,with some records, create objects and store objects in tables of a db.
By stamv in forum JDBCReplies: 1Last Post: 01-22-2009, 04:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks