저는 두 클래스를 먼저 하나의 멤버와 두 번째 클래스로 작성했습니다. 그리고 멤버 클래스에서 객체를 생성 할 수있는 메소드를 작성했으며 멤버 클래스에 Store라는 유형의 필드 스토어를 작성하려고하고 있는데 멤버가 입력 한 스토어에 대한 참조를 저장하고 싶습니다. 어떤이 어떻게 나에게 말했다 :. 인수, 당신이 현재있는 저장소 개체에 대한 포인터로 전달 될 필요가있다) memberRegister을 (사실자기 참조 포인터로 나를 도와주세요
, 스토어 오브젝트가 말할 수 있어야합니다 멤버 개체 "point to me". 즉, Store 객체에는 자체에 대한 포인터가 필요합니다. 하지만 난하지 않았다 그것을
이 회원 클래스입니다
private int pinNumber;
private String name, id;
private Store store;
/**
* Constructor for objects of class Member
*/
public Member(String name, String id, int pinNumber, Store store)
{
// initialise instance variables
this.name = name;
this.id = id;
this.pinNumber = pinNumber;
checkId();
checkPinNumber();
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
private void checkId()
{
// put your code here
int length;
length = id.length();
if (length > 10){
System.out.println("lentgh must be at 10 ");
}
}
private void checkPinNumber()
{
int length;
length = id.length();
if ((length > 4) && (length < 4)){
System.out.println("lentgh must be at 4");
}
클래스 저장소
private String storeName;
private int total;
private Member member;
/**
* Constructor for objects of class Store
*/
public Store(String storeName, int total)
{
// initialise instance variables
this.storeName = storeName;
this.total = total;
}
/**
*
*/
public String getStoreName()
{
return storeName;
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public Member memberRegister(String name, String id, int pinNumber)
{
// put your code here
Member member;
member = new Member(name, id, pinNumber)
return member;
}
'이'충분하지 않습니까? 나는. '새 멤버를 반환하십시오 (name, id, pinNumber, this); '? –
@Kerrek 생성자가 저장소를 개인 구성원 변수에 저장하는 경우이 작업은 수행하지 않습니다. –