예제 #1
0
 /** Returns the total sum that needs to be paid for all the items in the basket. */
 public double getTotalPrice() {
   double price = 0.0;
   for (SoldItem item : getRows()) {
     price += item.getSum();
   }
   return price;
 }
예제 #2
0
 @Override
 protected Object getColumnValue(SoldItem item, int columnIndex) {
   switch (columnIndex) {
     case 0:
       return item.getId();
     case 1:
       return item.getName();
     case 2:
       return item.getPrice();
     case 3:
       return item.getQuantity();
     case 4:
       return item.getSum();
   }
   throw new IllegalArgumentException("Column index out of range");
 }
예제 #3
0
  @Override
  public String toString() {
    final StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < headers.length; i++) buffer.append(headers[i] + "\t");
    buffer.append("\n");

    for (final SoldItem item : getRows()) {
      buffer.append(item.getId() + "\t");
      buffer.append(item.getName() + "\t");
      buffer.append(item.getPrice() + "\t");
      buffer.append(item.getQuantity() + "\t");
      buffer.append(item.getSum() + "\t");
      buffer.append("\n");
    }

    return buffer.toString();
  }
예제 #4
0
 @Test
 public void testGetSumWithZeroQuantity() {
   sold_item = new SoldItem(stock_item, 0);
   assertEquals(sold_item.getSum(), 0, 0.0001);
 }
예제 #5
0
 @Test
 public void testGetSum() {
   sold_item = new SoldItem(stock_item, 10);
   assertEquals(sold_item.getSum(), (price * 10), 0.0001);
 }