Gun 클래스 (메인메소드 없음)
private String model;
private int bullet;
private final int MAX_BULLET = 15;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getBullet() {
return bullet;
}
public void setBullet(int bullet) {
this.bullet = bullet;
}
public void reload(int bullet) {
if(this.bullet == MAX_BULLET) {
return;
}
this.bullet += bullet;
this.bullet = (this.bullet > MAX_BULLET) ? MAX_BULLET : this.bullet;
}
public void shoot() {
if(bullet == 0) {
return;
}
bullet--;
}
Soldier 클래스 (메인메소드 없음)
SoldierMain 클래스 (메인메소드 설정)
Soldier soldier = new Soldier();
soldier.reload(10);
soldier.shoot();
System.out.println(soldier.getBullet());