Results 1 to 6 of 6

Thread: Need help

  1. #1
    jaisan72980 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default Need help

    I am trying to Create a class called Employee. I want to have 4 variables first name (type String), last name (type String), monthly salary (type double), and dependents(type int). ive got to Provide a get and set method for each variable. Then i want to make a method that will determine the annual salary of the employee and call it getAnnualSalary. aFTER THIS I NEED TO BE ABLE TO TEST IT.

    any ideas on where to start this and how to do the test deff need help on this im lost as hell

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    Do you know how to create classes and declaire variables and how setters and gettes looks like?

  3. #3
    jaisan72980 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    A little im still learning

  4. #4
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    There are a lot of tutorials about these very basic things in programming, try to find some.

    Try to write something on your own and than ask for concrete details...

  5. #5
    jaisan72980 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    ok so ive written some code please tell me if im on the right track and if possible offer suggestions

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package employee;

    /**
    *
    * @author JAISAN
    */
    public class employee {

    String _firstname;
    String _lastname;
    double _monthlysalary;
    int _dependents;

    public employee(String initialfirstname,String initiallastname,double initialmonthlysalary, int initialdependents){

    _firstname = initialfirstname;
    _lastname = initiallastname;
    _dependents = initialdependents;
    _monthlysalary = initialmonthlysalary
    }

    public String get_firstname()
    {
    return _firstname;
    }

    public void set_firstname(String new_firstname)
    {
    _firstname = new_firstname;
    }

    public String get_lastname()
    {
    return _lastname;
    }

    public void set_lastname(String new_lastname)
    {
    _lastname = new_lastname;
    }

    public int _dependents()
    {
    return _dependents;
    }

    public void setSong(int new_dependents)
    {
    _dependents = new_dependents;
    }

    }


    and the test i used a previous project so its not complete but am i on the right trak

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package employee;

    /**
    *
    * @author JAISAN
    */
    public class employeetest {


    public static void main(String args[])

    {
    // Construct new employee
    employee myEmployee = new employee();

    // Display IPOD state

    System.out.println("Current Brand : " + myemployee.get_firstname());
    System.out.println("Current Song : " + myemployee.get_lastname());
    System.out.println("Current Volume : " + myemployee.get_dependents());

    System.out.println();

    // Change Brand, Channel, and turn up volume.
    myIpod.setBrand("APPLE 12GIG");
    myIpod.setSong(100);
    myIpod.turnVolumeUp();

    // Display IPOD state
    System.out.println("Power On Status : " + myIpod.isOn());
    System.out.println("Current Brand : " + myIpod.getBrand());
    System.out.println("Current Song : " + myIpod.getSong());
    System.out.println("Current Volume : " + myIpod.getVolume());
    System.out.println();

    // Turn Volume down 2 times and then turn off IPOD
    myIpod.turnVolumeDown();
    myIpod.turnVolumeDown();
    myIpod.turnOff();

    // Display IPOD state
    System.out.println("Power On Status : " + myIpod.isOn());
    System.out.println("Current Brand : " + myIpod.getBrand());
    System.out.println("Current Song : " + myIpod.getSong());
    System.out.println("Current Volume : " + myIpod.getVolume());
    System.out.println();

    // Turn IPOD on
    myIpod.turnOn();

    // Display IPOD state
    System.out.println("Power On Status : " + myIpod.isOn());
    System.out.println("Current Brand : " + myIpod.getBrand());
    System.out.println("Current Song : " + myIpod.getSong());
    System.out.println("Current Volume : " + myIpod.getVolume());
    System.out.println();
    }
    }

  6. #6
    Dinesh_rockz is offline Member
    Join Date
    Jan 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Default

    you must pass the arguments in constructor

    Java Code:
    // Construct new employee
    employee myEmployee = new employee("xxxx","sssss",8000.00,5);

Posting Permissions

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