我的教授給了我下面的代碼。如果語句代碼問題
public static void main(String[] args) {
Customer customer;
Transaction transaction;
double withdrawalAmount = 0;
boolean finished = false;
while (finished == false)
{
// Menu Display and Get user input
int inputInt = 0;
while (inputInt == 0)
{
inputInt = displayMenuAndGetInput();
// if the input is out of range
if ((inputInt < 1) || (inputInt > 8))
{
System.out.println("\nThe input is out of range!");
System.out.println();
inputInt = 0;
}
} //end while
// switch to correspondence function
switch (inputInt)
{
case 1:
customer = createPersonalCustomer();
System.out.println("\nThe Personal customer has been created: \n" + newPC.toString());
customers.add(customer);
break;
case 2:
customer = createCommercialCustomer();
System.out.println("\nThe Commercial customer has been created: \n" + newCC.toString());
customers.add(customer);
break;
case 3:
transaction = recordTransaction();
if(transaction != null)
System.out.println("\nThe Transaction has been created: \n" + trans.toString());
else
System.out.println("\nThe ID could not be found.");
break;
case 4:
withdrawalAmount = makeWithdrawal();
if(withdrawalAmount > 0)
System.out.println("\nAmount withdrawn from this account: " + moneyFormat.format(acct.getMakeWithdrawal()) + "\n");
else
System.out.println("\nThe ID could not be found.");
break;
case 5:
displayCustomer();
break;
case 6:
displayCustomerSummary();
break;
case 7:
displayGrandSummary();
break;
case 8:
// exit
finished = true;
break;
default:
System.out.println("Invalid Input!");
break;
} // end switch
} // end while
}
我應該採取以下代碼
// Create a new Transaction
public static Transaction recordTransaction(){}
,使一個循環,在以下情況下工作:
輸入客戶ID,如果客戶ID不匹配在數組中,生成情況3時讀出的錯誤並顯示主菜單。如果客戶ID有效,則用戶在下面輸入輸入信息。
下面是我的代碼
public static Transaction recordTransaction(){
System.out.println("Enter the customer ID to create the transaction > ");
long customerID = scan.nextLong();
for (Customer c : customers) {
if (c.getCustomerID() == customerID) {
if (trans != null) {
System.out.println("\nEnter the weight of gold > ");
Transaction.goldWt = scan.nextDouble();
System.out.println("\nEnter the weight of platinum > ");
Transaction.platinumWt = scan.nextDouble();
System.out.println("\nEnter the weight of silver > ");
Transaction.silverWt = scan.nextDouble();
}
}
return null;
}
Anywho,我這運行多種方式,要麼我的代碼將接受無效和有效的客戶ID,否則它不會接受無效或有效的客戶ID 。 我知道我可能忽略了一些東西,這就是爲什麼我拼命地要求論壇的幫助。在編程方面我有強迫症的傾向,這是我的第一個java類,所以我對這門語言不太熟悉。過去兩天我一直在困擾這個問題。請幫忙。
這是有道理的。自從我之前已經打電話給我之後,我的印象就是這樣,我不必再打電話給他。 – ComplexVolcano 2013-03-07 15:56:26
目前尚不清楚「接受」是什麼意思。 「不接受任何東西」意味着您收到「無法找到身份證」的消息。無論您提供的客戶ID是什麼?
您應該提供方法createPersonalCustomer()的代碼。 – dotvav 2013-03-07 16:16:57
是的,輸出狀態:「無法找到ID。」對於任何提供的ID。我不遵循你的第二條語句「你應該提供方法createPersonalCustomer()的代碼。」 – ComplexVolcano 2013-03-07 16:25:51