Advertisement
Guest User

Untitled

a guest
May 28th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5.  
  6. //데이터만 저장 할 클래스!!!!!!(Dto,Bean,Vo <-데이터만 저장할때 보통사용)
  7. class ScoreDto
  8. {
  9.     private int seq;
  10.     private String name;
  11.     private int kor;
  12.     private int eng;
  13.     private int mat;
  14.     private int total;
  15.     private float avg;
  16.     //출력
  17.     public void output()
  18.     {
  19.         System.out.printf("%d %s %d %d %d %d %.2f \n",
  20.                 seq, name, kor, eng, mat, total, avg);
  21.     }
  22.     //총점,평균 클래스
  23.     public void calc()
  24.     {
  25.         total = kor+eng+mat; //총점
  26.         avg=total/3.0f;         //평균
  27.     }
  28.     //마우스 오른쪽->source->Generate Getters and Setters
  29.     public int getSeq() {
  30.         return seq;
  31.     }
  32.     public void setSeq(int seq) {
  33.         this.seq = seq;
  34.     }
  35.     public String getName() {
  36.         return name;
  37.     }
  38.     public void setName(String name) {
  39.         this.name = name;
  40.     }
  41.     public int getKor() {
  42.         return kor;
  43.     }
  44.     public void setKor(int kor) {
  45.         this.kor = kor;
  46.     }
  47.     public int getEng() {
  48.         return eng;
  49.     }
  50.     public void setEng(int eng) {
  51.         this.eng = eng;
  52.     }
  53.     public int getMat() {
  54.         return mat;
  55.     }
  56.     public void setMat(int mat) {
  57.         this.mat = mat;
  58.     }
  59.     public int getTotal() {
  60.         return total;
  61.     }
  62.     public void setTotal(int total) {
  63.         this.total = total;
  64.     }
  65.     public float getAvg() {
  66.         return avg;
  67.     }
  68.     public void setAvg(float avg) {
  69.         this.avg = avg;
  70.     }    
  71. }
  72. //입력 클래스
  73. class ScoreManager
  74. {
  75.     ArrayList<ScoreDto> list = new ArrayList<ScoreDto>();
  76.     BufferedReader reader =
  77.             new BufferedReader(new InputStreamReader(System.in));
  78.    
  79.     public void append() throws NumberFormatException, IOException
  80.     {
  81.         ScoreDto dto = new ScoreDto(); //객체 하나 생성
  82.         //이름,과목 함수생성
  83.         System.out.print("이름 : ");
  84.         dto.setName(reader.readLine());
  85.         System.out.print("국어 : ");
  86.         dto.setKor(Integer.parseInt(reader.readLine()));
  87.         System.out.print("영어 : ");
  88.         dto.setEng(Integer.parseInt(reader.readLine()));
  89.         System.out.print("수학 : ");
  90.         dto.setMat(Integer.parseInt(reader.readLine()));
  91.         dto.calc();//
  92.        
  93.         //리스트 추가하기
  94.         list.add(dto);
  95.        
  96.     }
  97.     public void output() throws IOException
  98.     {
  99.         for(int i=0; i<list.size(); i++)
  100.             list.get(i).output();
  101.     }
  102.     //메뉴 내용
  103.     void menuDisplay()
  104.     {
  105.         System.out.println("1. 추가");
  106.         System.out.println("2. 출력");
  107.         System.out.println("3. 수정");
  108.         System.out.println("4. 삭제");
  109.         System.out.println("5. 검색");
  110.         System.out.println("6. 정렬");
  111.         System.out.println("0. 종료");
  112.     }
  113.     public void run() throws IOException
  114.     {
  115.         //menuDisplay 선택창
  116.         int menu;
  117.         while(true)//무한루트 반복
  118.         {
  119.             menuDisplay();
  120.             System.out.println("선택 : ");
  121.             menu = Integer.parseInt(reader.readLine());
  122.             switch(menu)
  123.             {
  124.                 case 1: append(); break;
  125.                 case 2: output(); break;
  126.                 case 0: return; //함수를 종료해야한다
  127.                 default: System.out.println("존재하지 않는 메뉴입니다");
  128.             }
  129.         }
  130.     }
  131. }
  132. //메인
  133. public class ScoreTest {
  134.     public static void main(String[] args) throws IOException {
  135.         ScoreManager mgr = new ScoreManager();
  136.         mgr.run();
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement