我不明白我的家庭作业在说什么
I could not understand what my homework says
预计是Accountclass,其中User对象,余额,最小余额
limit,账号,iban number信息被保存,所有的accessor和mutator
class 的方法已创建。此外,你应该开发一种方法,
在此 class 内执行电子转帐交易,并将接收方帐户对象作为
范围。您还需要创建一个执行余额检查的方法
需要执行 Eft 交易。
我的一部分作业需要我创建上面留下的两种方法。我创建了方法,但我不知道它是否足够工作。请你检查一下好吗?
请您不要理解,因为我希望您编写实际代码,请告诉我哪里错了。暂时感谢
public class Account {
private User user;
private int balance;
private int minBalanceLim;
private String accNum;
private String IBAN;
public User getUser() {
return user;
}
public int getBalance() {
return balance;
}
public int getMinBalanceLim() {
return minBalanceLim;
}
public String getAccNum() {
return accNum;
}
public String getIBAN() {
return IBAN;
}
public void setUser(User user) {
this.user = user;
}
public void setBalance(int balance) {
this.balance = balance;
}
public void setMinBalanceLim(int minBalanceLim) {
this.minBalanceLim = minBalanceLim;
}
public void setAccNum(String accNum) {
this.accNum = accNum;
}
public void setIBAN(String IBAN) {
this.IBAN = IBAN;
}
public void eft(Account receiver, Account sender, int amount)
{
if(sender.balanceCheck(sender, amount))
{
sender.setBalance(sender.getBalance()-amount);
receiver.setBalance(receiver.getBalance()+amount);
}
else
{
System.out.println(sender.getUser().getName() + " has not enough money");
}
}
public boolean balanceCheck(Account sender, int amount)
{
return sender.getBalance()>= amount;
}
public boolean balanceCheck(int amount) {
// so we changed it here, as you have the getMinBalanceLim it should be used
return this.getBalance() - amount >= this.getMinBalanceLim();
}
public void etf(Account receiver, int amount) {
if (this.balanceCheck(amount))
{
// set the balance of the receiver
receiver.setBalance(receiver.getBalance() + amount);
// set the balance of the user
this.setBalance(this.getBalance() - amount);
}
else
{
// handle your error (user has no money, he broke)
}
}
然后您可以在尝试时引用该对象:
// ... inside your main method
a1.etf(a2, 23);
预计是Accountclass,其中User对象,余额,最小余额 limit,账号,iban number信息被保存,所有的accessor和mutator class 的方法已创建。此外,你应该开发一种方法, 在此 class 内执行电子转帐交易,并将接收方帐户对象作为 范围。您还需要创建一个执行余额检查的方法 需要执行 Eft 交易。
我的一部分作业需要我创建上面留下的两种方法。我创建了方法,但我不知道它是否足够工作。请你检查一下好吗? 请您不要理解,因为我希望您编写实际代码,请告诉我哪里错了。暂时感谢
public class Account {
private User user;
private int balance;
private int minBalanceLim;
private String accNum;
private String IBAN;
public User getUser() {
return user;
}
public int getBalance() {
return balance;
}
public int getMinBalanceLim() {
return minBalanceLim;
}
public String getAccNum() {
return accNum;
}
public String getIBAN() {
return IBAN;
}
public void setUser(User user) {
this.user = user;
}
public void setBalance(int balance) {
this.balance = balance;
}
public void setMinBalanceLim(int minBalanceLim) {
this.minBalanceLim = minBalanceLim;
}
public void setAccNum(String accNum) {
this.accNum = accNum;
}
public void setIBAN(String IBAN) {
this.IBAN = IBAN;
}
public void eft(Account receiver, Account sender, int amount)
{
if(sender.balanceCheck(sender, amount))
{
sender.setBalance(sender.getBalance()-amount);
receiver.setBalance(receiver.getBalance()+amount);
}
else
{
System.out.println(sender.getUser().getName() + " has not enough money");
}
}
public boolean balanceCheck(Account sender, int amount)
{
return sender.getBalance()>= amount;
}
public boolean balanceCheck(int amount) {
// so we changed it here, as you have the getMinBalanceLim it should be used
return this.getBalance() - amount >= this.getMinBalanceLim();
}
public void etf(Account receiver, int amount) {
if (this.balanceCheck(amount))
{
// set the balance of the receiver
receiver.setBalance(receiver.getBalance() + amount);
// set the balance of the user
this.setBalance(this.getBalance() - amount);
}
else
{
// handle your error (user has no money, he broke)
}
}
然后您可以在尝试时引用该对象:
// ... inside your main method
a1.etf(a2, 23);