Urgent Help Needed on Project

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 13
Reputation: Gerbilkit is an unknown quantity at this point 
Solved Threads: 0
Gerbilkit Gerbilkit is offline Offline
Newbie Poster

Urgent Help Needed on Project

 
0
  #1
Sep 16th, 2008
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

  1. /*
  2.  * FullTimeEmployee.java
  3.  *
  4.  * CSCE 155 Fall 2008
  5.  * Assignment 1
  6.  * @author
  7.  * @version
  8.  */
  9.  
  10. // import statements
  11. import java.io.*;
  12. import java.util.*;
  13.  
  14. /**
  15.  * Used to calculate the pay of the full time employees
  16.  *
  17.  * This class allows the application class to calculate the pay of the
  18.  * full time employees by gathering information, performing calculations
  19.  * and displaying results.
  20.  * <p>
  21.  *
  22.  * @author
  23.  * @version
  24.  */
  25.  
  26. public class FullTimeEmployee {
  27.  
  28. // -------------------------------------------------------------------------
  29. // You may add more data members to the following to describe a Casual
  30. // Employee. You may need to remove some data members as well.
  31. // -------------------------------------------------------------------------
  32.  
  33. //------------------Declare Constants---------------------------------------
  34.  
  35. /**
  36.   * Represents the percentage of the federal tax
  37.   */
  38. private final double FEDERAL_TAX_PERCENT = 0.15;
  39.  
  40. /**
  41.   * Represents the percentage of the health insurance deduction
  42.   */
  43. private final double HEALTH_INSURANCE_PERCENT = 0.05;
  44.  
  45. /**
  46.   * Represents the percentage of the Retirement Savings deduction
  47.   */
  48. private final double RETIREMENT_SAVINGS_PERCENT = 0.12;
  49.  
  50. /**
  51.   * Represents the percentage of the state tax
  52.   */
  53. private final double STATE_TAX_PERCENT = 0.08;
  54.  
  55. //-------------Declare private variables-----------------------------------
  56.  
  57. /**
  58.   * Represents the name for the employee
  59.   */
  60. private String employeeID;
  61. /**
  62.   * Represents the name for the employee
  63.   */
  64. private String employeeName;
  65. /**
  66.   * Represents the amount in dollars of the salary for the employee
  67.   */
  68. private int monthlySalary;
  69. /**
  70.   * Represents the date of employment
  71.   */
  72. private Date startDate;
  73.  
  74. /**
  75.   * Constructor used to create this object. Responsible for setting
  76.   * all of this object's information to their corresponding default values
  77.   */
  78. public FullTimeEmployee(){
  79. this.employeeName = "";
  80.  
  81. }//end of constructor
  82.  
  83.  
  84. //-------------------------------------------------------------------------
  85. //Please complete the following get and set methods
  86. //Some may need to be added or removed.
  87. //-------------------------------------------------------------------------
  88.  
  89. /**
  90.   * Returns the employee's name from this object
  91.   * @return <code>String</code> Name of the Employee represented in object
  92.   */
  93. public String getEmployeeName() {
  94. return employeeName;
  95. }
  96.  
  97. /**
  98.   * Sets the employee name represented by this object
  99.   * @param employeeName the name of the employee
  100.   */
  101. public void setEmployeeName(String employeeName) {
  102. this.employeeName = employeeName;
  103. }
  104.  
  105. //--------------------------------------------------------------------------
  106. //Please complete the code and docmentation for the following methods
  107. //--------------------------------------------------------------------------
  108.  
  109. // --------------------------------------------------------------------------
  110. // In the following, we will just have some "simulated" methods since you do
  111. // do not have enough background to actually implement the following
  112. // behavior. Our calculation is simply to printout a statement "performing"
  113. // an action. You need to perform the actual calculations for this type
  114. // of employee.
  115. // Hint!
  116. // 1. Complete the getInput method. You will need to prompt the user for
  117. // all of the information related to the employee. Use the provided
  118. // readInteger and readString methods within your code to do the actual
  119. // reading or information from the keyboard. Store all of the
  120. // information appropriately.
  121. // 2. Complete the calculateNetMonthly method. You will need to take some
  122. // of the information you have read from the getInput method and do the
  123. // appropriate calculations. You may need to break down this method
  124. // into several seperate methods and/or determine how to store the
  125. // calculated information.
  126. // 3. Complete the display method. You need to print out the information
  127. // that was input or calculated as needed for this employee type.
  128. // --------------------------------------------------------------------------
  129. public void calculateNetMonthly(){
  130.  
  131. double deductionFederalTax;
  132. double deductionStateTax;
  133. double deductionRetirementSavings;
  134. double deductionHealthInsurance;
  135. double totalDeduction;
  136. double netMonthlySalary;
  137.  
  138. deductionFederalTax = (monthlySalary * FEDERAL_TAX_PERCENT);
  139. deductionStateTax = (monthlySalary * STATE_TAX_PERCENT);
  140. deductionRetirementSavings = (monthlySalary * RETIREMENT_SAVINGS_PERCENT);
  141. deductionHealthInsurance = (monthlySalary * HEALTH_INSURANCE_PERCENT);
  142. totalDeduction = (deductionFederalTax + deductionStateTax + deductionRetirementSavings + deductionHealthInsurance);
  143. netMonthlySalary = (monthlySalary - totalDeduction);
  144.  
  145. }//end of calculateNetMonthly
  146.  
  147. public void display(){
  148. System.out.println("Calculating Pay for Employee: " + employeeName +" employeeID: " + employeeID);
  149. System.out.println("Deduction for Federal Income Tax (15%): " + deductFederalTax);
  150. System.out.println("Deduction for State Income Tax (8%): $");
  151. System.out.println("Deduction for Retirement Savings (12%): $");
  152. System.out.println("Deduction for Health Insurance (5%): $");
  153. System.out.println("Total deductions from employee salary: $");
  154. System.out.println("The net monthly salary of the employee is: $");
  155.  
  156. }//end of display
  157.  
  158. public void getInput(){
  159. System.out.println("Please enter the Employee ID:");
  160. employeeID = readString();
  161. System.out.println("Please enter the Employee Name:");
  162. employeeName = readString();
  163. System.out.println("Please enter the date of the employement period:");
  164.  
  165. System.out.println("Please enter the gross salary of employee (in dollars):");
  166. monthlySalary = readInteger();
  167.  
  168. }//end of getInput
  169.  
  170.  
  171. /**
  172.   * This method reads an integer and returns it to the caller of the method.
  173.   * @return <code>int</code> integer read from keyboard
  174.   */
  175. private int readInteger() {
  176.  
  177. int temp = 0;
  178.  
  179. Scanner scanner = new Scanner(System.in);
  180.  
  181. try {
  182. temp = scanner.nextInt(); // read integer
  183. } catch (InputMismatchException ex) {
  184. System.out.println(ex);
  185. }
  186.  
  187. return temp;
  188.  
  189. } // end readInteger
  190.  
  191. /**
  192.   * This method reads a string and returns it to the caller of the method.
  193.   * @return <code>String</code> String read from keyboard
  194.   */
  195. private String readString() {
  196.  
  197. String userInput = "";
  198.  
  199. Scanner scanner = new Scanner(System.in);
  200.  
  201. userInput = scanner.nextLine();
  202.  
  203. return userInput;
  204.  
  205. } // end readString
  206.  
  207. }//end of class FullTimeEmployee
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Urgent Help Needed on Project

 
0
  #2
