diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/.gitignore b/Summer-2024/CS-3443/Quizzes/Quiz-1/.gitignore new file mode 100644 index 0000000..d11829c --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings/ +target/ diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/pom.xml b/Summer-2024/CS-3443/Quizzes/Quiz-1/pom.xml new file mode 100644 index 0000000..1010bd2 --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + com.zfp106.quiz1 + lab1 + jar + 1.0-SNAPSHOT + lab1 + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/App.java b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/App.java new file mode 100644 index 0000000..4b25a51 --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/App.java @@ -0,0 +1,17 @@ +package com.zfp106.quiz1; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + Drink.QuestionOne(); + Drink.QuestionTwo(); + Drink.QuestionThree(); + Drink.QuestionFour(); + Drink.QuestionFive(); + } +} diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/Drink.java b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/Drink.java new file mode 100644 index 0000000..9bd5d79 --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/main/java/com/zfp106/quiz1/Drink.java @@ -0,0 +1,149 @@ +package com.zfp106.quiz1; + +public class Drink { + private int size, amount; + + public Drink(int size) { + this.size = size; + this.amount = size; + } + + public int sip() { + amount--; + return amount; + } + + public int gulp(int n) { + for (int i = 0; i < n; i++) { + sip(); + } + return amount; + } + + public int refill() { + amount = size; + return amount; + } + + /** + * + * Choose a sequence of statements that prints –2. Do not include unneeded statements. + * - int r = drink1.gulp(n); + * - Drink drink1 = new Drink(12); + * - System.out.print(r); + * - if (r <= 0) r = drink1.refill(); + * - r = drink1.sip(); + * - Drink drink1 = new Drink(16); + * - int n = 13; + * - int n = 7; + * + * @return A number that equals `-2` given the statements + */ + public static int QuestionOne() { + Drink drink1 = new Drink(12); + int n = 13; + int r = drink1.gulp(n); + r = drink1.sip(); + System.out.print(r); + return r; + } + + /** + * + * Choose a sequence of statements that prints 38. Do not include unneeded statements. + * - drink1.gulp(2); + * - int r = drink1.sip() + drink2.sip(); + * - Drink drink1 = new Drink(12); + * - Drink drink2 = drink1; + * - System.out.print(r); + * - Drink drink1 = new Drink(16); + * - drink2.gulp(drink1.sip() / 2); + * - Drink drink2 = new Drink(32); + * + * @return A number that equals `38` given the statements + */ + public static int QuestionTwo() { + Drink drink1 = new Drink(16); + Drink drink2 = new Drink(32); + drink2.gulp(drink1.sip() / 2); + int r = drink1.sip() + drink2.sip(); + System.out.print(r); + return r; + } + + /** + * + * Choose a sequence of statements that prints 37. Do not include unneeded statements. + * - System.out.print(r); + * - int r = drink1.sip() + drink2.sip(); + * - drink1.gulp(2); + * - Drink drink2 = drink1; + * - Drink drink1 = new Drink(16); + * - drink2.gulp(drink1.sip() / 2); + * - Drink drink1 = new Drink(12); + * - Drink drink2 = new Drink(32); + * + * @return A number that equals `37` given the statements + */ + public static int QuestionThree() { + Drink drink1 = new Drink(16); + Drink drink2 = new Drink(32); + drink1.gulp(2); + drink2.gulp(drink1.sip() / 2); + int r = drink1.sip() + drink2.sip(); + System.out.print(r); + return r; + } + + /** + * + * Choose a sequence of statements that prints 36. Do not include unneeded statements. + * - drink1.gulp(2); + * - Drink drink2 = new Drink(32); + * - System.out.print(r); + * - Drink drink1 = new Drink(12); + * - int r = drink1.sip() + drink2.sip(); + * - drink2.gulp(drink1.sip() / 2); + * - Drink drink2 = drink1; + * - Drink drink1 = new Drink(16); + * + * @return A number that equals `36` given the statements + */ + public static int QuestionFour() { + Drink drink1 = new Drink(12); + Drink drink2 = new Drink(32); + drink2.gulp(drink1.sip() / 2); + int r = drink1.sip() + drink2.sip(); + System.out.print(r); + return r; + } + + /** + * + * Choose a sequence of statements that prints 11. Do not include unneeded statements. + * - Drink drink2 = drink1; + * - drink1.gulp(2); + * - int r = drink1.sip() + drink2.sip(); + * - Drink drink2 = new Drink(32); + * - drink2.gulp(drink1.sip() / 2); + * - Drink drink1 = new Drink(12); + * - System.out.print(r); + * - Drink drink1 = new Drink(16); + * + * @return A number that equals `11` given the statements + */ + public static int QuestionFive() { + Drink drink1 = new Drink(16); + Drink drink2 = drink1; + drink1.gulp(2); + drink2.gulp(drink1.sip() / 2); + int r = drink1.sip() + drink2.sip(); + System.out.print(r); + return r; + } + + + + + +} diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/src/test/java/com/zfp106/quiz1/DrinkTest.java b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/test/java/com/zfp106/quiz1/DrinkTest.java new file mode 100644 index 0000000..dd71145 --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/src/test/java/com/zfp106/quiz1/DrinkTest.java @@ -0,0 +1,47 @@ +package com.zfp106.quiz1; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class DrinkTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public DrinkTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(DrinkTest.class); + } + + public void testQuestionOne() { + assertEquals(-2, Drink.QuestionOne()); + } + + public void testQuestionTwo() { + assertEquals(38, Drink.QuestionTwo()); + } + + public void testQuestionThree() { + assertEquals(37, Drink.QuestionThree()); + } + + public void testQuestionFour() { + assertEquals(36, Drink.QuestionFour()); + } + + public void testQuestionFive() { + assertEquals(11, Drink.QuestionFive()); + } +} diff --git a/Summer-2024/CS-3443/Quizzes/Quiz-1/test/java/com/zfp106/quiz1/AppTest.java b/Summer-2024/CS-3443/Quizzes/Quiz-1/test/java/com/zfp106/quiz1/AppTest.java new file mode 100644 index 0000000..36122d6 --- /dev/null +++ b/Summer-2024/CS-3443/Quizzes/Quiz-1/test/java/com/zfp106/quiz1/AppTest.java @@ -0,0 +1,38 @@ +package com.zfp106.quiz1; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}