728x90
반응형
💾MainClass 클래스
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
Cat c = new Cat();
c.set_name("검둥이");
c.set_color("black");
Scanner s = new Scanner(System.in);
System.out.println(c.get_name() + "의 정보!\n털 색 : " + c.get_color());
System.out.println(c.get_name() + "의 호기심의 정도를 입력하세요.");
c.set_curio(s.nextInt());
System.out.println(c.curio_rank());
}
}
💾Cat클래스
public class Cat {
String name; // 이름
String color; // 털 색상
int curio = 0; // 호기심 정도
void set_name(String n) {
name = n;
}
void set_color(String c) {
color = c;
}
void set_curio(int cu) {
curio = cu;
}
String get_name() {
return name;
}
String get_color() {
return color;
}
String curio_rank() {
String str = null;
if(curio < 20) {
str = "무서워요! 도망치기";
}
else if(curio < 40) {
str = "경계중! 털 곤두 세우기";
}
else {str = "야옹! 인사해요";}
return str;
}
}
728x90
반응형
'Project > Study | etc' 카테고리의 다른 글
JAVA의 정석 3판 - 객체지향 프로그래밍 연습문제(3) (0) | 2022.06.24 |
---|---|
JAVA의 정석 3판 - 객체지향 프로그래밍 연습문제 (0) | 2022.06.23 |
성적 관리 프로그램 (0) | 2022.06.23 |
명품 자바 프로그래밍 에센셜 실습문제 3장 (0) | 2022.06.21 |
명품 자바 프로그래밍 에센셜 실습문제 2장 (0) | 2022.06.20 |
댓글