diff --git a/kkanazawa/src/WinningResult2.java b/kkanazawa/src/WinningResult2.java new file mode 100644 index 0000000000000000000000000000000000000000..2a770e50c339ea390344373f781cb7843c69ca29 --- /dev/null +++ b/kkanazawa/src/WinningResult2.java @@ -0,0 +1,68 @@ +package paiza.src; + +import java.util.Scanner; + +/** + * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. + * + * @author 金澤継心 + */ +public class WinningResult2 { + + /** + * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. + * + */ + public static void main(final String[] args) { + Scanner sc = new Scanner(System.in); + + final int applicantNumber = sc.nextInt(); + final int prizeAnumber = sc.nextInt(); + final int prizeBnumber = sc.nextInt(); + sc.close(); + + outputWinningResult(applicantNumber, prizeAnumber, prizeBnumber); + } + + /** + * 応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. + * + * @param applicantNumber 応募者の人数 + * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 + * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 + */ + public static void outputWinningResult(final int applicantNumber, final int prizeAnumber, + final int prizeBnumber) { + + for (int currentNumber = 1; currentNumber <= applicantNumber; currentNumber++) { + final boolean isAwin = isWinning(currentNumber, prizeAnumber); + final boolean isBwin = isWinning(currentNumber, prizeBnumber); + + // isAwin isBwinの値から応募者がどの賞に当選したか分岐 + if (isAwin && isBwin) { + System.out.println("AB"); + } else if (isAwin && !isBwin) { + System.out.println("A"); + } else if (!isAwin && isBwin) { + System.out.println("B"); + } else { + System.out.println("N"); + } + } + } + + /** + * 応募者の番号と賞に割り当てられた番号から、その応募者が当選したかどうかをbool値で返す. + * + * @param currentNumber 当選判定の対象となる応募者番号 + * @param prizeNumber 賞に割り当てられた番号 + * @return 当選条件を満たす場合、trueを返す. 当選条件を満たさない場合、falseを返す + */ + public static boolean isWinning(final int currentNumber, final int prizeNumber) { + // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす + if (currentNumber % prizeNumber == 0) { + return true; + } + return false; + } +}