I've been searching on the internet and can't seem to find this answer So does anyone know to how stop users from inputting letters where only numbers should be allowed?
This is what my code looks like so far.
public static double payCalculator(double hours, double basePay)
{
double totalPay;
double overTime = 8.00 * 1.5;
while(hours < 0 | hours > 60) {
System.out.println("Cannot work more than 60 hours a week");
System.out.println("Hours Work?");
hours = in.nextDouble();
}
while(basePay < 8) {
System.out.println("Base Pay cannot be less than 8");
System.out.println("Base Pay?");
basePay = in.nextDouble();
}
if
(hours <= 40){
totalPay = hours*basePay;
}
else {
totalPay = ((hours - 40)*overTime) + (40*basePay);
}
return totalPay;
}
public static void main (String[] args) {
System.out.println("Hours worked?");
hours = in.nextDouble();
System.out.println("Base Pay?");
basePay = in.nextDouble();
DecimalFormat df = new DecimalFormat("###.##");
totalPay = payCalculator(hours, basePay);
System.out.println("Total Pay is " + df.format(totalPay));
}
}
Thank you for your time.
mainmethod is enough to understand what you are asking for, therefore there was no need to includepayCalculator()method with your code.