私が取り組んでいるコードは、ユーザーからの入力を受け入れることを目的としていますが、プログラムを実行するたびに、java.land.nullexception: null. どうすればいいのかわからない!
import java.util.Scanner;
public class HamzasGrocery
{
// instance variables - replace the example below with your own
private Scanner in;
/**
* Constructor for objects of class HamzasGrocery
*/
public HamzasGrocery()
{
Scanner in = new Scanner(System.in);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void sampleMethod()
{
double choice1;
double choice2;
double choice3;
double choice4;
double choice5;
double total;
System.out.print("Enter item #1: ");
System.out.println();
choice1 = in.nextDouble();
System.out.print("Enter item #2: ");
choice2 = in.nextDouble();
System.out.println();
System.out.print("Enter item #3: ");
choice3 = in.nextDouble();
System.out.println();
System.out.print("Enter item #4: ");
choice4 = in.nextDouble();
System.out.println();
System.out.print("Enter item #5: ");
choice5 = in.nextDouble();
System.out.println();
System.out.printf("%-10s", "Item #'s");
System.out.printf("%-10s", "Cost:");
System.out.printf("%-10s", "Total:");
}
}