I have been trying to create program that lets a user input a number of eggs to buy and calculates the price. I have tried using the scanner method to input the integer, but I can't seem to import the scanner method.
Here's what I have:
package eggsorder;
import java.util.Scanner;
import java.io.IOException;
public class EggsOrder {
static final double EGGS_DOZEN = 7.25;
static final double EGGS_SINGLE = 0.75;
static final int DOZEN_NUMBER = 12;
public static void main(String[] args) throws IOException {
System.out.println("Enter number of eggs for purchase: ");
Scanner enter = new Scanner(System.in);
int eggs = enter.nextInt();
System.out.println("You ordered " + eggs + "eggs.");
System.out.println("That is " + (eggs / DOZEN_NUMBER) + " dozen eggs at 7.25 per dozen and " + (eggs % DOZEN_NUMBER) + " additional eggs at 0.75 each");
System.out.println("Which is a total price of " + (((eggs % DOZEN_NUMBER) * EGGS_SINGLE) + ((eggs / DOZEN_NUMBER) * EGGS_DOZEN)));
This is the error I get after running:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Scanner
location: class java.util
at eggsorder.EggsOrder.<clinit>(EggsOrder.java:7)
The code works without the scanner method, but it needs to use it.
I have tried using java.util and various other variations but to no avail.
Also, I am using the latest version of NetBeans and java