Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cool #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

cool #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Average {
private int count = 0;
private double sum = 0;

public void addValue(double value) {
sum += value;
count += 1;
}

public double getAverage() {
if (count == 0) {
return 0;
}
else {
return sum / count;
}
}

public int getCount() {

return count;
}
}
59 changes: 59 additions & 0 deletions AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import junit.framework.TestCase;


public class AverageTest extends TestCase {


public void testNewAverage() {
Average avg = new Average ();

assertEquals(0, avg.getCount());
assertEquals(0.0, avg.getAverage(), 0.001);
}

public void testSingleValue() {
Average avg = new Average();

avg.addValue(5.5);

assertEquals(5.5, avg.getAverage(), 0.001);
assertEquals(1, avg.getCount());
}

public void testFiveValuesNonZeroAverage() {
Average avg = new Average ();

avg.addValue(5.5);
avg.addValue(2.5);
avg.addValue(3.5);
avg.addValue(1.5);
avg.addValue(4.0);

assertEquals(3.4, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testFiveValuesZeroAverage() {
Average avg = new Average ();

avg.addValue(-1);
avg.addValue(0);
avg.addValue(-2);
avg.addValue(1);
avg.addValue(2);

assertEquals(0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testFiveValuesSameAverage() {
Average avg = new Average ();

avg.addValue(5);
avg.addValue(5);
avg.addValue(5);
avg.addValue(5);
avg.addValue(5);

assertEquals(5, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
}
59 changes: 59 additions & 0 deletions Lab_3_answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CS Lab 2/12/2015 **Wilson Silverio**

**Question 1**

List three mistakes we can make when using an array.

**a)** Reference the wrong position of the array.

**b)** Can't use multiple types in an array.

**c)** While looping the array, making sure that we have conditions that are logical to solve the problem.

**Question 2:**

List at least one configuration of a `Scoreboard` for each of the above scenarios.

**a)** With a new instance of the class, it would use a reference to `Scoreboard`. No value(s) are in either array.

**Instance of a class:**

scores = [0,0,0,0,0,0,0,0,0,0]

names = null

**b)** An instance with a single mutation would change `Scoreboard` and `String` array.

**Instance with a single mutation:**

scores = [1,0,0,0,0,0,0,0,0]

names = ["Professor Sommer"]

**c)** An instance with multiple mutations would change to `Scoreboard` and `String` array multiple times, in sorted order (hightest to lowest).

**Instance with multiple mutations:**

scores = [1,0,0,0,0,1,0,0,0,0]

names = ["Professor Sommer","Professor Coleman"]

**Question 3:** Answer the "Testing Questions" descripted in the previous section.

**New instance of the class:**

max: 10.0

min: 0.0

**Best mutation:**

No mutator methods

**What else can we do with the class:**

Ask it to return its values

**Boundary conditions for the class:**

min, max
53 changes: 53 additions & 0 deletions Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
public class Range {
private double min = 0;
private double max = 0;

public Range (double start, double stop) {
if (start > stop) {
min = stop;
max = start;
}
else {
min = start;
max = stop;
}
}

public boolean contains (double value) {
if (value > max || value < min) {
return false;
}
else {
return true;
}
}

public double getWidth() {
return getMax() - getMin();
}

public double getMin() {

return min;
}

public double getMax() {

return max;
}

public Range intersection(Range other) {
double newMin = 0.0;
double newMax = 0.0;

if (other.contains(min)) {
newMin = min;
newMax = other.getMax();
}
else if (other.contains(max)) {
newMin = other.getMin();
newMax = max;
}
return new Range(newMin, newMax);
}
}
24 changes: 24 additions & 0 deletions RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import junit.framework.TestCase;


public class RangeTest extends TestCase {
public void testNewRange() {
Range r = new Range(0.0, 0.0);

}
public void testMin() {
Range r1 = new Range(1.0, 10.0);
assertEquals(1.0, r1.getMin(), 0.001);

Range r2 = new Range(5.8, -1.2);
assertEquals(-1.2, r2.getMin(), 0.001);
}
public void testIntersection() {
Range r1 = new Range(1.0, 10.0);
Range r2 = new Range(5.0, 15.0);
Range r3 = r1.intersection(r2);

assertEquals(r1.getMax(),r3.getMax());
assertEquals(r2.getMin(),r3.getMin());
}
}