嗨,大家好,請幫助我!對不起,如果標題中不夠清楚。我的英語非常有限。我無法在此列表中添加其他信息給聯繫人
所以我有這樣的Java代碼,它有這樣的工作:
MENU:
1 - 註冊用戶信息
2 - 註冊客戶航空公司里程
3 - 列出特定客戶的英里數
4 - 列出客戶最多和最少里程
5 - 列出每個人的名字和他們的英里
我可以註冊自己的信息就好了,但我似乎無法登記他們英里出於某種原因。
我輸入1鍵入信息,輸入完所有內容後,它回到菜單,我輸入2,它應該做的是:請求一個我之前已經註冊過的人的名字,然後我註冊他們的航空公司里程。但是當我輸入2來做這件事時,它甚至不讓我輸入一個名字。它只是給
這將是有問題的代碼塊中的「其他」條件「找不到名稱」:
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;
而且這是在情況下,整個代碼任何你想取看。
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();
}
}
對不起,我的英文和佔用你的時間。我非常感謝這裏的幫助。我(非常)新來這個。
也http://stackoverflow.com/q/13102045/4125191 – RealSkeptic
見我不知道這是問題。否則我會用搜索。對不起。 –