public class Member
{
private String name;
private String alias;
public int balance;
/**
* Constructor for objects of class Member
*/
public Member(String fullName, String nickname)
{
this.name = fullName;
this.alias = nickname;
this.balance = 0;
}
public void setBalance(int account)
{
if(account > 0)
{
balance = balance + account;
}
else
{
System.out.println("You have not entered a valid number");
}
}
}
import java.util.ArrayList;
public class Lan
{
private ArrayList<Member> members;
public Lan()
{
members = new ArrayList<Member>();
}
public void addMember(Member newMember)
{
if(balance >= 200)
{
this.members.add(newMember);
}
else
{
System.out.println("You dont have enough money to enter");
}
}
}
在Member
類,我得到了一個平衡點,在那裏你把成員「錢」的平衡,並在Lan
類,我希望它如果成員的餘額= 200,則可以輸入Lan「將成員添加到陣列中」。我無法使餘額字段按照它的樣子行事,並將其導入Lan
類。的Java BlueJ的類會員/ LAN
if(balance> = 200)'if(newMember.balance> = 200)'if? – Tom
非常感謝湯姆,它的工作! :D – pikkstup