I say urgent because I have to finish it pretty much tonight or maybe very early tomorrow morning. But I am moving along decently on the project, so it's not like nothing is getting done.
Basically I have a problem with a class I am in the process of completing, in which one method display(), needs to use the variables defined in another method calculateNetMonthly(). The problem is that calculateNetMonthly is not recognizing these variables. Which leads me to believe that I am somehow defining them wrong. I'm not sure how but I suspect it is obvious to those more experienced in java.
As you can see I tried a concatenation in the display() method. Doing so generates a compiler error which says cannot find symbol, basically the variable is invalid. Why?
Also any help in figuring out how to get a date from the user in getInput() would be useful. :)
The code is as follows
/*
* FullTimeEmployee.java
*
* CSCE 155 Fall 2008
* Assignment 1
* @author
* @version
*/
// import statements
import java.io.*;
import java.util.*;
/**
* Used to calculate the pay of the full time employees
*
* This class allows the application class to calculate the pay of the
* full time employees by gathering information, performing calculations
* and displaying results.
* <p>
*
* @author
* @version
*/
public class FullTimeEmployee {
// -------------------------------------------------------------------------
// You may add more data members to the following to describe a Casual
// Employee. You may need to remove some data members as well.
// -------------------------------------------------------------------------
//------------------Declare Constants---------------------------------------
/**
* Represents the percentage of the federal tax
*/
private final double FEDERAL_TAX_PERCENT = 0.15;
/**
* Represents the percentage of the health insurance deduction
*/
private final double HEALTH_INSURANCE_PERCENT = 0.05;
/**
* Represents the percentage of the Retirement Savings deduction
*/
private final double RETIREMENT_SAVINGS_PERCENT = 0.12;
/**
* Represents the percentage of the state tax
*/
private final double STATE_TAX_PERCENT = 0.08;
//-------------Declare private variables-----------------------------------
/**
* Represents the name for the employee
*/
private String employeeID;
/**
* Represents the name for the employee
*/
private String employeeName;
/**
* Represents the amount in dollars of the salary for the employee
*/
private int monthlySalary;
/**
* Represents the date of employment
*/
private Date startDate;
/**
* Constructor used to create this object. Responsible for setting
* all of this object's information to their corresponding default values
*/
public FullTimeEmployee(){
this.employeeName = "";
}//end of constructor
//-------------------------------------------------------------------------
//Please complete the following get and set methods
//Some may need to be added or removed.
//-------------------------------------------------------------------------
/**
* Returns the employee's name from this object
* @return <code>String</code> Name of the Employee represented in object
*/
public String getEmployeeName() {
return employeeName;
}
/**
* Sets the employee name represented by this object
* @param employeeName the name of the employee
*/
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
//--------------------------------------------------------------------------
//Please complete the code and docmentation for the following methods
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
// In the following, we will just have some "simulated" methods since you do
// do not have enough background to actually implement the following
// behavior. Our calculation is simply to printout a statement "performing"
// an action. You need to perform the actual calculations for this type
// of employee.
// Hint!
// 1. Complete the getInput method. You will need to prompt the user for
// all of the information related to the employee. Use the provided
// readInteger and readString methods within your code to do the actual
// reading or information from the keyboard. Store all of the
// information appropriately.
// 2. Complete the calculateNetMonthly method. You will need to take some
// of the information you have read from the getInput method and do the
// appropriate calculations. You may need to break down this method
// into several seperate methods and/or determine how to store the
// calculated information.
// 3. Complete the display method. You need to print out the information
// that was input or calculated as needed for this employee type.
// --------------------------------------------------------------------------
public void calculateNetMonthly(){
double deductionFederalTax;
double deductionStateTax;
double deductionRetirementSavings;
double deductionHealthInsurance;
double totalDeduction;
double netMonthlySalary;
deductionFederalTax = (monthlySalary * FEDERAL_TAX_PERCENT);
deductionStateTax = (monthlySalary * STATE_TAX_PERCENT);
deductionRetirementSavings = (monthlySalary * RETIREMENT_SAVINGS_PERCENT);
deductionHealthInsurance = (monthlySalary * HEALTH_INSURANCE_PERCENT);
totalDeduction = (deductionFederalTax + deductionStateTax + deductionRetirementSavings + deductionHealthInsurance);
netMonthlySalary = (monthlySalary - totalDeduction);
}//end of calculateNetMonthly
public void display(){
System.out.println("Calculating Pay for Employee: " + employeeName +" employeeID: " + employeeID);
System.out.println("Deduction for Federal Income Tax (15%): " + deductFederalTax);
System.out.println("Deduction for State Income Tax (8%): $");
System.out.println("Deduction for Retirement Savings (12%): $");
System.out.println("Deduction for Health Insurance (5%): $");
System.out.println("Total deductions from employee salary: $");
System.out.println("The net monthly salary of the employee is: $");
}//end of display
public void getInput(){
System.out.println("Please enter the Employee ID:");
employeeID = readString();
System.out.println("Please enter the Employee Name:");
employeeName = readString();
System.out.println("Please enter the date of the employement period:");
System.out.println("Please enter the gross salary of employee (in dollars):");
monthlySalary = readInteger();
}//end of getInput
/**
* This method reads an integer and returns it to the caller of the method.
* @return <code>int</code> integer read from keyboard
*/
private int readInteger() {
int temp = 0;
Scanner scanner = new Scanner(System.in);
try {
temp = scanner.nextInt(); // read integer
} catch (InputMismatchException ex) {
System.out.println(ex);
}
return temp;
} // end readInteger
/**
* This method reads a string and returns it to the caller of the method.
* @return <code>String</code> String read from keyboard
*/
private String readString() {
String userInput = "";
Scanner scanner = new Scanner(System.in);
userInput = scanner.nextLine();
return userInput;
} // end readString
}//end of class FullTimeEmployee