본문 바로가기
Project/Study | etc

Cat 클래스 만들기

by 코젼 2022. 6. 23.
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
반응형

댓글