如何在数组中存储新的客户机信息,并能够在java中再次查看它?

如何在数组中存储新的客户机信息,并能够在java中再次查看它?,java,arrays,class,user-input,Java,Arrays,Class,User Input,这是我的任务。 我必须创建一个显示菜单的应用程序,并根据用户的选择执行相应的操作。这是我的菜单应该包括的内容 1. add a new client - keep it as the current client 2. find a client with a given name - keep it as the current client 3. add a service for the current client 4. print the current client's balanc

这是我的任务。 我必须创建一个显示菜单的应用程序,并根据用户的选择执行相应的操作。这是我的菜单应该包括的内容

1. add a new client - keep it as the current client
2. find a client with a given name - keep it as the current client
3. add a service for the current client
4. print the current client's balance
5. print the current client's history of services
6. print all the clients' balances
7. exit [save all the data to a file option and retrieve it back when the program starts] 
对于添加新客户机的选项,我在main中创建了一个方法

public static void main_addNewClient() {
String name, email, vin, make;
int year;
input.nextLine();
System.out.print("Enter your first name: ");
name = input.nextLine();
System.out.print("Enter your email: ");
email = input.nextLine();
System.out.print("Enter vin: ");
vin = input.nextLine();
System.out.print("Enter make: ");
make = input.nextLine();
System.out.print("Enter year: ");
year = input.nextLine();

但是我如何获取所有用户输入并将其存储到一个数组中呢?我不确定从何处开始。

首先,在main中声明一个ArrayList,它将包含所有客户端

 ArrayList clients = new ArrayList<Client>();   
import java.util.ArrayList;
导入java.util.List;
导入java.util.Scanner;
公开课练习{
//列表以存储您的客户
静态列表客户端=新的ArrayList();
静态类客户端{
公共字符串名称;
公共字符串电子邮件;
公共字符串制作;
公共国际年;
公共字符串vin;
客户端(字符串名称、字符串电子邮件、字符串制作、整数年、字符串vin){
this.name=名称;
this.email=电子邮件;
make=make;
今年=年;
这个。vin=vin;
}
}
公共静态void main_addNewClient(){
字符串名称、电子邮件、vin、make;
国际年;
扫描仪输入=新扫描仪(System.in);
input.nextLine();
System.out.print(“输入您的名字:”);
name=input.nextLine();
System.out.print(“输入您的电子邮件:”);
email=input.nextLine();
系统输出打印(“输入vin:”;
vin=input.nextLine();
系统输出打印(“输入make:”);
make=input.nextLine();
系统输出打印(“输入年份:”;
年份=input.nextInt();
//使用您获得的输入创建新的客户端对象
客户c=新客户(名称、电子邮件、品牌、年份、vin);
//将客户端添加到列表中
添加(c);
}
}

这就是你想知道的吗?这个练习有很多内容。我认为您首先需要构建一个菜单,询问用户想要做什么:添加新客户端、查找客户端等。

我认为它与Android无关。看起来像是大学/学校的常规Java练习。可以使用
列表
(并在其中搜索以查找现有客户)或
地图
(可以按键请求特定客户)。是的,我已经创建了菜单(我已将其添加到帖子中)。它只是存储我遇到问题的客户的基本信息。
public static void main_addNewClient() {
String name, email, vin, make;
int year;
input.nextLine();
System.out.print("Enter your first name: ");
name = input.nextLine();
System.out.print("Enter your email: ");
email = input.nextLine();
System.out.print("Enter vin: ");
vin = input.nextLine();
System.out.print("Enter make: ");
make = input.nextLine();
System.out.print("Enter year: ");
year = input.nextLine();
 ArrayList clients = new ArrayList<Client>();   
   Client client = new Client(name,email,vin,year,make);
   clients.add(client);
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Exercise {

// list to store your clients
static List<Client> clients = new ArrayList<>();

static class Client{
    public String name;
    public String email;
    public String make;
    public int year;
    public String vin;

    Client(String name, String email, String make, int year, String vin){
        this.name = name;
        this.email = email;
        this.make = make;
        this.year = year;
        this.vin = vin;
    }
}

public static void main_addNewClient() {
    String name, email, vin, make;
    int year;
    Scanner input = new Scanner(System.in);
    input.nextLine();
    System.out.print("Enter your first name: ");
    name = input.nextLine();
    System.out.print("Enter your email: ");
    email = input.nextLine();
    System.out.print("Enter vin: ");
    vin = input.nextLine();
    System.out.print("Enter make: ");
    make = input.nextLine();
    System.out.print("Enter year: ");
    year = input.nextInt();

    // create new client object with input you got
    Client c = new Client(name, email, make, year, vin);
    // add client to the list
    clients.add(c);
}
}