我的教授给了我下面的代码。如果语句代码问题
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