Java
[TIL] 231019 첫 프로젝트 시작....클래스 이해해보기....클래스의 생김새와 기능(메소드)
studymode
2023. 10. 19. 22:58
클래스 생김새
//클래스 만들기
class 클래스명 {
public String 메소드명 ( ) { => 클래스 생성 (변수와 메소드 포함)
기능 }
}
public class 페이지이름 {
public static void main(String[] args) {
//클래스 호출하기
클래스명 인스턴스명 = new 클래스명(); => 메소드로 인스턴스 생성
인스턴스 명. 메소드명 () => 클래스의 기능 사용
}
프로젝트 위해 짜본 코드....
이게 맞는걸까효....? ㅎ....
(일단 웃어^^^^^웃는자가 일류니까)
class CreateMenu {
public String createMenu (String menuName, String menuDes) {
String namedes = ( menuName + "\n" + ":"+ menuDes+ "\n");
return namedes;
}
}
public class MenuList {
public static void main(String[] args) {
CreateMenu cr = new CreateMenu();
System.out.println("-------< 커피 >-------");
//커피 음료 리스트에 담기
String americano = cr.createMenu("아메리카노", "샷이 들어간 커피 음료");
System.out.println(americano);
String cafelatte = cr.createMenu("카페라떼", "우유에 샷이 들어간 커피 음료");
System.out.println(cafelatte);
String cafemocha = cr.createMenu("카페모카", "초코맛이 나는 커피 음료");
System.out.println(cafemocha);
//System.out.println(americano + cafelatte + cafemocha);
System.out.println("-------< 탄산음료 >-------");
//탄산음료 리스트에 담 컾
String kola = cr.createMenu("콜라", "검정 탄산음료");
System.out.println(kola);
String sprite = cr.createMenu("스프라이트", "무색 탄산음료");
System.out.println(sprite);
String lemonade = cr.createMenu("레몬에이드", "레몬맛 탄산음료");
System.out.println(lemonade);
}
}