From d82d683200907806586b5b14263c21ecadd3a614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Mon, 4 Jul 2022 12:48:49 +0900 Subject: [PATCH 1/9] =?UTF-8?q?C065=20=E6=95=B0=E5=AD=97=E3=81=82=E3=81=A6?= =?UTF-8?q?=E3=82=B2=E3=83=BC=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/test/C065_AnswerNumberTest.java | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 knoda/test/C065_AnswerNumberTest.java diff --git a/knoda/test/C065_AnswerNumberTest.java b/knoda/test/C065_AnswerNumberTest.java new file mode 100644 index 0000000..107ef17 --- /dev/null +++ b/knoda/test/C065_AnswerNumberTest.java @@ -0,0 +1,83 @@ +package hellojunit; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; + +@RunWith(Enclosed.class) +public class C065_AnswerNumberTest { + + public static class + ヒントの記号が大なり小なりスラッシュのみかつ正の整数が100以下のとき { + + List symbolList; + List numList; + + @Test + public void 出力が35になるテスト() { + symbolList = new ArrayList(Arrays.asList(">", "<", "/")); + numList = new ArrayList(Arrays.asList(30, 40, 5)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 35; + assertThat(actual, is(expected)); + } + + @Test + public void 出力が84になるテスト() { + symbolList = new ArrayList(Arrays.asList("/", "<", "/", ">")); + numList = new ArrayList(Arrays.asList(4, 90, 6, 77)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 84; + assertThat(actual, is(expected)); + } + } + + public static class + ヒントの記号が大なり小なりスラッシュ以外を含むとき { + + List symbolList; + List numList; + + @Test + public void 出力が0になるテスト1() { + symbolList = new ArrayList(Arrays.asList(">", "<", "/", "+")); + numList = new ArrayList(Arrays.asList(30, 40, 5, 4)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 0; + assertThat(actual, is(expected)); + } + + @Test + public void 出力が0になるテスト2() { + symbolList = new ArrayList(Arrays.asList("/", "<", "*", "/", ">")); + numList = new ArrayList(Arrays.asList(4, 90, 12, 6, 77)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 0; + assertThat(actual, is(expected)); + } + } + + public static class + ヒントが100以上の整数を含むとき { + + List symbolList; + List numList; + + @Test + public void 出力が0になるテスト() { + symbolList = new ArrayList(Arrays.asList("/", "<", "/", ">")); + numList = new ArrayList(Arrays.asList(20, 200, 5, 100)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 0; + assertThat(actual, is(expected)); + } + + } +} -- GitLab From cb51528a8bfdb099f94f66760fd155caec31868e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Mon, 4 Jul 2022 12:49:29 +0900 Subject: [PATCH 2/9] =?UTF-8?q?C065=20=E6=95=B0=E5=AD=97=E3=81=82=E3=81=A6?= =?UTF-8?q?=E3=82=B2=E3=83=BC=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/src/C065_AnswerNumber.java | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 knoda/src/C065_AnswerNumber.java diff --git a/knoda/src/C065_AnswerNumber.java b/knoda/src/C065_AnswerNumber.java new file mode 100644 index 0000000..87f2a85 --- /dev/null +++ b/knoda/src/C065_AnswerNumber.java @@ -0,0 +1,93 @@ +package hellojunit; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class C065_AnswerNumber { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + // ヒントの数を入力 + final int hintNum = scan.nextInt(); + + /* symbolList : 記号(<、>、/)が格納されているリスト + * numList : 整数が格納されているリスト + */ + final List symbolList = new ArrayList(); + final List numList = new ArrayList(); + + // 記号と整数を入力 + for (int hint = 0; hint < hintNum; hint++) { + symbolList.add(scan.next()); + numList.add(scan.nextInt()); + } + + final int answer = getAnswer(symbolList, numList); + System.out.println(answer); + scan.close(); + } + + // ヒントの条件を満たす整数を取得するメソッド + static int getAnswer(List symbolList, List numList) { + final List answerCandidateNumList + = hintCalculation(symbolList, numList); + + int answer = 0; + + // 整数がいくつ条件を満たしているか数える + for (Integer num : answerCandidateNumList) { + long numCount = answerCandidateNumList + .stream() + .filter(n -> n == num) + .count(); + + // 整数がすべての条件を満たしているとき + if (numCount == symbolList.size()) { + answer = num; + break; + } + } + return answer; + } + + // ヒントの条件を満たすための計算処理メソッド + static List hintCalculation(List symbolList, List numList) { + + // 1つでもヒントの条件を満たす整数を格納するリスト + final List answerCandidateNumList = new ArrayList(); + + for (int hint = 0; hint < symbolList.size(); hint++) { + for (int num = 1; num <= 100; num++) { + + // ヒントの記号が「>」「<」「/」のみのとき + if (symbolList.contains(">") || symbolList.contains("<") + || symbolList.contains("/")) { + + // ヒントの条件を満たしているかを判定 + if (symbolList.get(hint).equals(">")) { + if (num > numList.get(hint)) { + answerCandidateNumList.add(num); + } + } else if (symbolList.get(hint).equals("<")) { + if (num < numList.get(hint)) { + answerCandidateNumList.add(num); + } + } else if (symbolList.get(hint).equals("/")) { + if (num % numList.get(hint) == 0) { + answerCandidateNumList.add(num); + } + } + } else { + while (answerCandidateNumList.size() > 0) { + answerCandidateNumList.remove(0); + } + break; + } + } + } + return answerCandidateNumList; + } + +} -- GitLab From 5e97899f28b28ca851be62ef6f5c72227a8e074a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Mon, 4 Jul 2022 18:00:32 +0900 Subject: [PATCH 3/9] =?UTF-8?q?C065=20=E6=95=B0=E5=AD=97=E3=81=82=E3=81=A6?= =?UTF-8?q?=E3=82=B2=E3=83=BC=E3=83=A0=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/src/C065_AnswerNumber.java | 53 ++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/knoda/src/C065_AnswerNumber.java b/knoda/src/C065_AnswerNumber.java index 87f2a85..ac3d300 100644 --- a/knoda/src/C065_AnswerNumber.java +++ b/knoda/src/C065_AnswerNumber.java @@ -52,11 +52,11 @@ public class C065_AnswerNumber { return answer; } - // ヒントの条件を満たすための計算処理メソッド + // ヒントの記号によって取得方法を変えるメソッド static List hintCalculation(List symbolList, List numList) { // 1つでもヒントの条件を満たす整数を格納するリスト - final List answerCandidateNumList = new ArrayList(); + List answerCandidateNumList = new ArrayList(); for (int hint = 0; hint < symbolList.size(); hint++) { for (int num = 1; num <= 100; num++) { @@ -64,25 +64,11 @@ public class C065_AnswerNumber { // ヒントの記号が「>」「<」「/」のみのとき if (symbolList.contains(">") || symbolList.contains("<") || symbolList.contains("/")) { - - // ヒントの条件を満たしているかを判定 - if (symbolList.get(hint).equals(">")) { - if (num > numList.get(hint)) { - answerCandidateNumList.add(num); - } - } else if (symbolList.get(hint).equals("<")) { - if (num < numList.get(hint)) { - answerCandidateNumList.add(num); - } - } else if (symbolList.get(hint).equals("/")) { - if (num % numList.get(hint) == 0) { - answerCandidateNumList.add(num); - } - } + answerCandidateNumList = calculation( + symbolList.get(hint), numList.get(hint), + num, answerCandidateNumList); } else { - while (answerCandidateNumList.size() > 0) { - answerCandidateNumList.remove(0); - } + removeList(answerCandidateNumList); break; } } @@ -90,4 +76,31 @@ public class C065_AnswerNumber { return answerCandidateNumList; } + // ヒントの条件を満たすための計算処理メソッド + static List calculation(String symbol, int hintNum, + int num, List answerCandidateNumList) { + + // ヒントの条件を満たしているかを判定 + if (">".equals(symbol)) { + if (num > hintNum) { + answerCandidateNumList.add(num); + } + } else if ("<".equals(symbol)) { + if (num < hintNum) { + answerCandidateNumList.add(num); + } + } else if ("/".equals(symbol)) { + if (num % hintNum == 0) { + answerCandidateNumList.add(num); + } + } + return answerCandidateNumList; + } + + // リストの中身を削除するメソッド + static void removeList(List list) { + while (list.size() > 0) { + list.remove(0); + } + } } -- GitLab From 53c8a4b9aa4d0e963e8bf0b70b0a3bcbbf3a351d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Mon, 4 Jul 2022 18:01:13 +0900 Subject: [PATCH 4/9] =?UTF-8?q?C065=20=E6=95=B0=E5=AD=97=E3=81=82=E3=81=A6?= =?UTF-8?q?=E3=82=B2=E3=83=BC=E3=83=A0=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/src/C065_AnswerNumber.class | Bin 0 -> 3442 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 knoda/src/C065_AnswerNumber.class diff --git a/knoda/src/C065_AnswerNumber.class b/knoda/src/C065_AnswerNumber.class new file mode 100644 index 0000000000000000000000000000000000000000..123ca7f334f30bc4dfdd83fffbc0a621af717bf7 GIT binary patch literal 3442 zcma)8S#uLt8a-EPscpG2j*Jb$G6`UUEn`d|I01o)F%u9YLxO>TlK^e0Z8x;K6{+RK zS!W@$?~_>|Gg-*um!vAm17N6{nyPu5${)x>enZ}wNyxd~ZPXS{iYmMB_TBHE^L^)j zSO5Ly#=ihOf)5kegb@|{n=y(52}JM%`FUK$!35$Mk%L1m*os^N?Kqr34}K_3^9hXM zh+I7?=bn%zPqyG89Fw1M702bwi6jqsx&_bRS@}65=gvw;=bE6)!DJH(O(@E)p<+t9 znwFoL1n!3^r_Zanpu!S}?=fxD9Ttf8_MH?^MxCM|urhDj#*tcS(x@EQCoRq>CEc_I zI(whapVw#gK})x%2glutX-{Y6#uekPUbrx(mpywGB^5Mpo;KVOyZXFQ5!l%4@2t6| zHJCT6ZnkmUms8u#;WWAlxh_S}8^aHFHJP0n_WX`_-I&i3WVYsR$QQQa!k zEZsF7BHZ41K%=v4Un5L`a^t4(i9t~A6;*@xu%|k9ftErT^-usHoP}Jj!PRoe&)v($ zMCjJrOBe+b4N%$+XVW;EEb~_62{_G z-vr@|JGDx|c-)jK?i}4VwDYX5NMGJtrJ6N7h|L1`dCK`$#Z$dZ2Dml+9KR4~+wVAT)vf5|F~gm4iq(~I{IU&mY<|^-Uu*aceyiel8h(#I zX!s-kq~Xt~X?R1T6vG<+f;o2f@PAOlU-37(Y`nV~i`AnVb|b6d?-KnbX_lTbEXz4x zV`Uh;D`HE$9GyIG6l9*4DGLIv^-%e8NY*EEu2IolhlL>wYOd-UC4q>nH64CNO=mD? zmuoKXm7$li0&9ZoH!MiCsJ8Kf%P4x~jQ3rUV}Vt@fq29Bg*JMz$Ya7{^7&+?aMW4d zsu@S8WYNoo_b;l84xAdj*Kt0Do zdRknJ6sfB-di97$iRGFYml6xWv#3)wjFmvw5=Z{5tlBb=30%gT@>TeUWcVGoM{x~# zjdv`&9;!D}HM<}SD!Cd(v!J^M(XOs%d&$uRIAvO7E3hkY>=9kYNx0}N@j>^of>R4p zeVEa#nlE}$wB3_3aSUj|v0c7eRVIq%LuPtO9_!&Uo~!8=&EkIPQt?j>Z{doDz2M8Z zp?+yhd)B#N4CcL>#9OIP=>=+-*Q}*fAE|hszVeQ9p;i{qa^FBgtEgK$Cnu=wA}L0fl2=BGZ2zE61Y4TNcnJuv^spiS8JGj-KG`DL!eEPZH5@&?Y&k zc<6sPaEo5Hd!BdD51+k&&lltq<9sbh1Q~Vv$gW^g8B#iww&Hs@mPxK%Kv#qnDwRp5 zgKldk+3j^Np(n%Mx(G?%-@n*vC#eo)%XK_3Hjf0`_48=Hs4#~gUySm5dCMmrAgLXn zYL?LUViks&lo39J`$=zdWm*b5|>mvp?-~or22noV)Fy>TZr*5 zpgTmLd{P6tZ?aXm=Xi2$<|;N^LT9?`eH6D zEALu|pOm-Inu#u8BQMAN?XT*xZ{e=0obG8$$l4j)%B@_9(7vTV z^C47a9!j*XI{zB?2f!lDkFi=a4^otm;a#=~dU+e~;T@#N4ZLsyPtoQS8BTl)CGA-z literal 0 HcmV?d00001 -- GitLab From 76eb423dba57721a42cf74c017e3cfa8b1437de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Mon, 4 Jul 2022 18:01:47 +0900 Subject: [PATCH 5/9] =?UTF-8?q?C065=20=E6=95=B0=E5=AD=97=E3=81=82=E3=81=A6?= =?UTF-8?q?=E3=82=B2=E3=83=BC=E3=83=A0=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/test/C065_AnswerNumberTest.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/knoda/test/C065_AnswerNumberTest.java b/knoda/test/C065_AnswerNumberTest.java index 107ef17..1cf005d 100644 --- a/knoda/test/C065_AnswerNumberTest.java +++ b/knoda/test/C065_AnswerNumberTest.java @@ -80,4 +80,27 @@ public class C065_AnswerNumberTest { } } + + public static class 条件を満たす整数が一意でない { + List symbolList; + List numList; + + @Test + public void 出力が32と36の2つあるのに32のみが出力されるテスト() { + symbolList = new ArrayList(Arrays.asList(">", "<", "/")); + numList = new ArrayList(Arrays.asList(30, 40, 4)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 32; + assertThat(actual, is(expected)); + } + + @Test + public void 出力が15の倍数すべてがあるのに15のみが出力されるテスト() { + symbolList = new ArrayList(Arrays.asList("/", "/")); + numList = new ArrayList(Arrays.asList(3, 5)); + int actual = C065_AnswerNumber.getAnswer(symbolList, numList); + int expected = 15; + assertThat(actual, is(expected)); + } + } } -- GitLab From da04f8f080f7cbcfcc9c72c2d0c1a7a4e410a379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Wed, 6 Jul 2022 08:19:36 +0900 Subject: [PATCH 6/9] =?UTF-8?q?C018=20=E4=BD=95=E4=BA=BA=E5=89=8D=E4=BD=9C?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=81=AE=E5=95=8F=E9=A1=8C=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/src/C018_Recipe.java | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 knoda/src/C018_Recipe.java diff --git a/knoda/src/C018_Recipe.java b/knoda/src/C018_Recipe.java new file mode 100644 index 0000000..1370d02 --- /dev/null +++ b/knoda/src/C018_Recipe.java @@ -0,0 +1,89 @@ +package hellojunit; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +public class C018_Recipe { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + // foodstuffMap : レシピに書かれている食材とその個数が格納されるマップ + final Map foodstuffMap = new LinkedHashMap(); + + // レシピに書かれている食材の個数を入力 + int foodstuffOfRecipeNum = scan.nextInt(); + + // レシピに書かれているそれぞれの食材とその個数を入力 + for (int foodstuff = 0; foodstuff < foodstuffOfRecipeNum; foodstuff++) { + String foodstuffName = scan.next(); + int foodstuffNum = scan.nextInt(); + + if (foodstuffMap.containsKey(foodstuffName)) { + // 食材が重複している場合はその個数を更新する + foodstuffMap.replace(foodstuffName, foodstuffMap.get(foodstuffName) + foodstuffNum); + } else { + // 食材が重複していない場合は新たに食材とその個数をfoodstuffMapに格納する + foodstuffMap.put(foodstuffName, foodstuffNum); + } + } + + // haveFoodstuffMap : 自身が所持している食材とその個数が格納されるマップ + final Map haveFoodstuffMap = new LinkedHashMap(); + + // 自身が所持している食材の個数を入力 + int haveFoodstuffNum = scan.nextInt(); + + // 自身が所持しているそれぞれの食材とその個数を入力 + for (int foodstuff = 0; foodstuff < haveFoodstuffNum; foodstuff++) { + String foodstuffName = scan.next(); + int foodstuffNum = scan.nextInt(); + + if (haveFoodstuffMap.containsKey(foodstuffName)) { + // 食材が重複している場合はその個数を更新する + haveFoodstuffMap.replace(foodstuffName, haveFoodstuffMap.get(foodstuffName) + foodstuffNum); + } else { + // 食材が重複していない場合は新たに食材とその個数をfoodstuffMapに格納する + haveFoodstuffMap.put(foodstuffName, foodstuffNum); + } + } + + // 何人前のレシピを作ることができるかを取得する + int people = howManyService(foodstuffMap, haveFoodstuffMap); + System.out.println(people); + + scan.close(); + } + + // 何人前のレシピを作ることができるかを取得するメソッド + static int howManyService(final Map foodstuffMap, final Map haveFoodstuffMap) { + final Set foodstuffSet = foodstuffMap.keySet(); + + // foodstuffNumList : レシピに書かれているそれぞれの食材の個数が格納されるリスト + final List foodstuffNumList = new ArrayList(); + + // haveFoodstuffNumList : 自身が所持している食材がレシピに書かれている場合、その個数が格納されるリスト + final List haveFoodstuffNumList = new ArrayList(); + + if (haveFoodstuffMap.keySet().containsAll(foodstuffMap.keySet())) { + + int people = 10000; + for (String foodstuff : foodstuffSet) { + int foodstuffPeople = haveFoodstuffMap.get(foodstuff) / foodstuffMap.get(foodstuff); + if (people > foodstuffPeople) { + people = foodstuffPeople; + } + } + + return people; + + } else { + return 0; + } + } + +} -- GitLab From 55252dafb3ff2ea8cacb7962321a7f814d1d37b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Wed, 6 Jul 2022 08:20:13 +0900 Subject: [PATCH 7/9] =?UTF-8?q?C018=20=E4=BD=95=E4=BA=BA=E5=89=8D=E4=BD=9C?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=81=AE=E5=95=8F=E9=A1=8C=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/test/C018_RecipeTest.java | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 knoda/test/C018_RecipeTest.java diff --git a/knoda/test/C018_RecipeTest.java b/knoda/test/C018_RecipeTest.java new file mode 100644 index 0000000..b4fc8ae --- /dev/null +++ b/knoda/test/C018_RecipeTest.java @@ -0,0 +1,72 @@ +package hellojunit; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.Test; + +public class C018_RecipeTest { + + @Test + public void 出力が2になるテスト() { + Map foodstuffMap = new LinkedHashMap(); + Map haveFoodstuffMap = new LinkedHashMap(); + + foodstuffMap.put("supaisu", 5); + foodstuffMap.put("imo", 2); + foodstuffMap.put("niku", 2); + foodstuffMap.put("mizu", 3); + + haveFoodstuffMap.put("mizu", 7); + haveFoodstuffMap.put("imo", 4); + haveFoodstuffMap.put("ninjin", 10); + haveFoodstuffMap.put("unagi", 6); + haveFoodstuffMap.put("supaisu", 20); + haveFoodstuffMap.put("niku", 5); + + int actual = C018_Recipe.howManyService(foodstuffMap, haveFoodstuffMap); + int expected = 2; + assertThat(actual, is(expected)); + } + + @Test + public void 出力が3になるテスト() { + Map foodstuffMap = new LinkedHashMap(); + Map haveFoodstuffMap = new LinkedHashMap(); + + foodstuffMap.put("supaisu", 5); + foodstuffMap.put("imo", 2); + foodstuffMap.put("niku", 2); + foodstuffMap.put("mizu", 3); + + haveFoodstuffMap.put("mizu", 10); + haveFoodstuffMap.put("imo", 4); + haveFoodstuffMap.put("supaisu", 20); + haveFoodstuffMap.replace("imo", haveFoodstuffMap.get("imo") + 2); + haveFoodstuffMap.put("niku", 1); + haveFoodstuffMap.replace("niku", haveFoodstuffMap.get("niku") + 5); + + int actual = C018_Recipe.howManyService(foodstuffMap, haveFoodstuffMap); + int expected = 3; + assertThat(actual, is(expected)); + } + + @Test + public void 出力が0になるテスト() { + Map foodstuffMap = new LinkedHashMap(); + Map haveFoodstuffMap = new LinkedHashMap(); + + foodstuffMap.put("gohan", 1); + foodstuffMap.put("okazu", 1); + + haveFoodstuffMap.put("mizu", 10000); + + int actual = C018_Recipe.howManyService(foodstuffMap, haveFoodstuffMap); + int expected = 0; + assertThat(actual, is(expected)); + } + +} -- GitLab From 4695c1e3ed33e3af181625fabc068c7171507550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Wed, 6 Jul 2022 11:32:43 +0900 Subject: [PATCH 8/9] =?UTF-8?q?C069=20=E3=81=8A=E7=A5=AD=E3=82=8A=E3=81=AE?= =?UTF-8?q?=E6=97=A5=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/src/C069_Festival.java | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 knoda/src/C069_Festival.java diff --git a/knoda/src/C069_Festival.java b/knoda/src/C069_Festival.java new file mode 100644 index 0000000..136d7c7 --- /dev/null +++ b/knoda/src/C069_Festival.java @@ -0,0 +1,77 @@ +package hellojunit; + +import java.util.Scanner; + +public class C069_Festival { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + final int year = scan.nextInt(); + final int month = scan.nextInt(); + final int day = scan.nextInt(); + final int holdMonth = scan.nextInt(); + final int holdDay = scan.nextInt(); + + Festival festival = new Festival(year, month, day, holdMonth, holdDay); + System.out.println(festival.dayUntilFestival()); + + scan.close(); + } +} + +class Festival { + private int year; + private int month; + private int day; + private final int holdMonth; + private final int holdDay; + + public Festival(final int year, final int month, final int day, final int holdMonth, final int holdDay) { + this.year = year; + this.month = month; + this.day = day; + this.holdMonth = holdMonth; + this.holdDay = holdDay; + } + + // ある月の日数を取得するメソッド + private int daysOfMonth(int month) { + if (month % 2 == 0) { + return 15; + } + return 13; + } + + // 祭りが開催される年であるかを判定するメソッド + private boolean isHoldFestivalYear(int year) { + return year % 4 == 1; + } + + // 年と月をカウントアップするメソッド + private void countUpYearAndMonth() { + month++; + if (month > 13) { + month = 1; + year++; + } + } + + // 祭り開催までの残り日数を取得するメソッド + public int dayUntilFestival() { + int holdYear = year + 1; + int nokoriDay = 0; + while (!isHoldFestivalYear(holdYear)) { + holdYear++; + } + + nokoriDay += daysOfMonth(month) - day; + countUpYearAndMonth(); + + while ((year != holdYear) || (month != holdMonth)) { + nokoriDay += daysOfMonth(month); + countUpYearAndMonth(); + } + nokoriDay += holdDay; + return nokoriDay; + } +} -- GitLab From 4262670b4494d5a5655ef7c6f76a27814a0b9dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E7=94=B0=20=E5=95=93=E4=BB=8B?= Date: Wed, 6 Jul 2022 11:33:27 +0900 Subject: [PATCH 9/9] =?UTF-8?q?C069=20=E3=81=8A=E7=A5=AD=E3=82=8A=E3=81=AE?= =?UTF-8?q?=E6=97=A5=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knoda/test/C069_FestivalTest.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 knoda/test/C069_FestivalTest.java diff --git a/knoda/test/C069_FestivalTest.java b/knoda/test/C069_FestivalTest.java new file mode 100644 index 0000000..9bd2d66 --- /dev/null +++ b/knoda/test/C069_FestivalTest.java @@ -0,0 +1,26 @@ +package hellojunit; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +public class C069_FestivalTest { + + @Test + public void 日数を取得するテスト1() { + Festival sut = new Festival(2000, 12, 10, 1, 10); + int expected = 28; + int actual = sut.dayUntilFestival(); + assertThat(actual, is(expected)); + } + + @Test + public void 日数を取得するテスト2() { + Festival sut = new Festival(1994, 4, 8, 7, 13); + int expected = 591; + int actual = sut.dayUntilFestival(); + assertThat(actual, is(expected)); + } + +} -- GitLab