# 학생 관리 ## 문제 학생 정보(학번, 이름, 평점)를 출력하고, 이름을 통해 학생을 검색하는 프로그램이 준비되어있다. 이 코드의 ArrayList<Student> 클래스를 HashMap<String, Student>로 변경하여 동일한 동작을 만드시오. (해시맵의 키는 이름으로 할 것) ## 입력 예 ``` 홍길동 ``` ## 출력 예 ``` 학번: 1 이름: 임꺽정 평균: 3.34 ===================== 학번: 2 이름: 이순신 평균: 4.26 ===================== 학번: 3 이름: 홍길동 평균: 3.67 ===================== 학번: 4 이름: 김유신 평균: 3.95 ===================== 3, 홍길동, 3.67 ``` ## 뼈대코드 ``` import java.util.ArrayList; public class Main { public static void main(String[] args) { // input String keyword = args[0]; // array list ArrayList<Student> students = new ArrayList<Student>(); students.add(new Student(1, "임꺽정", 3.34)); students.add(new Student(2, "이순신", 4.26)); students.add(new Student(3, "홍길동", 3.67)); students.add(new Student(4, "김유신", 3.95)); // print for (Student s : students) { s.prettyPrint(); } // search for (Student s : students) { if (keyword.equals(s.getName())) { System.out.println(s.toString()); } } } } class Student { private int number; private String name; private double gpa; public Student(int number, String name, double gpa) { this.number = number; this.name = name; this.gpa = gpa; } public String getName() { return name; } public String toString() { return String.format("%d, %s, %.2f", number, name, gpa); } public void prettyPrint() { System.out.printf("학번: %d\n", number); System.out.printf("이름: %s\n", name); System.out.printf("평균: %.2f\n", gpa); System.out.println("====================="); } } ```
관련 강의로 이동

코드: java 1.8

public class Main { public static void main(String[] args) { } }

입력

정답이 궁금하다면? 코드를 제출해보세요!