Skip to content
Snippets Groups Projects
Commit c8558661 authored by Christian Lampe's avatar Christian Lampe
Browse files

Submitting homework 6.4 which is the main folder for the conditional homework.

parent bb795153
No related branches found
No related tags found
No related merge requests found
Showing
with 662 additions and 0 deletions
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>soft160--homework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.DS_Store
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>conditionals_homework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
homework-6.4/conditionals_homework/documentation/AutonomousCarCoverage.png

188 KiB

homework-6.4/conditionals_homework/documentation/MembershipCoverage.png

318 KiB

homework-6.4/conditionals_homework/documentation/ScrambleCoverage.png

226 KiB

<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>edu.unl.cse.soft160.conditionals</groupId>
<artifactId>conditionals</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>conditionals</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>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package edu.unl.cse.soft160.conditionals;
import java.util.Scanner;
//Christian Lampe
//The code looks at each of the inputs to check to see if any of them evaluate to false.
//If any of them evaluate to false, it prints start breaking
//If none of them are false, then they are all true so it prints continue driving.
public class AutonomousCar {
public static void main(String... arguments) {
Scanner scanner = new Scanner(System.in);
System.out.print("Has an obstacle been detected (yes/no)? ");
boolean obstacle = scanner.nextLine().matches("[Yy].*");
System.out.print("Is the car approaching a red light (yes/no)? ");
boolean redLight = scanner.nextLine().matches("[Yy].*");
System.out.print("Does the driver want to stop (yes/no)? ");
boolean driverRequest = scanner.nextLine().matches("[Yy].*");
if (obstacle == true || redLight == true || driverRequest == true) {
System.out.print("Start braking\n");
}else {
System.out.print("Continue\n");
}
scanner.close();
}
}
package edu.unl.cse.soft160.conditionals;
import java.util.Scanner;
public class Membership {
public static void main(String... arguments) {
Scanner scanner = new Scanner(System.in);
System.out.print("How long has the customer been a member for (in years)? ");
double membershipDuration = Double.parseDouble(scanner.nextLine());
System.out.print("Has the member spent at least $10K each year in the past 2 years (yes/no)? ");
boolean highSpender = scanner.nextLine().matches("[Yy].*");
System.out.print("Has the member accumulated at least 5,000 reward points (yes/no)? ");
boolean rewardPoints = scanner.nextLine().matches("[Yy].*");
// [write code here]
if (membershipDuration == 2 && highSpender == true) {
System.out.print("VIP Member\n");
}
else if (membershipDuration >= 6 && rewardPoints == true) {
System.out.print("VIP Member\n");
}
else if (membershipDuration >= 12) {
System.out.print("VIP Member\n");
}
else {
System.out.print("Member\n");
}
scanner.close();
}
}
package edu.unl.cse.soft160.conditionals;
import java.util.Scanner;
//Christian Lampe
//The code looks at the side lengths of different triangles to determine which type of triangle they are.
//If all sides are equal, it is a regular triangle, if two are the same, it is a symmetric triangle.
//If none of the sides are equal, it is a irregular triangle.
public class Scramble {
public static void main(String... arguments) {
Scanner scanner = new java.util.Scanner(System.in);
System.out.print("Enter length of the first edge: ");
int firstEdge = Integer.parseInt(scanner.nextLine());
System.out.print("Enter length of the second edge: ");
int secondEdge = Integer.parseInt(scanner.nextLine());
System.out.print("Enter length of the third edge: ");
int thirdEdge = Integer.parseInt(scanner.nextLine());
if (firstEdge == thirdEdge) {
if (secondEdge == thirdEdge) {
System.out.println("The triangle is regular.");
} else {
System.out.println("The triangle is symmetric.");
}
} else {
if (firstEdge == secondEdge) {
System.out.println("The triangle is symmetric.");
} else {
System.out.println("The triangle is irregular.");
}
if (secondEdge == thirdEdge) {
System.out.println("The triangle is symmetric.");
} else {
scanner.close();
}
}
}
}
package edu.unl.cse.soft160.conditionals;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.junit.Test;
public class AutonomousCarTest {
protected static String assemble(String... lines) {
return String.join("\n", lines) + "\n";
}
protected static String runMain(String... inputs) {
InputStream in = System.in;
PrintStream out = System.out;
System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes()));
ByteArrayOutputStream collector = new ByteArrayOutputStream();
System.setOut(new PrintStream(collector));
AutonomousCar.main();
System.setIn(in);
System.setOut(out);
return collector.toString();
}
@Test
public void testContinueWithNoReason() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Continue"),
runMain("no", "no", "no"));
}
@Test
public void testBrakeWithDriverRequest() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("no", "no", "yes"));
}
@Test
public void testBrakeWithRedLight() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("no", "yes", "no"));
}
@Test
public void testBrakeWithNoObstacle() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("no", "yes", "yes"));
}
@Test
public void testBrakeWithObstacle() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("yes", "no", "no"));
}
@Test
public void testBrakeWithNoRedLight() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("yes", "no", "yes"));
}
@Test
public void testBrakeWithNoDriverRequest() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("yes", "yes", "no"));
}
@Test
public void testBrakeWithAllReason() {
assertEquals(
assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? "
+ "Does the driver want to stop (yes/no)? " + "Start braking"),
runMain("yes", "yes", "yes"));
}
}
package edu.unl.cse.soft160.conditionals;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.junit.Test;
public class MembershipTest {
protected static String assemble(String... lines) {
return String.join("\n", lines) + "\n";
}
protected static String runMain(String... inputs) {
InputStream in = System.in;
PrintStream out = System.out;
System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes()));
ByteArrayOutputStream collector = new ByteArrayOutputStream();
System.setOut(new PrintStream(collector));
Membership.main();
System.setIn(in);
System.setOut(out);
return collector.toString();
}
// LESS THAN 2 YEARS OF MEMBERSHIP
@Test
public void testMembershipWithNoRequirementMet() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("1", "no", "no"));
}
@Test
public void testMembershipWithFewYearsAndRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("1", "no", "yes"));
}
@Test
public void testMembershipWithFewYearsAndSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("1", "yes", "no"));
}
@Test
public void testMembershipWithFewYears() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("1", "yes", "yes"));
}
// 2 YEARS OF MEMBERSHIP
@Test
public void testMembershipWith2Years() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("2", "no", "no"));
}
@Test
public void testMembershipWith2YearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("2", "no", "yes"));
}
@Test
public void testMembershipWith2YearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("2", "yes", "no"));
}
@Test
public void testMembershipWith2YearsAndAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("2", "yes", "yes"));
}
// BETWEEN 2 AND 6 YEARS OF MEMBERSHIP
@Test
public void testMembershipBetween2And6Years() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("3", "no", "no"));
}
@Test
public void testMembershipBetween2And6YearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("3", "no", "yes"));
}
@Test
public void testMembershipBetween2And6YearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("3", "yes", "no"));
}
@Test
public void testMembershipBetween2And6YearsAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("3", "yes", "yes"));
}
// 6 YEARS OF MEMBERSHIP
@Test
public void testMembership6Years() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("6", "no", "no"));
}
@Test
public void testMembership6YearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("6", "no", "yes"));
}
@Test
public void testMembership6YearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("6", "yes", "no"));
}
@Test
public void testMembership6YearsAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("6", "yes", "yes"));
}
// BETWEEN 6 AND 12 YEARS OF MEMBERSHIP
@Test
public void testMembership6PlusYears() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("7", "no", "no"));
}
@Test
public void testMembership6PlusYearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("7", "no", "yes"));
}
@Test
public void testMembership6PlusYearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"),
runMain("7", "yes", "no"));
}
@Test
public void testMembership6PlusYearsAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("7", "yes", "yes"));
}
// 12 YEARS OF MEMBERSHIP
@Test
public void testMembership12Years() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("12", "no", "no"));
}
@Test
public void testMembership12YearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("12", "no", "yes"));
}
@Test
public void testMembership12YearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("12", "yes", "no"));
}
@Test
public void testMembership12YearsAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("12", "yes", "yes"));
}
// MORE THAN 12 YEARS OF MEMBERSHIP
@Test
public void testMembership12PlusYears() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("13", "no", "no"));
}
@Test
public void testMembership12PlusYearsNoSpending() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("13", "no", "yes"));
}
@Test
public void testMembership12PlusYearsNoRewards() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("13", "yes", "no"));
}
@Test
public void testMembership12PlusYearsAll() {
assertEquals(
assemble("How long has the customer been a member for (in years)? "
+ "Has the member spent at least $10K each year in the past 2 years (yes/no)? "
+ "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"),
runMain("13", "yes", "yes"));
}
}
package edu.unl.cse.soft160.conditionals;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.junit.Test;
public class ScrambleTest {
protected static String assemble(String... lines) {
return String.join("\n", lines) + "\n";
}
protected static String runMain(String... inputs) {
InputStream in = System.in;
PrintStream out = System.out;
System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes()));
ByteArrayOutputStream collector = new ByteArrayOutputStream();
System.setOut(new PrintStream(collector));
Scramble.main();
System.setIn(in);
System.setOut(out);
return collector.toString();
}
@Test
public void testRegular() {
assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: "
+ "Enter length of the third edge: " + "The triangle is regular."), runMain("1", "1", "1"));
}
@Test
public void testSymmetric12() {
assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: "
+ "Enter length of the third edge: " + "The triangle is symmetric."), runMain("1", "1", "2"));
}
@Test
public void testSymmetric13() {
assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: "
+ "Enter length of the third edge: " + "The triangle is symmetric."), runMain("1", "2", "1"));
}
@Test
public void testSymmetric23() {
assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: "
+ "Enter length of the third edge: " + "The triangle is symmetric."), runMain("2", "1", "1"));
}
@Test
public void testIrregular() {
assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: "
+ "Enter length of the third edge: " + "The triangle is irregular."), runMain("1", "2", "3"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment