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();
}
}
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();
}
}
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.