From fe2a815600276aa9bf529dff8f98b66a7354abac Mon Sep 17 00:00:00 2001 From: Mohaned Yossry Abdulaziz Date: Tue, 10 Nov 2020 17:13:12 +0200 Subject: [PATCH] Added Task 1 Solution --- Task1Solution/.idea/.gitignore | 8 ++ Task1Solution/.idea/misc.xml | 6 + Task1Solution/.idea/modules.xml | 8 ++ Task1Solution/.idea/vcs.xml | 6 + Task1Solution/Task1Solution.iml | 11 ++ .../Task1Solution/com/task1/Task1.class | Bin 0 -> 2203 bytes .../Task1Solution/com/task1/student_info.txt | 3 + .../Task1StarterProject/com/task1/Task2.class | Bin 0 -> 2203 bytes .../com/task1/student_info.txt | 3 + .../Task1StarterProject/newpacakge/Task.class | Bin 0 -> 506 bytes Task1Solution/src/com/task1/Task1.java | 128 ++++++++++++++++++ Task1Solution/src/com/task1/student_info.txt | 3 + 12 files changed, 176 insertions(+) create mode 100644 Task1Solution/.idea/.gitignore create mode 100644 Task1Solution/.idea/misc.xml create mode 100644 Task1Solution/.idea/modules.xml create mode 100644 Task1Solution/.idea/vcs.xml create mode 100644 Task1Solution/Task1Solution.iml create mode 100644 Task1Solution/out/production/Task1Solution/com/task1/Task1.class create mode 100644 Task1Solution/out/production/Task1Solution/com/task1/student_info.txt create mode 100644 Task1Solution/out/production/Task1StarterProject/com/task1/Task2.class create mode 100644 Task1Solution/out/production/Task1StarterProject/com/task1/student_info.txt create mode 100644 Task1Solution/out/production/Task1StarterProject/newpacakge/Task.class create mode 100644 Task1Solution/src/com/task1/Task1.java create mode 100644 Task1Solution/src/com/task1/student_info.txt diff --git a/Task1Solution/.idea/.gitignore b/Task1Solution/.idea/.gitignore new file mode 100644 index 0000000..440e4c5 --- /dev/null +++ b/Task1Solution/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../:\WorkProjects\Task1StarterProject\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/Task1Solution/.idea/misc.xml b/Task1Solution/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Task1Solution/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task1Solution/.idea/modules.xml b/Task1Solution/.idea/modules.xml new file mode 100644 index 0000000..42ee5f1 --- /dev/null +++ b/Task1Solution/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Task1Solution/.idea/vcs.xml b/Task1Solution/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Task1Solution/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task1Solution/Task1Solution.iml b/Task1Solution/Task1Solution.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Task1Solution/Task1Solution.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Task1Solution/out/production/Task1Solution/com/task1/Task1.class b/Task1Solution/out/production/Task1Solution/com/task1/Task1.class new file mode 100644 index 0000000000000000000000000000000000000000..366e8016bfaf7b3ca65fe8fe3077507e884d8dc1 GIT binary patch literal 2203 zcmaJ>OLNm!6#ir@mZB(697hBi#49-A;qodC0YZX#B$!8W2!v-9TXh7sWF#39`uGFg zc7|a((`{B=l!eKZnRee*e@2(xb<>u9S4wauF!hXe&pqedbH4AKbMJ5e{`?DoWB5kH zZpQdSXh`6ykgln?uHiG>5SpTfU6>Wyn=0mn=9Y@vD&~d$j`-Zwa1Zy}7*YH* z1rIc&F(W#3EiT5cs*41LF~j7Nzqzrv$iK46y6=D77nNNaqy5jxdev1GZf?K5=J zZPX-4GX(G3L8D4XnX1Foi=H3a<+uzypUUR*`3QSx*Xlf6vzElyDf3(Po-rFsR4SG{p9NEb z7%&qCLc_jG(28EeFWDCyQBp0c)ge(H9ec2sg^WtIk*)$q$0Ixz4pkjB5OmjhH?(~- z#&yzE;OVI2i4Gruj!!Wrwj`L2{Vq6u5We%)(ZEv){jsfRmpr%p&iL-k?4skh)H=>! zLPs8Z6+F|igfR&No4Y#IaH?h7*RhP}5)ubYA$_UiD|{`XBTg3;f;8v7hFQ0Qzzi2{ z(_XUJg8`u{d+xq)v!!>#S<|XSW7WNB;3V|4@LXGXWS7W)gQ~b3uxErNX0kt?D#y!B zi!tL++E$HoWn@2S5FJl?VjNosuXB!D2e(AI8E=D{15g)ERgrKl@a8+9y7p37@Z1U$ zWW{KT31v1-=<{A9x_Gp3s=HeBu2>=OZPHp0BWcy^w#)h3p3RTEchS~bLTU#;gy4Vt z)zFLYDkmcQe&BKJFYe+v)NMIkosYuy@EM+}*zz9aU zYsY>Zphg`2i+(!S`)`n#e}&|0$c0yE>q|AE>~BJyG*{7nLZ&JsH=zkrM{Lr^QexM+ zzEj1nYkj8~DMK~1RdlbSrv>UHx|pmB9q7gu^uRzbhR{bSX&gd7U+fG{VE|LK%wQ|7 zV-WM$&gXYWMC1|_0Tu`84Mw>^_8*gqf%7iRLx?6tvF=>= zUwQj`i}WZ519-w_`5e!HghQBoy|Z}Ap;{u*Wt_uvT;>xi?p216J4oU@O96Tx!v%tu XBJeuoe_$xMm>g8Psk=mv1g8H3%htRB literal 0 HcmV?d00001 diff --git a/Task1Solution/out/production/Task1Solution/com/task1/student_info.txt b/Task1Solution/out/production/Task1Solution/com/task1/student_info.txt new file mode 100644 index 0000000..a47f2bc --- /dev/null +++ b/Task1Solution/out/production/Task1Solution/com/task1/student_info.txt @@ -0,0 +1,3 @@ +Name: +------------------------------------- +Group: \ No newline at end of file diff --git a/Task1Solution/out/production/Task1StarterProject/com/task1/Task2.class b/Task1Solution/out/production/Task1StarterProject/com/task1/Task2.class new file mode 100644 index 0000000000000000000000000000000000000000..c6eae517e3f66bcf92a61463202f2927323c4e29 GIT binary patch literal 2203 zcmaJ>OLNm!6#ir@mZB(697hBi#49-A;S!)U1jqyPNN@thArPKbY}FCil96Rd=;IG` z+Zl%GOt)EeQ5GgsX4-vM{TW?$*G*gcT`9q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ltZ;bqN})o=eWuzR@|!;A-9plMV12eK8Z^N YFNNTB$p64la5>(ubW(SP9x+V+2j4Wj1ONa4 literal 0 HcmV?d00001 diff --git a/Task1Solution/out/production/Task1StarterProject/com/task1/student_info.txt b/Task1Solution/out/production/Task1StarterProject/com/task1/student_info.txt new file mode 100644 index 0000000..a47f2bc --- /dev/null +++ b/Task1Solution/out/production/Task1StarterProject/com/task1/student_info.txt @@ -0,0 +1,3 @@ +Name: +------------------------------------- +Group: \ No newline at end of file diff --git a/Task1Solution/out/production/Task1StarterProject/newpacakge/Task.class b/Task1Solution/out/production/Task1StarterProject/newpacakge/Task.class new file mode 100644 index 0000000000000000000000000000000000000000..6cd9111cd8ee3178f91f28906808e21b2e07d234 GIT binary patch literal 506 zcmZWm$xZ@65Pi)uo5LcA`x0-+!MPYO7%wKCCTarV-V7aVm@PAdhR@Q2CLa6%Kgw7= z7!mD5b=9k?SFgH1KHuH}oZ-kq8BG%#Xj$0AmX2*5I}F-|3}tr7P;8$J7)n>sNHEk~ z8H$@(Fce9j4}C%!Zsc))z!RzBZ?Kfz%amc=4aH;3Jw6=^r_a-Am!UF}Y3%cPFH2-N zW@xqD34h>@&%?2^0K00S5&V=i{#P(qy=azr;#w*ZrXoL8JT^4wI(BXBVPD6AjYCvP z_a7k)_2tyt;Y4`Z3e=mYnFwh4Xhwiu@4ADAC)h zQvf|Ebg~9T4&99Ia_1H7DNmbZwHz$MBHvyVV2wP$L Bonus : Learn more about Math.abs() method and try to use it in the task through it's documentation + ---------------------------------------------- + * Write a method that prompts the user to enter an long then displays the sum of all its digits and call + this method in main + method to test the program. + + */ + + //TODO Write Answer for Question 1 Here + public static long sumDigits(long n) { + //n=>234 + long sum = 0; + n = Math.abs(n); + while (n != 0) { + // digit => 4 => 3 => 2 + long digit = n % 10; + // 0 => 4 => 7 => 9 + sum += digit; + //234=>23 => 2 => 0 + n = n / 10; + } + return sum; + } + + //-----------------------------------------------------------------------// + + /* + TODO: Question 2: (Sort three numbers) Write a method with the following header to display three + numbers in decreasing order: + --------------------- + public static void displaySortedNumbers(double num1, double num2, double num3) + --------------------- + Write a test program that prompts the user to enter three numbers and invokes the + method to display them in decreasing order. + */ + + //TODO Write Answer for Question 2 Here + public static void displaySortedNumbers(double max, double mid, double low) { + double temp; + if (mid >= max && mid >= low) { + temp = max; + max = mid; + mid = temp; + } else if (low >= max && low >= mid) { + temp = max; + max = low; + low = temp; + } + if (low > mid) { + temp = low; + low = mid; + mid = temp; + } + + + System.out.println(max + ", " + mid + ", " + low); + + } + + //-----------------------------------------------------------------------// + + /* + TODO: Question 3: Write a method that prompts a student to enter a score. + If the score is greater or equal to 60, display “you pass the exam”; + otherwise, display “you don’t pass the exam”. Your program ends with input -1. + */ + + //TODO Write Answer for Question 3 Here + public static void calcScore() { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter score"); + double score = scanner.nextDouble(); + while (score != -1) { + if (score >= 60) + System.out.println("You pass the exam"); + else + System.out.println("You don't pass the exam"); + System.out.println("Enter score again"); + score = scanner.nextDouble(); + } + } + + //-----------------------------------------------------------------------// + +} diff --git a/Task1Solution/src/com/task1/student_info.txt b/Task1Solution/src/com/task1/student_info.txt new file mode 100644 index 0000000..a47f2bc --- /dev/null +++ b/Task1Solution/src/com/task1/student_info.txt @@ -0,0 +1,3 @@ +Name: +------------------------------------- +Group: \ No newline at end of file