這段代碼將成爲我的終點....它運行良好現在(有點)但沒有得到正確的結果....當從示例文件中輸入7267881時說,這是無效但是,對於其他文件中 它給人的錯誤:程序沒有返回正確的結果和編譯錯誤
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The import src cannot be resolved
at Account.<init>(Account.java:1)
at AcccountArray.main(AcccountArray.java:45)
代碼:
import java.io.File;
import java.util.Scanner;
public class AcccountArray {
public static void main(String[] args)
{
//Scan the file and save account details to array
File file = new File ("customers.txt");
System.out.println("Path : " + file.getAbsolutePath());
try{
Scanner scanner = new Scanner(new File("customers.txt"));
String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];
for(int i=0;i<Account.length;i++)
{
Account[i][0]=scanner.nextLine();
//System.out.println(Account[i][0]);
Account[i][1]=scanner.nextLine();
Account[i][2]=scanner.nextLine();
//System.out.println(Account[i][2]);
}
scanner.close();
Scanner userinput = new Scanner(System.in);
System.out.println("Please enter account number: ");
String accountNumber = userinput.next();
int matchindex = 0;
Boolean match = false;
for (int k =0;k<Account.length;k++)
{
if(Account[k][1].equals(accountNumber))
{
match = true;
matchindex = k;
}
}
if(match)
{
Account ac = new Account();
ac.toString(Account[matchindex][0], Account[matchindex][1], Account[matchindex][2]);
System.out.println("Enter 'D' for deposite\nEnter 'W' for withdrawal\nEnter 'Q' for quit");
Scanner transaction = new Scanner(System.in);
String type = transaction.next();
Scanner ammount = new Scanner(System.in);
switch (type) {
case "D":
System.out.println("Enter the ammount : ");
float diposit = ammount.nextFloat();
float curent = Float.valueOf(Account[matchindex][2]);
System.out.println("New balance = "+(curent+diposit));
break;
case "W":
System.out.println("Enter the ammount : ");
float withdrawal = ammount.nextFloat();
float balance = Float.valueOf(Account[matchindex][2]);
System.out.println("New balance = "+(balance-withdrawal));
break;
case "Q":
System.out.println("Exit");
break;
default:
System.out.println("Invalid transaction");
}
}
else
{
System.out.println("Invalid user account number");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import src.String;
public class Account
{
public String toString(String name,String account,String balance)
{
System.out.println("Customer name :\t\t "+name);
System.out.println("Account Number :\t "+ account);
System.out.println("Current Balance :\t $"+ balance);
return null;
}
}
測試文件
4
John Anderson
4565413
250.00
Louise Carter
2323472
1250.45
Paul Johnson
7267881
942.81
Sarah Wilson
0982377
311.26
如果您不告訴我們正確的結果應該是什麼樣子,很難幫助您。 – nhgrif
使用與類名* *相同的標識符,對於查看代碼的外部人可能會有點誤導。 'Account'? – ChiefTwoPencils
@BobbyDigital權利,順便說一句,帳戶類是完全沒用的。雖然看起來不是String [] [],他應該使用Account []。 – Ingo