그래서 기본적으로 pin
변수에 액세스 할 코드가 필요합니다. 그러나 pin
을 정적으로 만들면 이클립스에서 모든 변수를 정적으로 만들기도합니다. 그래서 그렇게했습니다. 이 문제의 원인은 무엇이클립스 자바 스캐너 함수에서 정적 변수를 만드는 동안 오류가 발생했습니다
Unhandled exception type FileNotFoundException
:하지만 최대한 빨리 정적 file
수 있도록 한, Scanner(textFile)
오류를 준다? 변수가 정적이어야합니다. 어쩌면 비 정적 변수를 정적 변수로 만드는 방법이 있다면.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class atmtester {
atmtester() throws FileNotFoundException{}
static Scanner keyboard = new Scanner(System.in);
private static float balance = 500;
static String pinfile = "/Users/Pallav/Documents/Work/Computer Science/pin.txt";
static File textFile = new File(pinfile);
static Scanner fromfile = new Scanner(textFile);
static String pin = fromfile.nextLine();
위 항목에 대한 도움이 필요합니다. 아래의 코드는 왜 정적이 필요한지에 대한 컨텍스트에 대한 것입니다. 당신이하는 방법, 다음 중 하나를 수행 할 수 있습니다 내부에서 스캐너 문을 묶으면 그것이
unhandled exception: FileNotFoundException
이 때문에 주요 방법이나 다른 방법이 될 수 있습니다, 함수에서 static Scanner fromfile = new Scanner(textFile);
:
public static void main(String[] args) throws InterruptedException {
System.out.print("Please enter your PIN: ");
for (int i = 1; i < 4; i++) {
String theirpin = keyboard.next();
if (theirpin.equals(pin)) {
System.out.println("Correct PIN entered. Now taking you to menu...");
break;
} else if (!theirpin.equals(pin)) {
int triesremaining = 0;
triesremaining = 3 - i;
System.out.println("*Incorrect PIN. You have " + triesremaining + " tries remaining*");
if (triesremaining != 0)
System.out.print("Enter the correct PIN: ");
else if (i == 3) {
System.err.println("\n*Card Blocked!*");
System.exit(0);
}
}
}
static void checkPin(String tocheckpin) {
if (!tocheckpin.equals(pin)) {
System.out.print("Incorrect Pin. You have 1 more try. Try again: ");
tocheckpin = keyboard.next();
if (!tocheckpin.equals(pin)) {
System.err.println("*Card Blocked!*");
System.exit(0);
}
} else if (tocheckpin.equals(pin)) {
}
}
이 파일이 존재 하는가? 확인해 봤어? 그걸 만들려는거야? –