cs-3443: add quiz1

This commit is contained in:
Price Hiller 2024-06-10 14:14:30 -05:00
parent 35355269ff
commit 82212475d0
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
6 changed files with 273 additions and 0 deletions

View File

@ -0,0 +1,4 @@
.classpath
.project
.settings/
target/

View File

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zfp106.quiz1</groupId>
<artifactId>lab1</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>lab1</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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 );
}
}