I am a novice java student I need to caculate employee bonus's based on their units produced. Whenever I run the program it is giving a scanner error due to the input. "java.util.InputMismatchException". Any help is greatly appreciated!
/**
* NAME: Mitchell Noble
* DATE: October 27, 2015
* FILE: lab9
* COMMENTS: This java program is designed to caculate employee bonus's based on their units produced
*/
import java.util.Scanner;
public class lab9
{
public static void main(String[]args)
{
// declare variables
double Lastname;
double Currentunits;
double Lastunits;
double Firstname;
//Create a Scanner Object
Scanner keyboard= new Scanner(System.in);
//Get names and units
System.out.print("Hello we are going to learn about your production this year and award bonus's but first we need some information.");
System.out.print("What is your last name?");
Lastname = keyboard.nextDouble();
System.out.print("What is your first name?");
Firstname = keyboard.nextDouble();
System.out.print("How many units did you produce this year?");
Currentunits = keyboard.nextDouble();
System.out.print("How many units did you produce last year?");
Lastunits = keyboard.nextDouble();
//Sort into proper bonus category
if (Currentunits > Lastunits)
{
if (Currentunits >= 1000)
{
if (Currentunits >= 3001)
{
if (Currentunits >= 6001)
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $200. Good work!");
}
else
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $100. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $50. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on your units produced this year your bonus will be $25. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on the units produced this year compared to last year you do not qualify for any bonu's.");
}
} // close main
} // close lab7
double. Can you show us your input?lastName,firstNameto bedouble. Check your code. I think you have to usenextLine()and declare those fields as Stringsif(currentUnits >= 6001) { // $200 bonus } else if(currentUnits >= 3001) { // $100 bonus }etc. Makes the code a lot clearer.