I need some Java Help
Posted: Sat Feb 11, 2006 10:31 am
Hey guys I am working on a program for school and I'm having some serious issues with it. Currently it is telling me I have not declared the variable 'rate' when I try to print out my results. Maybe you guys can take a look and tell me wtf I'm doing wrong. TIA for any assistance.
Code: Select all
import javax.swing.JOptionPane;
public class Pay
{
public static void main(String[] args)
{
String jobTypeString, empHoursString;
int jobType;
double empHours;
double regularPay;
double rate;
double grossPay = 0.0;
double overtimePay = 0.0;
double maxHours = 50.0;
//Request employee type and hours worked from user
jobTypeString = JOptionPane.showInputDialog(null,
\"Please enter the job type.\" +
\"/nChoose type 1, 2, or 3\");
jobType = Integer.parseInt(jobTypeString);
empHoursString = JOptionPane.showInputDialog(null,
\"Please enter the hours worked.\" +
\"/nHours are not to exceed 50.\");
empHours = Integer.parseInt(empHoursString);
if(jobType == 1 && empHours <= 50 && empHours > 40)
{
rate = 7.00;
regularPay = 40 * rate;
overtimePay = (empHours - 40) * 2 * rate;
grossPay = regularPay + overtimePay;
}
else if(empHours < 40)
{
rate = 7.00;
regularPay = 40 * rate;
overtimePay = overtimePay;
grossPay = regularPay + overtimePay;
}
else if(jobType == 2 && empHours <= 50 && empHours > 40)
{
rate = 10.00;
regularPay = 40 * rate;
overtimePay = (empHours - 40) * 2 * rate;
grossPay = regularPay + overtimePay;
}
else if(empHours < 40)
{
rate = 10.00;
regularPay = 40 * rate;
overtimePay = overtimePay;
grossPay = regularPay + overtimePay;
}
else if(jobType == 3 && empHours <= 50 && empHours > 40)
{
rate = 12.00;
regularPay = 40 * rate;
overtimePay = (empHours - 40) * 2 * rate;
grossPay = regularPay + overtimePay;
}
else if(empHours < 40)
{
rate = 12.00;
regularPay = 40 * rate;
overtimePay = overtimePay;
grossPay = regularPay + overtimePay;
}
//Display hours worked, rate, regular pay, and overtime pay for employee.
JOptionPane.showMessageDialog(null,
\"The employee worked \" + empHours + \" at the rate of \" + rate +
\"dollars per hour.\" +
\"/nThe regular pay amount for the week is \" + regularPay +
\"/nThe overtime pay amount for the week is \" + overtimePay +
\"/nThe gross pay amount for the week is \" + grossPay);
System.exit(0);
}
}