Reputation: 1
This is the code I have so far and this is only one file of multiple ones that all belong to the same program.
As soon as I want to compile and check my errors eclipse tells me that it cannot resolve the scanner and I have no idea how to fix this problem nor what it exactly means.
import java.util.Scanner;
public class PieShop {
static FoodItem foodItem = new FoodItem();
public static void main(String[] args) {
Scanner_in.consoleLine("Enter Food item File name:");
foodItem.foodItemFile=new File(Scanner_in.getConsole());
foodItem.addFoodItem();
foodItem.displayAll();
foodItem.choices();
}
}
Upvotes: 0
Views: 103
Reputation: 4385
This would be the correct way if you wan to read the input from the console:
import java.util.Scanner;
public class PieShop {
private static FoodItem foodItem = new FoodItem();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); // Initialize scanner
System.out.println("Enter Food item File name:"); // Print yourtext
foodItem.foodItemFile = new File(scanner.nextLine()); // Read from scanner
foodItem.addFoodItem();
foodItem.displayAll();
foodItem.choices();
}
}
Upvotes: 1
Reputation: 1666
Below code should work fine provided that you pass right value to scanner source
import java.util.Scanner;
public class PieShop {
static FoodItem foodItem = new FoodItem();
public static void main(String[] args) {
Scanner Scanner_in = new Scanner(source);
Scanner_in.consoleLine("Enter Food item File name:");
foodItem.foodItemFile=new File(Scanner_in.getConsole());
foodItem.addFoodItem();
foodItem.displayAll();
foodItem.choices();
}
}
Upvotes: 1