someone check out this program and tell me what im doing wrong please...every time i fix some errors i get even more than before (right now theres 10). note that im a beginner/noob, and that this doesnt work when i click run java application, either. im not sure what exactly i should put in the main method either...
import javax.swing.*;
import java.text.*;
public class Salary
{
public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}
public static int getYears()
{
boolean done = false;
int years = 0;
while (!done)
{
String strYears = JOptionPane.sho wInputDialog(nu ll, "How many years have you worked here?", "Experience ", JOptionPane.QUE STION_MESSAGE);
if (strYears == null) finish();
try
{
int years = Integer.parseIn t(strYears);
if (years <= 0) throw new NumberFormatExc eption();
else done = true;
}
catch(NumberFor matException e)
{
JOptionPane.sho wMessageDialog( null, "Your entry was not in the proper format.", "Error", JOptionPane.WAR NING_MESSAGE);
}
}
String strHours = JOptionPane.sho wInputDialog(nu ll, "How many hours have you worked?", "Hours worked", JOptionPane.QUE STION_MESSAGE);
double hours = Double.parseDou ble(strHours);
if (years <= 5)
years = getExp1();
else if ((years > 5) && (years <= 10))
years = getExp2();
else if (years > 10)
years = getExp3();
}
public static int getExp1(int years, double hours)
{
double pay;
if (hours > 40)
pay = (16.00 * hours);
else
pay = (12.00 * hours);
return pay;
}
public static int getExp2(int years, double hours)
{
double pay;
if (hours > 40)
pay = (24.00 * hours);
else
pay = (16.00 * hours);
return pay;
}
public static int getExp3(int years, double hours)
{
double pay;
if (hours > 40)
pay = (37.50 * hours);
else
pay = (25.00 * hours);
return pay;
}
public static void output(double pay)
{
DecimalFormat twoDigits = new DecimalFormat(" $#0.00");
JOptionPane.sho wMessageDialog( null, "Your gross pay is " + twoDigits.forma t(pay), "Gross Pay", JOptionPane.INF ORMATION_MESSAG E);
}
public static void finish()
{
System.exit(0);
}
}
and heres the errors:
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 6: getExp1(int,dou ble) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 7: getExp2(int,dou ble) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 8: getExp3(int,dou ble) in Salary cannot be applied to ()
pay = getExp3();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:3 4: years is already defined in getYears()
int years = Integer.parseIn t(strYears);
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:4 8: getExp1(int,dou ble) in Salary cannot be applied to ()
years = getExp1();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 0: getExp2(int,dou ble) in Salary cannot be applied to ()
years = getExp2();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 2: getExp3(int,dou ble) in Salary cannot be applied to ()
years = getExp3();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:6 2: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:7 2: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:8 2: possible loss of precision
found : double
required: int
return pay;
^
10 errors
Tool completed with exit code 1
import javax.swing.*;
import java.text.*;
public class Salary
{
public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}
public static int getYears()
{
boolean done = false;
int years = 0;
while (!done)
{
String strYears = JOptionPane.sho wInputDialog(nu ll, "How many years have you worked here?", "Experience ", JOptionPane.QUE STION_MESSAGE);
if (strYears == null) finish();
try
{
int years = Integer.parseIn t(strYears);
if (years <= 0) throw new NumberFormatExc eption();
else done = true;
}
catch(NumberFor matException e)
{
JOptionPane.sho wMessageDialog( null, "Your entry was not in the proper format.", "Error", JOptionPane.WAR NING_MESSAGE);
}
}
String strHours = JOptionPane.sho wInputDialog(nu ll, "How many hours have you worked?", "Hours worked", JOptionPane.QUE STION_MESSAGE);
double hours = Double.parseDou ble(strHours);
if (years <= 5)
years = getExp1();
else if ((years > 5) && (years <= 10))
years = getExp2();
else if (years > 10)
years = getExp3();
}
public static int getExp1(int years, double hours)
{
double pay;
if (hours > 40)
pay = (16.00 * hours);
else
pay = (12.00 * hours);
return pay;
}
public static int getExp2(int years, double hours)
{
double pay;
if (hours > 40)
pay = (24.00 * hours);
else
pay = (16.00 * hours);
return pay;
}
public static int getExp3(int years, double hours)
{
double pay;
if (hours > 40)
pay = (37.50 * hours);
else
pay = (25.00 * hours);
return pay;
}
public static void output(double pay)
{
DecimalFormat twoDigits = new DecimalFormat(" $#0.00");
JOptionPane.sho wMessageDialog( null, "Your gross pay is " + twoDigits.forma t(pay), "Gross Pay", JOptionPane.INF ORMATION_MESSAG E);
}
public static void finish()
{
System.exit(0);
}
}
and heres the errors:
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 6: getExp1(int,dou ble) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 7: getExp2(int,dou ble) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 8: getExp3(int,dou ble) in Salary cannot be applied to ()
pay = getExp3();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:3 4: years is already defined in getYears()
int years = Integer.parseIn t(strYears);
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:4 8: getExp1(int,dou ble) in Salary cannot be applied to ()
years = getExp1();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 0: getExp2(int,dou ble) in Salary cannot be applied to ()
years = getExp2();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 2: getExp3(int,dou ble) in Salary cannot be applied to ()
years = getExp3();
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:6 2: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:7 2: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:8 2: possible loss of precision
found : double
required: int
return pay;
^
10 errors
Tool completed with exit code 1
Comment