I am having difficulty with this line of code. The code is to calculate a bill of internet service where Package A cost $9.95 a month for ten hours and additional hours for $2.00. Package B cost 13.95 a month for 20 hours with the additional cost of $1.00. Package C cost $19.95 per month. I keep getting this error java.util.NoSuchElementException after I put in the hours.
Here is the code:
import java.util.Scanner;
public class InternetServiceProvider {
public static void main (String args[])
{
while (true)
{
printMonthlyBill(calculateBill(getHours(), menu()));
}
}
public static double getHours()
{
double hours;
Scanner inputHours = new Scanner (System.in);
System.out.print("Please enter the hours used: ");
hours = inputHours.nextDouble();
inputHours.close();
return hours;
}
public static int menu ()
{
int packageChoice;
Scanner userInput = new Scanner (System.in);
System.out.println("Which package have you obtain? (Please use A, B, or C)");
System.out.println("[1] Package A");
System.out.println("[2] Package B");
System.out.println("[3] Package C");
System.out.print("Please select your package: ");
packageChoice = userInput.nextInt();
userInput.close();
return packageChoice;
}
}
This is the input:
Please enter the hours used: 25
Which package have you obtain? (Please use A, B, or C)
[1] Package A
[2] Package B
[3] Package C
Please select your package: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at InternetServiceProvider.menu(InternetServiceProvider.java:37)
at InternetServiceProvider.main(InternetServiceProvider.java:8)