Results 1 to 8 of 8
  1. #1
    couline is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default getter and setter method using Jcreator

    my teacher asked us to do a program, but i'm not quite sure where to start. he asked us to make 3 classes

    Employee
    String firstName
    String lastName
    String address
    int age
    double salary

    get First Name
    set First Name...

    EmployeeApp
    this is our project name and were told to start here.

    EmployeeLauncher
    this is where the main is.

    output should be
    Enter FirstName: John
    Enter LastName: Doe
    Enter Address: San Fran, CA
    Enter Age: 28
    Enter Salary: 10000

    John Doe - 28
    San Fran, CA
    $10000

    hope you can help me with the codes or at least help me start with it. x-x
    thanks in advance. :D

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: getter and setter method using Jcreator

    The starting point would be the class statement:
    class Employee {
    } // end class Employee

    Then add to it the variables and methods it needs and perhaps some import statements.

  3. #3
    couline is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: getter and setter method using Jcreator

    Java Code:
    class Employee
    {
    	private String firstName;
    	private String lastName;
    	private String address;
    	private int age;
    	private double salary;
    
    	public Employee(String first, String last, String add, int a, double sal)
    	{
    		firstName = first;
    		lastName = last;
    		address = add;
    		age = a;
    		salary = sal;
    	}
    	public void setFirstName(String first)
    	{
    		firstName = first;
    	}
    	public String getFirstName()
    	{
    		return firstName;
    	}
    
    }
    idk if im on the right track.
    i used import java.io.*; on my EmployeeApp to input all the needed data.
    Last edited by Norm; 01-22-2012 at 01:41 PM. Reason: added code tags

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: getter and setter method using Jcreator

    Does it compile without errors?
    Then write a small testing program to create an instance of the class and call the set and get methods to see if they work properly. One quick and easy way would be to add a main method to the class itself and put the testing code in there. Then execute the class and have it test itself.

  5. #5
    couline is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: getter and setter method using Jcreator

    i have nothing written on my EmployeeLauncher yet... im not sure what to put in there.

    this is what i put on my EmployeeApp
    import java.io.*;

    public class EmployeeApp
    {
    public static void main(String[] args) throws Exception
    {
    BufferedReader m = new BufferedReader(new InputStreamReader(System.in));



    System.out.print("Enter FirstName: ");
    String firstName = m.readLine();

    System.out.print("Enter LastName: ");
    String lastName = m.readLine();

    System.out.print("Enter Adress: ");
    String address = m.readLine();

    System.out.print("Enter Age: ");
    int age = Integer.parseInt(m.readLine());

    System.out.println("Enter Salary: ");
    double salary = Double.parseDouble(m.readLine());


    }

    }

    i really dont have any ideas how to call getter and setter. x-x been reading and watching tutorials about it. =/
    im not sure if im even doing the right codes for every classes. =/

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: getter and setter method using Jcreator

    how to call getter and setter.
    Call the getter to get the value from an instance of the class.
    String aValue = theClass.getValue();
    Call the setter to change a value in an instance of the class.
    theClass.setValue(theNewValue);

  7. #7
    couline is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: getter and setter method using Jcreator

    im really confuse. x-x can you make a short example of inputing data using import java.io and using getter and setter to get the inputs using 3 classes?
    please. i'd really appreciate it.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: getter and setter method using Jcreator

    There are many code samples on the forum that read data from a file. Do a Search here for the class you are using: BufferedReader.

Similar Threads

  1. help with getter and setter methods of this question.
    By luciawashaya in forum New To Java
    Replies: 6
    Last Post: 11-01-2011, 11:28 AM
  2. getter and setter method help please!
    By merdzins in forum New To Java
    Replies: 2
    Last Post: 12-06-2010, 05:06 AM
  3. use of private in getter and setter
    By katturv in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 07:17 PM
  4. Replies: 4
    Last Post: 01-01-2009, 12:03 PM
  5. problem in getter method
    By freddieMaize in forum Advanced Java
    Replies: 5
    Last Post: 05-26-2008, 07:02 AM

Posting Permissions

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