I am working on a program I am new to Java and I am having a problem: I need to use the class below and create a variable to represent whether the employee donates money or not. I also need a constant to represent the set donation value of $10.00. Finally, a method to set the status of the employee if they donate or not. I am a little confused where do I put this in my code??? Thanks
public class Employee{
//Class instance variables
int empId; String firstName; String lastName; String streetAddress; String city; String state; String zip; int empId;
double hourlyRate = 0.00; //$Per Hour default to 0 double hoursWorked = 0.0; //Total hours worked default to 0
//Class Constructor
public Employee(){ //Default constructor, sent out a basic notification message System.out.println("New Employee Created"); }
public Employee(int id){ //Overloaded constructor, provides a shortcut for the adding the id this.empId = id; System.out.println("New Employee#"+empId+"Created");
}
public String empDepartment;
public Employee(int id, String dept){ //Overloaded constructor, provides a shortcut for the adding the id this.empId = id; this.empDepartment = dept; System.out.println("New Employee#"+empId+"Created"); }
//Assessor Methods
public void setId(int id) { //Assigns a value to the emp id this.empId = id;
}
public int getId(){ //Returns the employee's id return(empId); }
public void setName(String fName, String lName){ //Assigns values for the employee's name this.firstName = fName; this.lastName = lName; }
public void setAddress(String street, String city, String state, String zip){ //Assigns variables for the employee's address this.streetAddress = street; this.city = city; this.state = state; this.zip = zip; } public void setHourlyRate(double rate) { //Assigns hourly rate variable this.hourlyRate = rate; } public void setHoursWorked(double hours) { //Assigns hours worked variable this.hoursWorked = hours; } public double getSalary() { //calculate correct salary double salary; salary =hoursWorked*hourlyRate; return(salary); } public String toString() {
//Declares a tempory variable and assigns basic employee //information to it, with some basic formatting //Note the operator '+=', what does it do?
I am quite new as well, hopefully this will help a little bit.
First you can create a float variable called didDonate like so: private boolean didDonate;
then you also wanted a constant of $10.00 so create that with your instance variables as well like this: final float fixedDonation = 10.00;
finally, create a set method like all the rest in this class. e.g. setName etc... only this time you are setting the donation by receiving a boolean value of yes or no as to whether they donated or not. then in the new method, you can use fixedDonation to subtract from the employees paycheck amount if you like...