My question is this,
I have gotten the assignment I am attaching below all done, it is graded by webcat, an automated grading website for students that tests my code against the one provided by the instructor along with the drivers. However, I am getting the message that my code coverage is 100% but it is not giving all the grade for some reason with no explanation. Ususally you get at least a message saying why you are not getting the grade. Is my testing not extensive enough or something, I just don't get it. So, if there is an expert here who can help, I would really appreciate it.
CODE
import java.util.ArrayList;
/**
* Creates and holds a collection of objects of type RateEstimator.
*
* @author student name here
* @version March 2008
*/
public class LifeRatesManager
{
// instance variables
private ArrayList<RateEstimator> rates;
/**
* Constructor for objects of class LifeRatesManager.
*/
public LifeRatesManager()
{
// * student to complete code *
this.rates = new ArrayList<RateEstimator>();
}
/**
* get the next available position in the array list.
*
* @return int The next available array list position.
*
*/
public int getNextPos()
{
// * student to correct this *
return this.rates.size();
}
/**
* add a RateEstimator object to the array list.
*
* @param inRate The RateEstimator object.
*
*/
public void addRate(RateEstimator inRate)
{
// Create local RateEstimator object from
// passed in object attributes
RateEstimator tmp = new RateEstimator();
tmp.setSmoker(inRate.isSmoker());
tmp.setGender(inRate.getGender());
tmp.setAge(inRate.getAge());
tmp.setHighRisk(inRate.isRisky());
tmp.setNumTickets(inRate.getNumTickets());
tmp.setHealth(inRate.getHealth());
tmp.setFaceValue(inRate.getFaceValue());
tmp.setName(inRate.getName());
this.rates.add(tmp);
}
/**
* get a RateEstimator object from the array list.
*
* @param inIndex The list index position of the requested object.
* @return RateEstimator The RateEstimator object from the list,
* returns null if index not valid.
*
*/
public RateEstimator getRate(int inIndex)
{
// * student to complete/correct code *
if (inIndex < this.rates.size() && inIndex >= 0)
{
// Create local RateEstimator object from
// array element object attributes
RateEstimator tmp = new RateEstimator();
tmp.setAge(rates.get(inIndex).getAge());
tmp.setGender(rates.get(inIndex).getGender());
tmp.setHealth(rates.get(inIndex).getHealth());
tmp.setHighRisk(rates.get(inIndex).isRisky());
tmp.setSmoker(rates.get(inIndex).isSmoker());
tmp.setNumTickets(rates.get(inIndex).getNumTickets());
tmp.setFaceValue(rates.get(inIndex).getFaceValue());
tmp.setName(rates.get(inIndex).getName());
return tmp;
}
return null;
}
/**
* get a RateEstimator object from the array lsit.
*
* @param inName The Rate Quote associated name.
* @return RateEstimator The RateEstimator object from the list,
* if not found returns null.
*
*/
public RateEstimator getRate(String inName)
{
// * student to complete/correct code *
for (int i = 0; i < this.getNextPos(); i++)
{
if (inName.equals(rates.get(i).getName()))
{
// Create local RateEstimator object from
// array list element object attributes
RateEstimator tmp = new RateEstimator();
tmp.setAge(rates.get(i).getAge());
tmp.setGender(rates.get(i).getGender());
tmp.setHealth(rates.get(i).getHealth());
tmp.setHighRisk(rates.get(i).isRisky());
tmp.setSmoker(rates.get(i).isSmoker());
tmp.setNumTickets(rates.get(i).getNumTickets());
tmp.setFaceValue(rates.get(i).getFaceValue());
tmp.setName(rates.get(i).getName());
return tmp;
}
}
return null;
}
/**
* delete a RateEstimator object from the array list.
*
* @param inIndex The list index position of the requested object.
*
*/
public void deleteRate(int inIndex)
{
if (inIndex < this.rates.size() && inIndex >= 0)
{
this.rates.remove(inIndex);
}
}
/**
* delete a RateEstimator object from the array list.
*
* @param inName The name in the object to delete.
*
*/
public void deleteRate(String inName)
{
String tmp1 = null;
for (int i = 0; i < this.rates.size(); i++)
{
tmp1 = this.rates.get(i).getName();
if (inName.equalsIgnoreCase(tmp1))
{
this.rates.remove(i);
}
}
}
/**
* bubble sort the array list by term rate, in order of lowest
* rate to highest.
*
* This method is based on the bblSort3 method
* presented in Module 11.
*/
public void sortByRate()
{
boolean didSwap = true;
int last = this.rates.size() - 1;
double tmpRate1;
double tmpRate2;
while (didSwap)
{
didSwap = false;
for (int i = 0; i < last; ++i)
{
tmpRate1 = rates.get(i).getTermRate();
tmpRate2 = rates.get(i + 1).getTermRate();
if (tmpRate1 > tmpRate2)
{
didSwap = true;
RateEstimator tmp = new RateEstimator();
tmp = rates.get(i);
rates.set(i, rates.get(i + 1));
rates.set((i + 1), tmp);
}
}
}
}
/**
* get the quote with the min rate.
*
* @return RateEstimator The object in the collection
* with the min rate
*
*/
public RateEstimator getMinRate()
{
// return null if array list empty
if (rates.size() == 0)
{
return null;
}
//first sort the collection via a method call
sortByRate();
return rates.get(0);
//now return the first element in list
// *student to correct this statement*
}
/**
* get the quote with the max rate.
*
* @return RateEstimator The object in the collection
* with the max rate
*
*/
public RateEstimator getMaxRate()
{
//return null if array list empty
// first sort the collection via a method call
if (rates.size() == 0)
{
return null;
}
// now return the last element in list
sortByRate();
return rates.get(rates.size() - 1);
//return null; // *student to correct this statement*
}
/**
* get average term life rate.
*
* @return double The average term life rate for the collection.
*
*/
public double getAvgTermRate()
{
//return zero if array list empty
double sum = 0;
if (rates.size() == 0)
{
return 0;
}
for (int i = 0; i < rates.size(); i++)
{
sum += rates.get(i).getTermRate();
}
double avg = sum / rates.size();
return avg;
}
/**
* get average whole life rate.
*
* @return double The average whole life rate for the collection.
*
*/
public double getAvgWholeRate()
{
double sum = 0;
// return zero if array list empty
if (rates.size() == 0)
{
return 0;
}
for (int i = 0; i < rates.size(); i++)
{
sum += rates.get(i).getWholeRate();
}
//return -1; // *student to correct this statement*
double avg = sum / rates.size();
return avg;
}
}
TEST IS BELOW:
/**
* The test class LifeRatesManagerTest.
*
* @author /student name here
* @version March 2008
*/
public class LifeRatesManagerTest extends junit.framework.TestCase
{
// instance fields
private RateEstimator rate;
private LifeRatesManager quotes;
// Tolerance variable when comparing
// floating point values
private final double delta = .01;
/**
* Default constructor for test class LifeRatesManagerTest.
*/
public LifeRatesManagerTest()
{
// LifeRatesManagerTest constructor
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
protected void setUp()
{
quotes = new LifeRatesManager();
// Non smoker, Male, 25, Low Risk, 1 ticket, Good health
this.rate = new
RateEstimator(false, 'M', 25, false, 1, "Good",
100000, "Gutterman, Donald");
quotes.addRate(this.rate);
// Smoker, Male, 55, High Risk, 3 tickets, Poor health
this.rate = new
RateEstimator(true, 'M', 55, true, 3, "Poor",
500000, "Van Camp, Fred");
quotes.addRate(this.rate);
// Non smoker, female, 24, Low Risk, 0 tickets, Fair health
this.rate = new
RateEstimator(false, 'F', 24, false, 0, "Fair",
110000, "Speigel, Lisa");
quotes.addRate(this.rate);
// Non smoker, Male, 25, Low Risk, 1 ticket, Good health
this.rate = new
RateEstimator(false, 'M', 25, false, 1, "Good",
110000, "Lee, Kim");
quotes.addRate(this.rate);
// Smoker, Male, 79, Low Risk, 2 tickets, Poor health
this.rate = new
RateEstimator(true, 'M', 79, false, 2, "Poor",
405000, "Flynn, Thomas");
quotes.addRate(this.rate);
// Non smoker, Female, 62, High Risk, 3 tickets, Good health
this.rate = new
RateEstimator(false, 'F', 62, true, 3, "Good",
325000, "Tyler, Rachel");
quotes.addRate(this.rate);
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
protected void tearDown()
{
// tearDown method
}
/**
* Test domain class constructor.
*/
public void testCreateObject()
{
LifeRatesManager quotesObj = new LifeRatesManager();
assertNotNull(quotesObj);
}
/**
* Test get next array element position.
*/
public void testGetNextPosition()
{
// Student to replace this with viable code
assertEquals(6, quotes.getNextPos());
}
/**
* Test add rate.
*/
public void testAddRate()
{
RateEstimator rateTest = new
RateEstimator(false, 'M', 25, false, 1, "Good",
100000, "Gutterman, Donald");
this.quotes.addRate(rateTest);
assertEquals(rateTest.getName() ,
(quotes.getRate(quotes.getNextPos() - 1).getName()));
}
/**
* Test get rate by postion.
*/
public void testGetRateByPos()
{
RateEstimator rateTest =
quotes.getRate(quotes.getNextPos() - 1);
// Student to replace this with viable code
assertEquals(rateTest.getName() ,
(quotes.getRate(quotes.getNextPos() - 1).getName()));
// test default return
rateTest = quotes.getRate(quotes.getNextPos());
// Student to replace this with viable code
assertNull(rateTest);
}
/**
* Test get rate by name.
*/
public void testGetRateByName()
{
RateEstimator rateTest =
quotes.getRate("Van Camp, Fred");
// Student to replace this with viable code
assertEquals(rateTest.getAge() ,
(quotes.getRate("Van Camp, Fred").getAge()));
// test default return
// Student to replace this with viable code
rateTest = quotes.getRate("Samuel, Jack");
assertNull(rateTest);
}
/**
* Test delete rate by postion.
*/
public void testDeleteRateByPos()
{
// test successful position delete
// hint: nextPos should decrement after delete
quotes.deleteRate(5);
assertEquals(5, quotes.getNextPos());
quotes.deleteRate(9);
assertEquals(5, quotes.getNextPos());
// test unsuccessful position delete
// Student to replace this with viable code
}
/**
* Test delete rate by name.
*/
public void testDeleteRateByName()
{
// test successful position delete
// Student to replace this with viable code
quotes.deleteRate("Fred Camp, Fred");
assertNull(quotes.getRate("Fred Camp, Fred"));
// Student to replace this with viable code
quotes.deleteRate("James, Brown");
assertNull(quotes.getRate("James, Brown"));
}
/**
* Test sort results by term rate.
*/
public void testSortByRate()
{
// Presort results
assertEquals(50.00, quotes.getRate(0).getTermRate(), delta);
assertEquals(1298.70, quotes.getRate(1).getTermRate(), delta);
assertEquals(26.40, quotes.getRate(2).getTermRate(), delta);
assertEquals(52.80, quotes.getRate(3).getTermRate(), delta);
assertEquals(818.18, quotes.getRate(4).getTermRate(), delta);
assertEquals(409.78, quotes.getRate(5).getTermRate(), delta);
quotes.sortByRate();
// Post sort results
assertEquals(quotes.getRate(0).getTermRate(), 26.40, delta);
assertEquals(quotes.getRate(1).getTermRate(), 50.00, delta);
assertEquals(quotes.getRate(2).getTermRate(), 52.80, delta);
assertEquals(quotes.getRate(3).getTermRate(), 409.78, delta);
assertEquals(quotes.getRate(4).getTermRate(), 818.18, delta);
assertEquals(quotes.getRate(5).getTermRate(), 1298.70, delta);
// *student to code this section*
}
/**
* Test get min rate.
*/
public void testGetMinRate()
{
// Student to replace this with viable code
assertEquals(quotes.getMinRate().getTermRate(), 26.40, delta);
}
/**
* Test get max rate.
*/
public void testGetMaxRate()
{
// Student to replace this with viable code
assertEquals(quotes.getMaxRate().getTermRate(), 1298.70, delta);
}
/**
* Test get average of term rates.
*/
public void testGetAvgTermRate()
{
assertEquals(quotes.getAvgTermRate(), 442.64, delta);
}
/**
* Test get average of whole rates.
*/
public void testGetAvgWholeRate()
{
// Student to replace this with viable code
assertEquals(quotes.getAvgWholeRate(), 1106.61, delta);
}
}
Any suggestions would be greatly appreciated, thank you in advance; aladin10.
Edited to correct the [ code] tag
This post has been edited by pbl: 4 Aug, 2008 - 02:14 PM