알맹이의 개수를 알려주는 getCount()
와 기계의 현재 상태를 알려 주는 getState()
메소드는 이미 만들었다.
→ 보고서를 출력하는 메소드와 각 뽑기 기계의 위치를 알려주는 필드만 추가하면 된다.
public class GumballMachine {
// 기타 인스턴스 변수
String location;
public GumballMachine(String location, int count) {
// 기타 생성자 코드
this.location = location;
}
public String getLocation() {
return location;
}
// 기타 메소드
}
public class GumballMonitor {
GumballMachine machine;
public GumballMonitor(GumballMachine machine) {
this.machine = machine;
}
public void report() {
System.out.println("Gumball Machine: " + machine.getLocation());
System.out.println("Current inventory: " + machine.getCount() + " gumballs");
System.out.println("Current state: " + machine.getState());
}
}
public class GumballMachineTestDrive {
public static void main(String[] args) {
int count = 0;
if (args.length < 2) {
System.out.println("GumballMachine <name> <inventory>");
System.exit(1);
}
count = Integer.parseInt(args[1]);
GumballMachine gumballMachine = new GumballMachine(args[0], count);
// 기타 코드
monitor.report();
}
}
추가적으로 CEO가 뽑기 기계를 원격으로 모니터링 하고 싶어한다.
→ 원격 프록시를 이용해 해결해보자!
GumballMachine
클래스와 데이터를 주고받는다.