Sep 17th, 2008
I assume this is a typo?
System.out.println("Deduction for Federal Income Tax (15%): " + deductFederalTax);

Should it be deductionFederalTax ? If it is, it's still not going to work because deductionFederalTax is a local variable in the calculateNetMonthly() function and therefore you can't use it in the display () function. Is deductionFederalTax perhaps supposed to be a member variable in the FullTimeEmployee class? If so, it would be accessible to all the functions and you would declare it not in the calculateNetMonthly() function, but rather with the other class variables at the top outside of any functions.

As far as asking for the date in getInput , note that the Date class is mostly deprecated so it looks like you're supposed to use Calendar and GregorianCalendar instead. I'm a little confused because they seem to have deprecated most of the methods, but I don't see where they tell you not to use the class itself.

http://java.sun.com/j2se/1.5.0/docs/...util/Date.html
http://java.sun.com/j2se/1.5.0/docs/.../Calendar.html
http://java.sun.com/j2se/1.5.0/docs/...nCalendar.html

Regardless, ask the user for the month, day, and year, then set the Date/Calendar using what the user types in using the set functions. That's how I'd do it. You already have your readString and readInt functions, so use them, then use the set commands from Calendar .
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 160
Reputation: dmanw100 is on a distinguished road 
Solved Threads: 12
dmanw100's Avatar
dmanw100 dmanw100 is offline Offline
Junior Poster

Re: Urgent Help Needed on Project

 
0
  #3
Sep 17th, 2008
Couldn't an undefined symbol also refer to a package that wasn't imported?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: stema08 is an unknown quantity at this point 
Solved Threads: 0
stema08 stema08 is offline Offline
Newbie Poster

Re: Urgent Help Needed on Project

 
0
  #4
Sep 17th, 2008
First you are referencing a non-existent variable in display(). You've declared double deductionFederalTax; in the calculateNetMonthly() yet you are using deductFederalTax in the display() method.
However so, the scope of deductionFederalTax variable is only valid in the calculateNetMonthly() method and cannot be reffered to in the display() method. So, declare deductionFederalTax as a class variable.Also, i propose you do so for the variables in the calculateNetMonthly() method since it seems you will need to reference them in the display() method in the subsequent unconcatenated statements.

The code for deductionFederalTax is as follows:


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;

private double deductionFederalTax;

/**
* 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%): " + deductionFederalTax);
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


public static void main(String[] args) {
FullTimeEmployee ft=new FullTimeEmployee();
ft.getInput();
ft.calculateNetMonthly();
ft.display();

}


}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC