4 Replies - 360 Views - Last Post: 14 May 2014 - 03:44 AM Rate Topic: -----

#1 tonyzacharysmith22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 14

Help!

Posted 13 May 2014 - 02:04 PM

/**
   A class to test the CashRegister class.
*/
public class CashRegisterTester
{
   public static void main(String[] args)
   {
      CashRegister register = new CashRegister();

      // transaction #1
      register.recordPurchase(30);
      register.recordPurchase(10);
      register.enterPayment(50);

      double change = register.giveChange();
      System.out.println(change);
      System.out.println("Expected: ...");

      // transaction #2
      register.recordPurchase(20);
      register.enterPayment(20);

      change = register.giveChange();
      System.out.print("Change: ");
      System.out.println(change);
      System.out.println("Expected: ...");

      // test new functionality
      System.out.print("Total: ");
      System.out.println(register.getSalesTotal());
      System.out.println("Expected: ...");

      System.out.print("Count: ");
      System.out.println(register.getSalesCount());
      System.out.println("Expected: 2");

      register.reset();
      System.out.print("Total: ");
      System.out.println(register.getSalesTotal());
      System.out.println("Expected: ...");

      System.out.print("Count: ");
      System.out.println(register.getSalesCount());
      System.out.println("Expected: ...");
   }
}



I'm not sure what to put in the expected ones

This post has been edited by modi123_1: 13 May 2014 - 02:06 PM
Reason for edit:: please use the code tag button in the editor next time


Is This A Good Question/Topic? 0
  • +

Replies To: Help!

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: Help!

Posted 13 May 2014 - 02:07 PM

Would you expound on what you are asking for? The brevity isn't helping.
Was This Post Helpful? 0
  • +
  • -

#3 tonyzacharysmith22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 14

Re: Help!

Posted 13 May 2014 - 02:08 PM

"Expected: ...");
im not sure what to substitute for those dots
Was This Post Helpful? 0
  • +
  • -

#4 mike73  Icon User is offline

  • D.I.C Addict

Reputation: 164
  • View blog
  • Posts: 632
  • Joined: 24-April 10

Re: Help!

Posted 14 May 2014 - 12:05 AM

How are we supposed to know? What does your assignment/question ask you to do? What is this CashRegister class and why didn't you show us it?
Was This Post Helpful? 0
  • +
  • -

#5 x68zeppelin80x  Icon User is offline

  • D.I.C Addict

Reputation: 130
  • View blog
  • Posts: 576
  • Joined: 07-March 09

Re: Help!

Posted 14 May 2014 - 03:44 AM

You need to know what the expected output is supposed to be ahead of time, that is why it is called expected.

If this is a unit test, please use Junit4's assertEquals(java.lang.Object expected, java.lang.Object actual)

import static org.junit.Assert.assertEquals;

// Transaction #1
double costItem1 = 30;
double costItem2 = 10;
double payment1  = 50;
double expected  = payment1 - (costItem1 + costItem2);

register.recordPurchase(costItem1);
register.recordPurchase(costItem2);
register.enterPayment(payment1);

double actual = register.giveChange();

System.out.printf("Expected: %f, Actual: %f%n", expected, actual);
assertEquals(expected, actual, 0d);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1