Results 1 to 5 of 5
  1. #1
    Bashair is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default problem in code of EmployeeTest

    I have problem in this code ,I didn't get the run I don't know
    Create a class called Employee that includes three instance variables
    • First name, type string
    • Last name, type string
    • Monthly salary, type double
    Provide a constructor that initializes the three instance variables.
    Provide a set and get method for each instance variable. If the monthly salary is not positive, do not set its value.
    Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects each Employee’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.

    Java Code:
    // Create a class called Employee
     class Employee{
    private String FirstName;//First Name
    private String LastName;//Last Name
    private double MonthlySalary;//Monthly Salary
    
    // constructor that initializes the three instance variables
    public Employee()
        {
        FirstName=null;
        LastName=null;
        MonthlySalary=0.0;
    }
    
       
    void Employee(String first ,String last ,double salary) {
        FirstName=first;
        LastName=last;
        MonthlySalary=salary;
    
    }
    
    // Provide a set and get method for each instance variable.
    // set and get method for variable FirstName
    
    public void  setFirstName(String first)
    {
        FirstName=first;
    }
    public String  getFirstName()
    {
       return FirstName;
    }
    
    //----------------------
    //set and get method for variable LastName
    public void  setLastName(String last)
    {
         LastName=last;
    }
    public String  getLastName()
    {
       return LastName;
    }
    //----------------------------
    
    //set and get method for variable MonthlySalary
    
    public void  setMonthlySalary(double salary)
    {    if(salary<0.0){salary=salary*-1;}
         MonthlySalary=salary;
    }
    public double getMonthlySalary() {
            return MonthlySalary;
        }
    
    //-----------------------------------
    public double getSalaryForYear(){
        return  MonthlySalary *12;
        }
    
    public void raise(){
        double value = getMonthlySalary()/10.0;
        double newSalary = getMonthlySalary() + value;
        setMonthlySalary(newSalary);
    }
    }
    
    /**
     *
     * @author hp
     */
    
    
     class Main {
    
        /**
         * @param args the command line arguments
         */
          public static void main(String[] args) {
            // TODO code application logic here
    
    
    //  Create two Employee objects
            Employee e1 = new Employee("Ahmed,Ali,1000");
            Employee e2 = new Employee("Mohmed,Salam,5000");
    
            System.out.println("First Employee: "+e1.getFirstName()+"\t"+e1.getLastName()+"\n");
            System.out.println("His current salary : "+e1.getMonthlySalary()+"\tone year :"+e1.getSalaryForYear()+"\n\n");
            e1.raise();
            System.out.println("After Increase: "+e1.getMonthlySalary()+"\tone year :"+e1.getSalaryForYear()+"\n");
    
            System.out.println("----------------------------Second Employee-------------------------");
    
             System.out.println("First Employee: "+e2.getFirstName()+"\t"+e2.getLastName()+"\n");
            System.out.println("His current salary : "+e2.getMonthlySalary()+"\tone year :"+e2.getSalaryForYear()+"\n\n");
            e2.raise();
            System.out.println("After Increase: "+e2.getMonthlySalary()+"\tone year :"+e2.getSalaryForYear()+"\n");
    
    
        }
    }
    do you help me to find where are the errors???

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    What errors have you gotten?

  3. #3
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    I'm terribly sorry, but Uri Geller stole my crystal ball for one his magic acts, so I'm unable to read your mind and magically see what errors you get and what lines they point to. :(

    But one obvious error:
    PHP Code:
    void Employee
    That's not how you declare a constructor. Consult you documentation. And Java conventions state that variable names should start with a non-capital letter. It's not mandatory, but highly recommended.

  4. #4
    Bashair is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    I don't know if my code is true or not :(
    this is first homework in java and I'm novice in learning Java

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Like stated previously, we can't read your mind. Give use detailed error messages. Copy and paste the exact errors, do not paraphrase.

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  2. Problem with code
    By and0rsk in forum New To Java
    Replies: 1
    Last Post: 10-10-2010, 09:52 AM
  3. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  4. Problem with code
    By oregon in forum New To Java
    Replies: 3
    Last Post: 08-05-2007, 05:57 PM
  5. Problem with my first code
    By paul in forum New To Java
    Replies: 2
    Last Post: 07-26-2007, 04:09 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
  •