Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Class Help

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Java Class Help

    I was wondering how do I go about adding this to my code?

    Now, create public accessor & private modifier methods (gets & sets) in the “Employee.java” file for each of the 4 data
    members. Use the following as the error-checking criteria in your modifier (“set”) methods:
    - First Name & Last Name: Must have size greater than zero, and size less than or equal to 20.
    - Employee Id: Value must be greater than or equal to 1000, but less than or equal to 9999.
    - Employee Rate: Must be greater than zero.

    public class Employee {
     
    public String firstName;
    public String lastName;
    private double hourlyRate;
    private int employeeId;
     
     
    private Employee(String first, String last, double hourly, int employeeID) 
    {
    firstName = first;
    lastName = last;
    hourlyRate = hourly;
    employeeId = employeeID;
    }
     
     
    public static void main(String[] args)
    {
     
    Employee e = new Employee("John", "Doe", 14.79, 1597);
     
    System.out.println("Name: " + e.firstName + " " + e.lastName);
    System.out.println("Hourly: $" + e.hourlyRate);
    System.out.println("EmployeeID: " + e.employeeId);
    System.out.println(); // This will simply create a blank line
     
    e = new Employee("Sarah", " Dao", 17.55, 2574);
     
    System.out.println("Name: " + e.firstName + " " + e.lastName);
    System.out.println("Hourly: $" + e.hourlyRate);
    System.out.println("EmployeeID: " + e.employeeId);
    System.out.println(); 
    }}
    Attached Files Attached Files


  2. #2
    Junior Member
    Join Date
    Jan 2014
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Java Class Help

    I was wondering how do I go about adding this to my code?

    Now, create public accessor & private modifier methods (gets & sets) in the “Employee.java” file for each of the 4 data
    members. Use the following as the error-checking criteria in your modifier (“set”) methods:
    - First Name & Last Name: Must have size greater than zero, and size less than or equal to 20.
    - Employee Id: Value must be greater than or equal to 1000, but less than or equal to 9999.
    - Employee Rate: Must be greater than zero.

    public class Employee {
     
    public String firstName;
    public String lastName;
    private double hourlyRate;
    private int employeeId;
     
     
    private Employee(String first, String last, double hourly, int employeeID) 
    {
    firstName = first;
    lastName = last;
    hourlyRate = hourly;
    employeeId = employeeID;
    }
     
     
    public static void main(String[] args)
    {
     
    Employee e = new Employee("John", "Doe", 14.79, 1597);
     
    System.out.println("Name: " + e.firstName + " " + e.lastName);
    System.out.println("Hourly: $" + e.hourlyRate);
    System.out.println("EmployeeID: " + e.employeeId);
    System.out.println(); // This will simply create a blank line
     
    e = new Employee("Sarah", " Dao", 17.55, 2574);
     
    System.out.println("Name: " + e.firstName + " " + e.lastName);
    System.out.println("Hourly: $" + e.hourlyRate);
    System.out.println("EmployeeID: " + e.employeeId);
    System.out.println(); 
    }}
    Attached Files Attached Files

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Class Help

    Please don't post the same topic in multiple places in the forum. It's not helpful.

    The smart-a answer to your question is "open your editor and follow the instructions." Since that's obvious, or should be, instead I'll ask you, What don't you understand about the very specific instructions you've been given?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Class Help

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java and Flickr - Help with Inheritance between Main Class and sub-class
    By thientanchuong in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 14th, 2012, 07:29 PM
  2. Java and Flickr - Help with Inheritance between Main Class and sub-class
    By thientanchuong in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 12th, 2012, 08:10 PM
  3. Java, calling another public class from within the main class giving problems.
    By RandomGaisha in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 26th, 2012, 02:30 PM
  4. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  5. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM

Tags for this Thread