Frog is cry
MVC모델(수정필요) 본문
DAO
package MVC.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import MVC.dto.StudentVO;
public class ScoreDAO {
//국영수
public final int SUBJECT_SIZE = 3;
public Scanner sc = new Scanner(System.in);
private ArrayList<StudentVO> arStudent = null;
private ArrayList<Integer> arScore = null;
// 과목이 더 추가될수도 있기 떄문에 동적인 ArrayList가 나와줌 ★★
// 매번 초기화 되어야 하기때문에 null을 줌
private HashMap<StudentVO, ArrayList<Integer>> smsMap = new HashMap<>();
public void join() {
String isQuit = "";
do {
System.out.println("============[학생정보 입력(종료는 q)]============");
System.out.println("이름 :");
String name = sc.nextLine();
System.out.println("나이 :");
int age = sc.nextInt();
StudentVO std = new StudentVO(name, age);
arStudent = new ArrayList<>();
arScore = new ArrayList<>();
arStudent.add(std);
System.out.println("국어 영어 수학 점수를 입력하세요.\n");
for (int i = 0; i < SUBJECT_SIZE; i++) {
arScore.add(Integer.parseInt(sc.next()));
}
smsMap.put(std, arScore);
System.out.println("종료?");
sc.nextLine(); // 점수 입력 후 엔터 상쇄
isQuit = sc.nextLine();
}while(isQuit.intern() != "q");
}
public void list(HashMap<StudentVO, ArrayList<Integer>> db) {
System.out.println("=====[가입목록]=====");
Set<Entry<StudentVO, ArrayList<Integer>>> set = db.entrySet();
Iterator<Map.Entry<StudentVO, ArrayList<Integer>>> iter = set.iterator();
while(iter.hasNext()) {
iter.next().getKey().show();
}
}
public void search() {
}
public void update() {
}
public void delete() {
}
}
DTO
package MVC.dto;
import MVC.dao.Student;
public class StudentVO implements Student{
private String name;
private int age;
private int number;
private static int seq;
public StudentVO() {;}
public StudentVO(String name, int age) {
this.name = name;
this.age = age;
this.number = ++seq;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getNumber() {
return number;
}
public void show() {
System.out.println("번호 : " + this.number + "/이름 : " + name + "/나이 : " + age + "살"
);
}
}
VIEW
package MVC.view;
import MVC.dao.ScoreDAO;
public class View {
public static void main(String[] args) {
new ScoreDAO().join();
}
}
'JAVA > 복습' 카테고리의 다른 글
시간 구하기 예제 (0) | 2020.07.30 |
---|---|
스레드 (0) | 2020.07.29 |
컬렉션 프레임워크 (Hash) (0) | 2020.07.29 |
컬렉션 프레임워크(Array List) (0) | 2020.07.29 |
Set (0) | 2020.07.29 |
Comments