간단한 은행 업무 신청서를 작성해야하는 과제가 있습니다. 나는 성과와 성, 고객 ID 및 균형을 가진 파일에 고객 정보를 저장해야합니다. 그런 다음 잔액을 확인하고 인출하고 입금하고 종료하는 메뉴 옵션을 만들어야합니다. 내가 현재 가지고있는 문제는 사용자가 균형을 확인하려고 할 때 균형을 보여 주려고하는 것입니다. 잔액이 내 파일의 네 번째 줄에 있으며 네 번째 줄만 표시 한 다음 그 번호를 사용하여 숫자를 더하거나 뺄 수있는 방법을 모르겠습니다. switch 문에서 case 1에서이 작업을 수행하려고합니다. 모든 힌트를 부탁드립니다.java에서 파일을 읽으시겠습니까?
import java.util.Scanner;
import java.text.DecimalFormat;
import java.io.*;
public class bank {
public static void main(String[] args) throws IOException {
String fileName; // stores the name of the file
String bankCustomer; // used to display the customers bank information
int menuOption = 0; // allows the user to enter a number so they can select what they want to do
Scanner keyboard = new Scanner(System. in);
// enter the file name to see customer information
System.out.print("enter file name ");
fileName = keyboard.nextLine();
File file = new File(fileName);
Scanner inputFile = new Scanner(file);
// read customer information from file i need this
while (inputFile.hasNext()) {
bankCustomer = inputFile.nextLine();
System.out.println(bankCustomer);
}
System.out.println("Please enter the number for the following:\n 1) Balance \n 2) Deposit + \n 3) Withdrawal \n 4) Quit ");
menuOption = keyboard.nextInt();
switch (menuOption) {
case 1:
// need to show balance how do i do that?
while (inputFile.hasNext()) {
bankCustomer = inputFile.nextLine();
System.out.println(bankCustomer);
}
break;
default:
System.out.println("Invalid choice");
}
inputFile.close();
}
}
배열 –
@RishiDholliwar 당신은 수업 만들기를 다루었습니까? 그렇다면, 모든 필드를 가진'User' 클래스를 생성하고 그것을 채 웁니다. –
는 대답 – owaism