From e2b8790aea706f03b4ef3a3fcb7b77d1fef34840 Mon Sep 17 00:00:00 2001 From: kshiraishi Date: Mon, 7 Jul 2025 14:17:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?B095=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kshiraishi/src/B095.java | 173 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 kshiraishi/src/B095.java diff --git a/kshiraishi/src/B095.java b/kshiraishi/src/B095.java new file mode 100644 index 0000000..a30974a --- /dev/null +++ b/kshiraishi/src/B095.java @@ -0,0 +1,173 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +/** + * カラオケ大会 + * + * 下記2点についてコメントいただけると幸いです。
+ * 1.クラスの分け方
+ * 2.クラス内での変数の使い方
+ * + * @author kshiraishi + * @version 1 + */ + +public class B095 { + /** + * データ保持クラス + * @param participantCount 参加人数(歌う人数) + * @param songLength 課題曲の長さ(小節数) + * @param correctPitche 課題曲の各小節の正しい音程のリスト + * @param sungPitch 各歌唱者の歌唱音程のリストのリスト + * @param scoreList 各歌唱者の点数のリスト + */ + public class KaraokeData { + + private final int participantCount; + private final int songLengs; + private final List correctPitche; + private final List> sungPitch; + private List scoreList; + + public KaraokeData(int participantCount, int songLengs, List correctPitche, + List> sungPitch) { + this.participantCount = participantCount; + this.songLengs = songLengs; + this.correctPitche = correctPitche; + this.sungPitch = sungPitch; + this.scoreList = new ArrayList<>(); + } + + public int getParticipantCount() { + return participantCount; + } + + public int getSongLengs() { + return songLengs; + } + + public List getCorrectPitche() { + return correctPitche; + } + + public List> getSungPitch() { + return sungPitch; + } + + public List getScoreList() { + return scoreList; + } + } + + /** + * スコア計算のクラス
+ * 1人の1曲でのスコアを計算 + * + */ + public class ScoreCalculator { + /** + * 正しい音程のリストとうたった音程のリストから点数を計算 + * @param correctPitche 正しい音程のリスト + * @param personalPitche 歌唱者のうたった音程のリスト + * @return 計算したスコアを返す(0を下回ったら0を返す) + */ + public int calcScore(List correctPitche, List personalPitche) { + int score = 100; + int errorHz = 0; + int penaltyScore = 0; + + for (int i = 0; i < personalPitche.size(); i++) { + errorHz = calculatePitchErrorHz(correctPitche.get(i), personalPitche.get(i)); + penaltyScore = calculatePenalty(errorHz); + score -= penaltyScore; + } + if(score < 0) { + return 0; + } + return score; + } + + // 誤差Hz(絶対値)を返す + public int calculatePitchErrorHz(int correctPitche, int personalPitche) { + int pitcheError = 0; + if (correctPitche != personalPitche) { + pitcheError = Math.abs(correctPitche - personalPitche); + } + return pitcheError; + } + + // 減点メソッド + public int calculatePenalty(int pitcheError) { + if (pitcheError <= 5) { + return 0; + } else if (pitcheError <= 10) { + return 1; + } else if (pitcheError <= 20) { + return 2; + } else if (pitcheError <= 30) { + return 3; + } else { + return 5; + } + } + } + /** + * 最大の点数を探索するクラス + * + */ + public class SearchMaxScore { + public int serchMaxScore(List scoreList) { + return Collections.max(scoreList); + } + } + + /** + * メインクラス + * + */ + public static void main(String[] args) { + B095 karaoke = new B095(); + KaraokeData dto = karaoke.initialize(); + ScoreCalculator calculator = karaoke.new ScoreCalculator(); + SearchMaxScore search = karaoke.new SearchMaxScore(); + + // 人数分スコアを計算しscoreListに格納 + for (int i = 0; i < dto.getParticipantCount(); i++) { + dto + .getScoreList() + .add(calculator.calcScore(dto.getCorrectPitche(), dto.getSungPitch().get(i))); + } + // maxスコアを探索し表示 + System.out.print(search.serchMaxScore(dto.getScoreList())); + + } + + // 初期化メソッド + public KaraokeData initialize() { + Scanner sc = new Scanner(System.in); + int participantCount = sc.nextInt(); + int songLengs = sc.nextInt(); + + List correctPitche = new ArrayList<>(); + for (int s = 0; s < songLengs; s++) { + correctPitche.add(sc.nextInt()); + } + + List> sungPitch = new ArrayList<>(); + for (int p = 0; p < participantCount; p++) { + List personSungPitch = new ArrayList<>(); + for (int s = 0; s < songLengs; s++) { + personSungPitch.add(sc.nextInt()); + } + sungPitch.add(personSungPitch); + } + + KaraokeData dto = new B095.KaraokeData( + participantCount, songLengs, correctPitche, sungPitch); + sc.close(); + return dto; + } + +} -- GitLab From c3f62fb76e92e357b2bf48dd2b7f38dcaf3601ae Mon Sep 17 00:00:00 2001 From: kshiraishi Date: Mon, 7 Jul 2025 15:59:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?B095=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kshiraishi/src/B095.java | 173 ----------------------- kshiraishi/src/B095/B095.java | 71 ++++++++++ kshiraishi/src/B095/KaraokeData.java | 49 +++++++ kshiraishi/src/B095/MaxScoreFinder.java | 14 ++ kshiraishi/src/B095/ScoreCalculator.java | 56 ++++++++ 5 files changed, 190 insertions(+), 173 deletions(-) delete mode 100644 kshiraishi/src/B095.java create mode 100644 kshiraishi/src/B095/B095.java create mode 100644 kshiraishi/src/B095/KaraokeData.java create mode 100644 kshiraishi/src/B095/MaxScoreFinder.java create mode 100644 kshiraishi/src/B095/ScoreCalculator.java diff --git a/kshiraishi/src/B095.java b/kshiraishi/src/B095.java deleted file mode 100644 index a30974a..0000000 --- a/kshiraishi/src/B095.java +++ /dev/null @@ -1,173 +0,0 @@ -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Scanner; - -/** - * カラオケ大会 - * - * 下記2点についてコメントいただけると幸いです。
- * 1.クラスの分け方
- * 2.クラス内での変数の使い方
- * - * @author kshiraishi - * @version 1 - */ - -public class B095 { - /** - * データ保持クラス - * @param participantCount 参加人数(歌う人数) - * @param songLength 課題曲の長さ(小節数) - * @param correctPitche 課題曲の各小節の正しい音程のリスト - * @param sungPitch 各歌唱者の歌唱音程のリストのリスト - * @param scoreList 各歌唱者の点数のリスト - */ - public class KaraokeData { - - private final int participantCount; - private final int songLengs; - private final List correctPitche; - private final List> sungPitch; - private List scoreList; - - public KaraokeData(int participantCount, int songLengs, List correctPitche, - List> sungPitch) { - this.participantCount = participantCount; - this.songLengs = songLengs; - this.correctPitche = correctPitche; - this.sungPitch = sungPitch; - this.scoreList = new ArrayList<>(); - } - - public int getParticipantCount() { - return participantCount; - } - - public int getSongLengs() { - return songLengs; - } - - public List getCorrectPitche() { - return correctPitche; - } - - public List> getSungPitch() { - return sungPitch; - } - - public List getScoreList() { - return scoreList; - } - } - - /** - * スコア計算のクラス
- * 1人の1曲でのスコアを計算 - * - */ - public class ScoreCalculator { - /** - * 正しい音程のリストとうたった音程のリストから点数を計算 - * @param correctPitche 正しい音程のリスト - * @param personalPitche 歌唱者のうたった音程のリスト - * @return 計算したスコアを返す(0を下回ったら0を返す) - */ - public int calcScore(List correctPitche, List personalPitche) { - int score = 100; - int errorHz = 0; - int penaltyScore = 0; - - for (int i = 0; i < personalPitche.size(); i++) { - errorHz = calculatePitchErrorHz(correctPitche.get(i), personalPitche.get(i)); - penaltyScore = calculatePenalty(errorHz); - score -= penaltyScore; - } - if(score < 0) { - return 0; - } - return score; - } - - // 誤差Hz(絶対値)を返す - public int calculatePitchErrorHz(int correctPitche, int personalPitche) { - int pitcheError = 0; - if (correctPitche != personalPitche) { - pitcheError = Math.abs(correctPitche - personalPitche); - } - return pitcheError; - } - - // 減点メソッド - public int calculatePenalty(int pitcheError) { - if (pitcheError <= 5) { - return 0; - } else if (pitcheError <= 10) { - return 1; - } else if (pitcheError <= 20) { - return 2; - } else if (pitcheError <= 30) { - return 3; - } else { - return 5; - } - } - } - /** - * 最大の点数を探索するクラス - * - */ - public class SearchMaxScore { - public int serchMaxScore(List scoreList) { - return Collections.max(scoreList); - } - } - - /** - * メインクラス - * - */ - public static void main(String[] args) { - B095 karaoke = new B095(); - KaraokeData dto = karaoke.initialize(); - ScoreCalculator calculator = karaoke.new ScoreCalculator(); - SearchMaxScore search = karaoke.new SearchMaxScore(); - - // 人数分スコアを計算しscoreListに格納 - for (int i = 0; i < dto.getParticipantCount(); i++) { - dto - .getScoreList() - .add(calculator.calcScore(dto.getCorrectPitche(), dto.getSungPitch().get(i))); - } - // maxスコアを探索し表示 - System.out.print(search.serchMaxScore(dto.getScoreList())); - - } - - // 初期化メソッド - public KaraokeData initialize() { - Scanner sc = new Scanner(System.in); - int participantCount = sc.nextInt(); - int songLengs = sc.nextInt(); - - List correctPitche = new ArrayList<>(); - for (int s = 0; s < songLengs; s++) { - correctPitche.add(sc.nextInt()); - } - - List> sungPitch = new ArrayList<>(); - for (int p = 0; p < participantCount; p++) { - List personSungPitch = new ArrayList<>(); - for (int s = 0; s < songLengs; s++) { - personSungPitch.add(sc.nextInt()); - } - sungPitch.add(personSungPitch); - } - - KaraokeData dto = new B095.KaraokeData( - participantCount, songLengs, correctPitche, sungPitch); - sc.close(); - return dto; - } - -} diff --git a/kshiraishi/src/B095/B095.java b/kshiraishi/src/B095/B095.java new file mode 100644 index 0000000..274701b --- /dev/null +++ b/kshiraishi/src/B095/B095.java @@ -0,0 +1,71 @@ +package B095; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * カラオケ大会 + * + * 下記2点についてコメントいただけると幸いです。
+ * 1.クラスの分け方
+ * 2.クラス内での変数の使い方
+ * + * @author kshiraishi + * @version 1 + */ + +/** + * データ保持クラス + * @param participantCount 参加人数(歌う人数) + * @param songLength 課題曲の長さ(小節数) + * @param correctPitch 課題曲の各小節の正しい音程のリスト + * @param sungPitch 各歌唱者の歌唱音程のリストのリスト + * @param scoreList 各歌唱者の点数のリスト + */ + +public class B095 { + + public static void main(String[] args) { + B095 karaoke = new B095(); + KaraokeData karaokeData = karaoke.initialize(); + ScoreCalculator calculator = new ScoreCalculator(); + MaxScoreFinder search = new MaxScoreFinder(); + + // 人数分スコアを計算しscoreListに格納 + for (int i = 0; i < karaokeData.getParticipantCount(); i++) { + karaokeData + .getScoreList() + .add(calculator.calcScore(karaokeData.getCorrectPitch(), karaokeData.getSungPitch().get(i))); + } + // maxスコアを探索し表示 + System.out.print(search.serchMaxScore(karaokeData.getScoreList())); + + } + + // 初期化メソッド + public KaraokeData initialize() { + Scanner sc = new Scanner(System.in); + int participantCount = sc.nextInt(); + int songLength = sc.nextInt(); + + List correctPitch = new ArrayList<>(); + for (int s = 0; s < songLength; s++) { + correctPitch.add(sc.nextInt()); + } + + List> sungPitch = new ArrayList<>(); + for (int p = 0; p < participantCount; p++) { + List personSungPitch = new ArrayList<>(); + for (int s = 0; s < songLength; s++) { + personSungPitch.add(sc.nextInt()); + } + sungPitch.add(personSungPitch); + } + + KaraokeData karaokeData = new KaraokeData( + participantCount, songLength, correctPitch, sungPitch); + sc.close(); + return karaokeData; + } + +} diff --git a/kshiraishi/src/B095/KaraokeData.java b/kshiraishi/src/B095/KaraokeData.java new file mode 100644 index 0000000..ab0273d --- /dev/null +++ b/kshiraishi/src/B095/KaraokeData.java @@ -0,0 +1,49 @@ +package B095; +import java.util.ArrayList; +import java.util.List; + +/** + * データ保持クラス + * @param participantCount 参加人数(歌う人数) + * @param songLength 課題曲の長さ(小節数) + * @param correctPitch 課題曲の各小節の正しい音程のリスト + * @param sungPitch 各歌唱者の歌唱音程のリストのリスト + * @param scoreList 各歌唱者の点数のリスト + */ +public class KaraokeData { + + private final int participantCount; + private final int songLength; + private final List correctPitch; + private final List> sungPitch; + private List scoreList; + + public KaraokeData(int participantCount, int songLength, List correctPitch, + List> sungPitch) { + this.participantCount = participantCount; + this.songLength = songLength; + this.correctPitch = correctPitch; + this.sungPitch = sungPitch; + this.scoreList = new ArrayList<>(); + } + + public int getParticipantCount() { + return participantCount; + } + + public int getSongLength() { + return songLength; + } + + public List getCorrectPitch() { + return correctPitch; + } + + public List> getSungPitch() { + return sungPitch; + } + + public List getScoreList() { + return scoreList; + } +} diff --git a/kshiraishi/src/B095/MaxScoreFinder.java b/kshiraishi/src/B095/MaxScoreFinder.java new file mode 100644 index 0000000..8cb57b7 --- /dev/null +++ b/kshiraishi/src/B095/MaxScoreFinder.java @@ -0,0 +1,14 @@ +package B095; + +import java.util.Collections; +import java.util.List; + +/** + * 最大の点数を探索するクラス + * + */ +public class MaxScoreFinder { + public int serchMaxScore(List scoreList) { + return Collections.max(scoreList); + } +} \ No newline at end of file diff --git a/kshiraishi/src/B095/ScoreCalculator.java b/kshiraishi/src/B095/ScoreCalculator.java new file mode 100644 index 0000000..053abe5 --- /dev/null +++ b/kshiraishi/src/B095/ScoreCalculator.java @@ -0,0 +1,56 @@ +package B095; + +import java.util.List; + +/** + * スコア計算のクラス
+ * 1人の1曲でのスコアを計算 + * + */ +public class ScoreCalculator { + /** + * 正しい音程のリストとうたった音程のリストから点数を計算 + * @param correctPitch 正しい音程のリスト + * @param personalPitch 歌唱者のうたった音程のリスト + * @return 計算したスコアを返す(0を下回ったら0を返す) + */ + public int calcScore(List correctPitch, List personalPitch) { + int score = 100; + int errorHz = 0; + int penaltyScore = 0; + + for (int i = 0; i < personalPitch.size(); i++) { + errorHz = calculatePitchErrorHz(correctPitch.get(i), personalPitch.get(i)); + penaltyScore = calculatePenalty(errorHz); + score -= penaltyScore; + } + if(score < 0) { + return 0; + } + return score; + } + + // 誤差Hz(絶対値)を返す + public int calculatePitchErrorHz(int correctPitch, int personalPitch) { + int pitchError = 0; + if (correctPitch != personalPitch) { + pitchError = Math.abs(correctPitch - personalPitch); + } + return pitchError; + } + + // 減点メソッド + public int calculatePenalty(int pitchError) { + if (pitchError <= 5) { + return 0; + } else if (pitchError <= 10) { + return 1; + } else if (pitchError <= 20) { + return 2; + } else if (pitchError <= 30) { + return 3; + } else { + return 5; + } + } +} \ No newline at end of file -- GitLab