Results 1 to 5 of 5
  1. #1
    jim01 is offline Member
    Join Date
    Sep 2010
    Location
    Southwest Missouri
    Posts
    97
    Rep Power
    0

    Default 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.

    Java 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{
         }
     }
    I receive dozens of error messages, the first being " '.class' expected" error message at line 51, which is the getFedtax method

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    pawdlk is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    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

  4. #4
    jim01 is offline Member
    Join Date
    Sep 2010
    Location
    Southwest Missouri
    Posts
    97
    Rep Power
    0

    Default

    OK. Thank you. I will begin again.

  5. #5
    jim01 is offline Member
    Join Date
    Sep 2010
    Location
    Southwest Missouri
    Posts
    97
    Rep Power
    0

    Default

    Not for very long. We are required to use JCreator. I will scrap it and begin again. Thank you

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Replies: 1
    Last Post: 02-03-2011, 06:43 PM
  3. creating objects by methods automatically
    By thedarlington in forum New To Java
    Replies: 13
    Last Post: 02-07-2010, 11:48 PM
  4. Replies: 4
    Last Post: 04-03-2009, 07:36 AM
  5. Replies: 1
    Last Post: 01-22-2009, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •