수업

+13 사용자 정의 클래스, 변수 설정 예제

hs_developer 2022. 5. 19. 17:10
데이터형

기본형: 정수, 실수, 논리, 문자 → 자바에서 지원하는 데이터형
참조형: 배열(같은 데이터형 모아서 관리), 클래스(다른 데이터형 모아서 관리)

클래스 용도

: 데이터만 모아서 관리 (데이터형 클래스)
→ ~DTO, ~VO(★중요), ~Bean

: 기능만 모아서 관리 (액션 클래스)
→ ~DAO(★중요), ~Manager, ~Service(BI)(★중요)

: 데이터 + 기능 = 혼합 클래스 → 조립
→ ~Model, ~Controller(★중요), ~Action

 

 

class FoodCategory{ // 클래스: 다른 데이터 모으기
	int cno; // 카테고리 번호
	String poster;
	String title;
	String subject;
}


public class 사용자정의클래스 {
	
    public static void main(String[] args) {

        FoodCategory f1 = new FoodCategory();

        f1.cno = 1;
        f1.poster = "aaa";
        f1.title = "aaa";
        f1.subject = "aaa";

        FoodCategory f2 = new FoodCategory();

        f2.cno = 2;
        f2.poster = "bbb";
        f2.title = "bbb";
        f2.subject = "bbb";

        // 여러 개 있을 때
        FoodCategory[] food = new FoodCategory[10]; // 맛집 10곳


    }
}

 

 


UML p27

 

변수 설정 예제

 

 

Class Movie
{
    String title;
    String subtitle;
    String date;
    String genre;
    String nation;
    String age;
    String runningTime;
    int rate;
    int boxOffice;
    String description;
}

 

 

 

Class Article
{
    String poster;
    String title;
    String content;
    String date;
    String company;
}

 

 

 

 

Class FoodCategory
{
    int cno;
    String poster;
    String title;
    String subject;
}

 

 

Class Restaurant
{
    String name;
    double rate;
    String address;
    String telephone;
    String mainDish;
    String price;
    String parking;
    String time;
    String menu;
}

 

 

 

Class Recipe
{
    String poster;
    String title;
    String uploader;
    int rate;
    int view;
}

 

Class Music
{
    int ranking;
    String poster;
    String title;
    String artist;
    String album;
    int likes;
    int upDown;
}

 

 

 

String Store
{
    String poster;
    int sale;
    String menu;
    String price;
}

 

 

Class Theater
{
    String poster
    String title
    boolean onAir;
    String genre;
    String date;
    String location;
    String actor;
    String age;
    String runningTime;
}

 

 

내일 답 확인 후 수정