Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';t在此java列表中向联系人添加其他信息_Java_Switch Statement - Fatal编程技术网

我能';t在此java列表中向联系人添加其他信息

我能';t在此java列表中向联系人添加其他信息,java,switch-statement,Java,Switch Statement,嗨,伙计们,请帮帮我!如果标题不够清楚,我很抱歉。我的英语非常有限 所以我有这个java代码,它必须像这样工作: 菜单: 1-注册客户信息 2-登记客户航空里程 3-列出特定客户的里程 4-列出里程数最多和最少的客户 5-列出每个人的姓名和里程 我可以很好地注册他们的信息,但出于某种原因,我似乎无法注册他们的里程 我输入1来输入信息,在我输入所有信息后,它会返回到菜单,我输入2,它应该做的是:询问我之前已经注册过的人的姓名,然后我会注册他们的航空里程。但是,当我输入2这样做时,它甚至不允许我输入

嗨,伙计们,请帮帮我!如果标题不够清楚,我很抱歉。我的英语非常有限

所以我有这个java代码,它必须像这样工作:

菜单:

1-注册客户信息

2-登记客户航空里程

3-列出特定客户的里程

4-列出里程数最多和最少的客户

5-列出每个人的姓名和里程

我可以很好地注册他们的信息,但出于某种原因,我似乎无法注册他们的里程

我输入1来输入信息,在我输入所有信息后,它会返回到菜单,我输入2,它应该做的是:询问我之前已经注册过的人的姓名,然后我会注册他们的航空里程。但是,当我输入2这样做时,它甚至不允许我输入名称。它只会转到“else”条件“找不到名称”

这将是有问题的代码块:

        case 2: 
            System.out.println("customer name: ");
            name = scanner.nextLine();
            d=0;

            while ( d < c-1 && name!=data1[d])
            {d++;}

            if (name==data1[d])
            {
                System.out.println("enter airline miles of " +data1[d]);
                airMiles = scanner.nextDouble();

                airMile[d] = airMile[d]+airMiles;
            }

            else 

            {System.out.println("name not found");}
            break;
案例2:
System.out.println(“客户名称:”);
name=scanner.nextLine();
d=0;
而(d
这是全部代码,以防你们想看一下

import java.util.Scanner;
public class Vetor49eng {
public static void main(String[] args) {
    Scanner scanner = new Scanner (System.in);

    int op, c, d, posLast, posFirst;
    String name, filler;
    double airMiles;
    String [] data1 = new String [50];
    String [] data2 = new String [50];
    String [] data3 = new String [50];
    double [] airMile = new double [50];

    for (c=0; c<5; c++)
    {airMile[c]=0.;}
    c=0;

    do
    {
        System.out.println("1. register customer info");
        System.out.println("2. register customer airline miles");
        System.out.println("3. show miles of a customer");
        System.out.println("4. show the names of the customer with the most miles and least miles");
        System.out.println("5. show all their names and their miles");
        System.out.println("6. exit");
        op = scanner.nextInt();

        switch (op)
        {
        case 1: 
            if(c<50)
            {
                System.out.println("customer " +(c+1) +": ");
                filler = scanner.nextLine(); //IT ALWAYS SKIP THIS FIRST LINE SO I CREATED THIS FILLER

                System.out.println("name: ");
                data1[c] = scanner.nextLine();

                System.out.println("address: ");
                data2[c] = scanner.nextLine();

                System.out.println("telephone number: ");
                data3[c] = scanner.nextLine();

                c++;
            }

            else

            {System.out.println("archive complete");}
            break;

        case 2: 
            System.out.println("customer name: ");
            name = scanner.nextLine();
            d=0;

            while ( d < c-1 && name!=data1[d])
            {d++;}

            if (name==data1[d])
            {
                System.out.println("enter airline miles of " +data1[d]);
                airMiles = scanner.nextDouble();

                airMile[d] = airMile[d]+airMiles;
            }

            else 

            {System.out.println("name not found");}
            break;

        case 3:
            System.out.println("customer name: ");
            name = scanner.nextLine();
            d=0;

            while (d<c-1 && name!=data1[d])
            {d++;}

            if (name==data1[d])

            {System.out.println("miles of " +data1[d] +": " +airMile[d]);}

            else

            {System.out.println("name not found");}
            break;

        case 4: 
            d=1;
            posLast=0;
            posFirst=0;

            while (d<=c)
            { if (airMile[d] > airMile[posFirst])
            { posFirst=d; }
            else
            { if (airMile[d] < airMile[posLast])
            { posLast = d; }
            }
            d++;
            }
            System.out.println("customer with the most mileage:");
            System.out.println("name: " +data1[posFirst]);
            System.out.println("address: " +data2[posFirst]);
            System.out.println("phone number: " +data3[posFirst]);
            System.out.println("miles: " +airMile[posFirst]);
            System.out.println();
            System.out.println("customer with the least mileage:");
            System.out.println("name: " +data1[posLast]);
            System.out.println("address: " +data2[posLast]);
            System.out.println("phone number: " +data3[posLast]);
            System.out.println("miles: " +airMile[posLast]);
            break;

        case 5: 
            System.out.println("list");
            for (d=0; d<c; d++)
            {System.out.println(d +" - " +data1[d] +": " +airMile[d]);}
            break;

        case 6:
            System.out.println("have a nice flight");
            break;
        default: 
            System.out.println("option not available");
        }
    }
    while (op!=6);
    System.out.println();
}
}
import java.util.Scanner;
公共级Vetor49eng{
公共静态void main(字符串[]args){
扫描仪=新的扫描仪(System.in);
int op,c,d,posLast,posFirst;
字符串名称、填充符;
双倍航空里程;
字符串[]数据1=新字符串[50];
字符串[]数据2=新字符串[50];
字符串[]数据3=新字符串[50];
双倍[]航空里程=新双倍[50];

对于(c=0;c这个代码块有一些东西。当您在这里比较字符串时,您不想使用==。这两个字符串不是同一个对象,虽然它们可能具有相同的值,但它们是完全不同的对象,因此在您尝试验证输入时会给您一个错误

对于要使用.equals()的字符串(如果大小写很重要),或者要使用.equalsIgnoreCase()的字符串(如果不关心大小写)

现在,对于您的跳过问题,您需要在此处使用=scanner.next()。使用nextLine将丢弃任何条目,并自动使条目为空

         case 2:                    
                System.out.print("customer name: ");
                name = scanner.next();
                d = 0;

                while (d < c - 1 && !name.equalsIgnoreCase(data1[d])) {
                    d++;
                }

                if (name.equalsIgnoreCase(data1[d])) {
                    System.out.println("enter airline miles of " + data1[d]);
                    airMiles = scanner.nextDouble();

                    airMile[d] = airMile[d] + airMiles;
                } else {
                    System.out.println("name not found");
                }
                break;
案例2:
系统输出打印(“客户名称:”);
name=scanner.next();
d=0;
while(d
另请看,我不知道这是问题所在。否则我会使用搜索。对不起,你是一个该死的生命救世主!谢谢你,伙计!!别担心,伙计。一定要看看你被标记为受骗的人。那将是非常有益的。