본문 바로가기
java&eclipse 코딩 알고리즘/20231213

성적표 ScoreList

by 몽상크리에이터 2023. 12. 13.

package com.tjoeun.score;

 

import java.text.DecimalFormat;

import java.util.ArrayList;

import java.util.Objects;

 

public class ScoreList {

// 점수 정보를 기억할 ArrayList를 만든다.

private ArrayList<ScoreVO> scoreList = new ArrayList<ScoreVO>();

 

// 기본 생성자 생략

 

// getters & setters

public ArrayList<ScoreVO> getScoreList() {

return scoreList;

}

public void setScoreList(ArrayList<ScoreVO> scoreList) {

this.scoreList = scoreList;

}

@Override

public String toString() {

//

String str = "";

str += "=========================================================\n";

str += " 번호 이름 java jsp spring 총점 평균 석차 \n";

str += "=========================================================\n";

for (int i = 0; i < scoreList.size(); i++) { //선택정렬

for (int j = i+1; j < scoreList.size(); j++) {

// i번째 학생의 총점이 다음 학생 j학생(i+1)보다 크면 j학생의 랭크를 1 증가시킨다 (내림차순)

if (scoreList.get(i).getTotal() > scoreList.get(j).getTotal()) {

scoreList.get(j).setRank(scoreList.get(j).getRank() + 1);

} else if (scoreList.get(i).getTotal() < scoreList.get(j).getTotal()) {

scoreList.get(i).setRank(scoreList.get(i).getRank() + 1);

} // getter로 데이터를 불러와서 setter로 수정하는 사용법을 기억하자

}

str += scoreList.get(i) + "\n";

 

// 석차 계산

}

 

str += "=========================================================\n";

 

return str;

}

 

@Override

public int hashCode() {

return Objects.hash(scoreList);

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

ScoreList other = (ScoreList) obj;

return Objects.equals(scoreList, other.scoreList);

}

 

public void addScore(ScoreVO score) {

scoreList.add(score);

}

 

}

'java&eclipse 코딩 알고리즘 > 20231213' 카테고리의 다른 글

성적표 ScoreList 출력  (0) 2023.12.13
성적표 ScoreMain  (0) 2023.12.13
성적표 ScoreVO  (0) 2023.12.13