I have the following CashRegister class where i must implement 3 methods:
-getSalesTotal total up sales for the day
-getSalesCount total number of sales for the day
- rest a reset method that returns all instance variables to 0

Here is my code any help on mistakes i may have made is great, but my real problem is that i keep getting missing return statement when i try to compile the program. TY

/**

   A cash register totals up sales and computes change due.

*/

public class CashRegister

{

   private double purchase;

   private double payment;

   private double purchaseTotal;
   private double purchaseCount;



   /**

      Constructs a cash register with no money in it.

   */

   public CashRegister()

   {

      purchase = 0;

      payment = 0;

      purchaseTotal = 0;
      purchaseCount = 0;

   }



   /**

      Records the sale of an item.

      @param amount the price of the item

   */

   public void recordPurchase(double amount)

   {

      double total = purchase + amount;
      purchase = total;
      purchaseCount++;
      purchaseTotal = purchaseTotal + total;	

   }



   /**

      Enters the payment received from the customer.

      @param amount the amount of the payment

   */

   public void enterPayment(double amount)

   {

      payment = amount;

   }



   /**

      Computes the change due and resets the machine for the next customer.

      @return the change due to the customer

   */

   public double giveChange()

   {   

      double change = payment - purchase;

      purchase = 0;

      payment = 0;

      return change;

   }



   /**

      Get the total amount of all sales for the day.

      @param return sale total

   */

   public double getSalesTotal(double salesTotal)
   {
      salesTotal = purchaseTotal;
   }



   /**

      Get the total number of sales for the day.

      @param return the number of sales.

   */

   public double getSalesCount(double salesCount)
   {
      salesCount = purchaseCount; 

   }

   /**

      Reset counters and totals for the next days sales.

      @param none

   */

   public void reset(double resetComplete)	
   {      
      purchaseCount = 0;
      purchaseTotal = 0;
      purchase = 0;
      payment = 0;
      resetComplete = purchase + payment + purchaseTotal + purchaseCount;
   }	
}

getSalesTotal() and getSalesCount() have been declared as double so they must return some value.
Declare them void if you do not wish to return any value from these methods

public double getSalesTotal(double salesTotal) {
  salesTotal = purchaseTotal;
}

You got yourself quite confused about get methods. You don't need to pass in the value if the purpose of the method is to get it! And setting the value of a parameter like that doesn't achieve anything anyway.
A typical get method looks like this example:

class Person {
  private String name;
  public String getName() {
    return name;
  }
  ...

I have made some changes to the code, my getSalesCount method is just the name of the method and was not meant to be

get.SalesCount a I think you mayb think I meant to do. I am very new to programmning so I could be wrong. In any case I have solved the missing return value by adding a return to the bottom of both getSalesCount and getSalesTotal. I have howeve encountered a new problem where I dont believe I am using the return method correctly. Any help on how to make this program work would be really appreciated.

/**

   A cash register totals up sales and computes change due.

*/

public class CashRegister

{

   private double purchase;

   private double payment;

   private double purchaseTotal;
   private double purchaseCount;



   /**

      Constructs a cash register with no money in it.

   */

   public CashRegister()

   {

      purchase = 0;

      payment = 0;

      purchaseTotal = 0;
      purchaseCount = 0;

   }



   /**

      Records the sale of an item.

      @param amount the price of the item

   */

   public void recordPurchase(double amount)

   {

      double total = purchase + amount;
      purchase = total;
      purchaseCount++;
      purchaseTotal = purchaseTotal + total;	

   }



   /**

      Enters the payment received from the customer.

      @param amount the amount of the payment

   */

   public void enterPayment(double amount)

   {

      payment = amount;

   }



   /**

      Computes the change due and resets the machine for the next customer.

      @return the change due to the customer

   */

   public double giveChange()

   {   

      double change = payment - purchase;

      purchase = 0;

      payment = 0;

      return change;

   }



   /**

      Get the total amount of all sales for the day.

      @param return sale total

   */

   public double getSalesTotal(double salesTotal)
   {
      salesTotal = purchaseTotal;
      return salesTotal;
   }



   /**

      Get the total number of sales for the day.

      @param return the number of sales.

   */

   public double getSalesCount(double salesCount)
   {
      salesCount = purchaseCount;
      return salesCount; 

   }

   /**

      Reset counters and totals for the next days sales.

      @param none

   */

   public double reset(double resetComplete)	
   {      
      purchaseCount = 0;
      purchaseTotal = 0;
      purchase = 0;
      payment = 0;
      resetComplete = purchase + payment + purchaseTotal + purchaseCount;
      return resetComplete;  
   }  	
}

Read up on accessor and mutator functions.

public double getSalesTotal(double salesTotal)
{
salesTotal = purchaseTotal;
return salesTotal;
}

This should be two separate functions, it will help avoid confusion.

One function should 'set' the fields and another should 'get' a value.

This article has been dead for over six months. Start a new discussion instead.