길동이와 철수의 신장과 체중구하기

ColinSong·2020년 11월 4일
0

Java문제풀이

목록 보기
3/4
post-thumbnail

public class Human {
    private String name;
    private int height;
    private int weight;

    public Human(String name, int height, int weight) {
      this.name = name;
      this.height = height;
      this.weight = weight;
    }


    public String getName() {
      return name;
    }

    public int getheight() {
      return height;
    }

    public int getWeight() {
      return weight;
    }

    void gainWeight(int w) {
      weight += w;
    }

    void reduceWeigth(int w) {
      weight -= w;
    }
  }
  public class HumanTester {

      public static void main(String[] args) {
          Human gildong = new Human("길동", 170, 60);
          Human chulsu = new Human("철수", 166, 72);

          gildong.gainWeight(3); //길동이 3키로 쪘다.
          chulsu.reduceWeigth(5); //철수가 5키로 빠졌다.

          System.out.println("이름 : " + gildong.getName());
          System.out.println("키 : " + gildong.getheight() + "cm");
          System.out.println("몸무게 : " + gildong.getWeight() + "kg");

          System.out.println();

          System.out.println("이름 : " + chulsu.getName());
          System.out.println("키 : " + chulsu.getheight() + "cm");
          System.out.println("몸무게 : " + chulsu.getWeight() + "kg");


      }
}

References

profile
안녕하세요:)

0개의 댓글