我正在创建一个银行应用程序,我需要从数字 1 开始生成一个客户编号,跟踪该数字,以便每次进入循环时它都不会重复并将其存储到我可以使用的 int 变量中收集值并将其传递给循环外的 customerNumber 变量。我尝试了一些类似数组列表和数组的东西,但是在将值传递给我想要的变量时遇到了麻烦。在此先感谢并为我可怕的noobishness道歉......我是编程新手......这是我到目前为止所得到的:
import java.util.ArrayList;
public class Bank{
public void addCustomer(String name, int telephone, String email, String profession) {
ArrayList customerList = new ArrayList();
Customer customer = new Customer();
customerList.add(customer);
}
}
public class Customer{
private String name;
private int telephone;
private String email;
private String profession;
private int customerNumber;
public Customer() {
}
}
public class Menu {
Scanner sc = new Scanner(System.in);
Bank bank = new Bank();
private void createCustomer() {
String name, email, profession;
int telephone, customerNumber;
System.out.println("Enter the customer's number: ");
name = sc.nextLine();
System.out.println("Enter the customer's telephone: ");
telephone = sc.nextInt();
System.out.println("Enter the customer's email: ");
email = sc.nextLine();
System.out.println("Enter the customer's profession: ");
profession = sc.nextLine();
bank.addCustomer(name, telephone, email, profession);
}
}