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.

Java Homework Question Help

hello all I have no idea how to program or structure this:

The assignment is as follows:
5) 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.
Use the following template as a guideline on how to structure your accessor & modifier methods (“gets” & “sets”) and how to handle any errors:
private void setSomeAttribute(argType someParameter) {
if (someParameter > 100) // I used 100 as an example for error checking! {
System.out.println("Bad value passed in for someAttribute: " + someParameter);
System.exit(-1); }
someAttribute = someParameter; }
public returnType getSomeAttribute() {
return someAttribute; }
You should try to make your “set” method error messages as informative as possible. For example:
Bad Last Name Size: Someverylonglastnamethatshouldcauseproblems:43 Employee Id must be 4 or more digits: 22
Hourly Rate must be greater than zero: -23.48
￼
6) Next, change the Employee constructor implementation so that rather than simply assigning the Employee’s data attributes directly to the incoming parameters with an “=” sign, it will now call the “set” methods for each of Employee’s data attributes.
For Example:
Rather than doing this:
someAttribute = someParameter; We now want to do this:
setSomeAttribute(someParameter);
7) Finally, completely remove the “main” method from the Employee class. We will be doing something a little different for the “main” method in this assignment.
8) At this point, your “Employee” class should compile cleanly – with no errors.
9) Now, create a brand new Java class called “Driver” in the existing “coursework” package. We’ve created new classes before so you should know how to do this by now. If you have forgotten, refer to the NetBeans notes pack, or the instructions in your previous assignments.
10) Add the following “main” method to your newly created “Driver” class (in between the opening and closing curly- braces of the “Driver” class):
￼public static void main(String[] args) {
// First we variable of type Employee.
// We always set this to null as good practice. Employee e = null;
// Declare variables to hold user inputs needed // by the Employee constructor
String firstNameInput;
String lastNameInput;
int idInput; double rateInput;
// Get input data values from the user (via the keyboard) Scanner userInput = new Scanner(System.in);
System.out.println("Employee First Name: "); firstNameInput = userInput.next();
System.out.println("Employee Last Name: "); lastNameInput = userInput.next();
System.out.println("Employee Id: " ); idInput = userInput.nextInt();
System.out.println("Employee Hourly Rate: "); rateInput = userInput.nextDouble();
// Now allocate a new instance of an Employee,
// passing test data to the constructor.
e = new Employee(firstNameInput, lastNameInput,
idInput, rateInput);
// Print out the data with nice titles System.out.println();
System.out.println("Name: " + e.getFirstName() + " "
+ e.getLastName()); System.out.println( "Emp. Id: " + e.getEmployeeId());
System.out.println("Hourly Rate: $" + e.getHourlyRate());
// We're done with this employee, so now free up
// the space we allocated for that employee by setting // the "e" variable back to null
e = null;
System.out.println(); }
￼￼
11) You will need to “import” “java.util.Scanner” at the top of the “Driver” class, below the “package statement:
package coursework;
import java.util.Scanner;
public class Driver { ...
...
}
12) Now compile your project – the “Driver.java” file and the “Employee.java” files will be compiled. Fix any compiler errors as usual. Then - run the program.

Re: Java Homework Question Help

You have been asked several times to post your code correctly and links have been provided to show you how. Here is the link again. Advice has been given and questions have been asked in the other threads you've started, and you rarely (if ever?) return to provide feedback on the advice given or answer the questions asked.

Without code posted correctly and timely feedback from you, I suspect the volunteers who help here are wondering why they should spend time on your posts. Observe the minimal forum rules and guildelines and make an effort to participate in the process which is all meant to be to your benefit, not ours.