我刚刚开始这项任务,而且我正在编写交易功能,但我已经迷失了自己。
说明是如果公司的一名成员已经开始新的交易而收银员必须输入交易代码然后输入付款类型:
1 - purchase
2 - payment on negative balance
0 - transaction complete (to close out the transaction)
ca - cash payment/purchase
cr - credit payment/purchase.
逻辑是程序必须检查事务方法,然后检查相对于该代码的支付类型,然后才能进行任何类型的处理。但Eclipse并不喜欢我试图在布尔检查中使用int
。
我最初的方法是public double getTransaction()
,但我认为这可能是错的,所以我拿出了double
并留下了一个空白区域,直到我弄清楚"类型"我应该真的在使用。
private String name; //instance variable that holds the customer's name
private int accountNumber; //instance variable that holds the customer's account number
private double transactionCode; //instance variable that holds the account transaction code
private String paymentType; //instance variable that holds the type of payment for the transaction
private double beginningBalance; //instance variable that holds the customer's beginning balanceprivate double currentBalance; //instance variable that holds the customer's current account balance
private double endBalance; //instance variable that holds the customer's end balance after a transaction
private double creditLimit; //instance variable that holds the limit on the customer's account (per transaction, is what we are going to assume)
private int numberPurchases; //instance variable that holds the number of purchases made by the customer
private int numberTransactions; //instance variable that holds the number of transactions made on the customer's account (purchase/payment/denied purchase, etc..)
private double costOfPurchase; //instance variable that holds the cost of the purchase
private double totalPurchaseSum; //instance variable that holds the total sum of the customer's purchase
private double totalPaymentAmount; //instance variable that holds the amount of the payment made by the customer
private double totalPayments; //instance variable that holds the total number of payments made by the customer
private double totalPenalty; //instance variable that holds the total amount of the penalty owed to the company by the customer
//method that gets the type of transaction being processed on the account
public double getTransaction()
{
if (transactionCode.equals("1")) //if a purchase is being made
{
if (paymentType.equals("ca")) //and if the purchase is being made in cash
return endBalance = ;
else if (paymentType.equals("cr")) //else if the purchase is being made in credit
return creditLimit = getCreditLimit(creditLimit);
}
if (transactionCode = 2) //if a payment is being made
{
if (paymentType.equals("ca") //and if the payment is being made in cash
return endBalance = getEndBalance();
else if (paymentType.equals("cr")) //else if the payment is being made in credit
}
if (transactionCode = 0) //if the current transaction on the account is complete
{
System.out.println("TRANSACTION COMPLETED. THANK YOU FOR YOUR PATRONAGE.")
return;
}
}
答案 0 :(得分:0)
我不确定你在问什么?应该从这个方法返回什么?你想恢复最终的平衡吗?如果是这样,如果交易完成,它不会只为零吗?
此外,您的应用程序存在一些问题。首先,在if语句中,您要分配变量,而不是进行比较。 java中的等于运算符是' ==',但这适用于基本类型。当您比较字符串(或任何对象)时,请确保使用'等于'方法。此外,返回时无需分配endBalance变量。你可以返回getEndBalance();