85f150
09-28-2005, 10:36 PM
I can't seem to find the prob but i suck at programming.............I won't lie it is for class but i am going nuts staring at the screen. I am getting the error can't resolve symbol.......it is for all the variables that are named hours_worked and pay_rate.
Don't pay much atten to the comments as it is all a mess.
This is what i am trying to do http://www.java-help.com/IntroProj01.htm
import java.io.*;
// The main method of this class can be used to convert temperatures
// from Fahrenheit to Celsius and Celsius to Fahrenheit. It supports
// keyboard input and demonstrates menu-driven processing.
// ----- Written by: Jon Huhtala
public class Project01 {
public static void main(String[] args) {
// Constants and variables needed for menu processing.
final int CALC_PAY = 1;
final int PAY_STAT = 2;
final int ABOUT = 3;
final int EXIT = 4;
int choice = 0;
int payroll_calc = 0;
int total_gross = 0;
int av_gross_pay = 0;
// This loop handles menu-driven processing. The loop will continue until
// the user chooses to exit.
do {
// Display the menu and get the user's choice.
System.out.println("----------------------------------------");
System.out.println("");
System.out.println(" Payroll Menu");
System.out.println("");
System.out.println("1 - Calculate Pay");
System.out.println("2 - Payroll Statistics");
System.out.println("3 - About");
System.out.println("4 - Exit");
System.out.println("");
System.out.print("Enter selection: ");
choice = Utility.readInt();
System.out.println("");
if (choice == CALC_PAY) {
System.out.print("Enter hours worked: ");
double hours_worked = Utility.readDouble();
System.out.print("Enter hourly wage: ");
double pay_rate = Utility.readDouble();
}
else if (hours_worked >= 40 && pay_rate >= 5.15) {
gross_pay = (hours_worked * pay_rate + 1.5 * pay_rate (hours_worked - 40));
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}
else if (Hours_worked <= 40 && pay_rate >= 5.15) {
gross_pay = (Hours_worked * pay_rate);
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}
else if (choice == PAY_STAT) {
System.out.println("Number of payroll calculations: " + payroll_calc);
System.out.println("Total gross pay for all employees" + total_gross);
}
else if (payroll_calc > 0) {
av_gross_pay = (total_gross / payroll_calc);
Utility.pressEnter();
System.out.println("");
}
else if (payroll_calc == 0) {
System.out.println("No payroll calculations have been made, please make a different choice.");
}
// This block processes a request to exit.
if (choice == ABOUT) {
System.out.println("Paul Immoos");
Utility.pressEnter();
System.out.println("");
}
else if (choice == EXIT) {
System.out.println("Exit requested");
Utility.pressEnter();
System.out.println("");
}
// This block processes an invalid menu selection.
else {
System.out.println("Invalid menu choice");
Utility.pressEnter();
System.out.println("");
}
} while (choice != EXIT);
}
}
// This class contains custom methods that support application processing.
// ----- Written by: Jon Huhtala
class Utility {
private static BufferedReader kb =
new BufferedReader(new InputStreamReader(System.in));
// Call this method to read an int value from the keyboard.
public static int readInt() {
Integer result = null;
while (result == null) {
try {
result = new Integer(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID int! Please try again: ");
}
}
return result.intValue();
}
// Call this method to read a double value from the keyboard.
public static double readDouble() {
Double result = null;
while (result == null) {
try {
result = new Double(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID double! Please try again: ");
}
}
return result.doubleValue();
}
// Call this method to read a String value from the keyboard.
public static String readString() {
String result = null;
while (result == null) {
try {
result = kb.readLine();
}
catch(Exception err) {
System.out.print("INVALID String! Please try again: ");
}
}
return result;
}
// Call this method to ask the user to press the ENTER key to continue.
public static void pressEnter() {
System.out.print("Press ENTER to continue...");
readString();
}
}
Don't pay much atten to the comments as it is all a mess.
This is what i am trying to do http://www.java-help.com/IntroProj01.htm
import java.io.*;
// The main method of this class can be used to convert temperatures
// from Fahrenheit to Celsius and Celsius to Fahrenheit. It supports
// keyboard input and demonstrates menu-driven processing.
// ----- Written by: Jon Huhtala
public class Project01 {
public static void main(String[] args) {
// Constants and variables needed for menu processing.
final int CALC_PAY = 1;
final int PAY_STAT = 2;
final int ABOUT = 3;
final int EXIT = 4;
int choice = 0;
int payroll_calc = 0;
int total_gross = 0;
int av_gross_pay = 0;
// This loop handles menu-driven processing. The loop will continue until
// the user chooses to exit.
do {
// Display the menu and get the user's choice.
System.out.println("----------------------------------------");
System.out.println("");
System.out.println(" Payroll Menu");
System.out.println("");
System.out.println("1 - Calculate Pay");
System.out.println("2 - Payroll Statistics");
System.out.println("3 - About");
System.out.println("4 - Exit");
System.out.println("");
System.out.print("Enter selection: ");
choice = Utility.readInt();
System.out.println("");
if (choice == CALC_PAY) {
System.out.print("Enter hours worked: ");
double hours_worked = Utility.readDouble();
System.out.print("Enter hourly wage: ");
double pay_rate = Utility.readDouble();
}
else if (hours_worked >= 40 && pay_rate >= 5.15) {
gross_pay = (hours_worked * pay_rate + 1.5 * pay_rate (hours_worked - 40));
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}
else if (Hours_worked <= 40 && pay_rate >= 5.15) {
gross_pay = (Hours_worked * pay_rate);
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}
else if (choice == PAY_STAT) {
System.out.println("Number of payroll calculations: " + payroll_calc);
System.out.println("Total gross pay for all employees" + total_gross);
}
else if (payroll_calc > 0) {
av_gross_pay = (total_gross / payroll_calc);
Utility.pressEnter();
System.out.println("");
}
else if (payroll_calc == 0) {
System.out.println("No payroll calculations have been made, please make a different choice.");
}
// This block processes a request to exit.
if (choice == ABOUT) {
System.out.println("Paul Immoos");
Utility.pressEnter();
System.out.println("");
}
else if (choice == EXIT) {
System.out.println("Exit requested");
Utility.pressEnter();
System.out.println("");
}
// This block processes an invalid menu selection.
else {
System.out.println("Invalid menu choice");
Utility.pressEnter();
System.out.println("");
}
} while (choice != EXIT);
}
}
// This class contains custom methods that support application processing.
// ----- Written by: Jon Huhtala
class Utility {
private static BufferedReader kb =
new BufferedReader(new InputStreamReader(System.in));
// Call this method to read an int value from the keyboard.
public static int readInt() {
Integer result = null;
while (result == null) {
try {
result = new Integer(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID int! Please try again: ");
}
}
return result.intValue();
}
// Call this method to read a double value from the keyboard.
public static double readDouble() {
Double result = null;
while (result == null) {
try {
result = new Double(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID double! Please try again: ");
}
}
return result.doubleValue();
}
// Call this method to read a String value from the keyboard.
public static String readString() {
String result = null;
while (result == null) {
try {
result = kb.readLine();
}
catch(Exception err) {
System.out.print("INVALID String! Please try again: ");
}
}
return result;
}
// Call this method to ask the user to press the ENTER key to continue.
public static void pressEnter() {
System.out.print("Press ENTER to continue...");
readString();
}
}