I'm writing a program but I don't understand the question that well could someone help explain what I have to do. Also, I am having difficulty making the methods could someone help, because I am getting an error every time.
This is the Question.
Write a cash register class. It should have the following methods:

AddTransaction(amount) – add an amount to a running total and increments the number of transactions
TransactionCount() – returns the number of transactions received
Total() – returns to total amount of the orders
ResetTransactions() – sets the total amount and transaction count to 0
Register Count() – returns the number of cash registers created
Next, write an application that instantiates at least two register objects to prove that your class works.

P.S.: Don't worry about storing each individual order.

My code is:

package cashregister;
import java.io.*;
public class CashRegister 
{
    public static void main(String[] args) 
    {
        AddTransaction call = new AddTransaction();
        System.out.println("the answer is" + call);
        
        public static void AddTransaction()
        {
            String one = "";
            for (int i = 0; i <10;)
            {
                i++;
                one += i; 
            }
            System.out.println(one);
        }
        public static void TransactionCount()
        {
            AddTransaction count = new AddTransaction;
            
        }
    
        public static void Total()
        {
        }
    
        public static void ResetTransactions()
        {
        }
    
        public static void RegisterCount()
        {
        }    
     }
}

Recommended Answers

All 3 Replies

The class and the application that instantiates it should be separated.

I really need help making the methods and understanding the questions

Your class (in a separate file) should start like this:

//CashRegister.java
public class CashRegister
{
	protected int m_intTransCount;
	protected double m_dblAmount;
	protected static int m_intObjCount = 0;
}

Inside that class, you should have a constructor, a finalize() and five other methods (like you've already done).

Once you have created that class, you should create another class with a main() in it that will create at least two CashRegister objects:

//UseCashReg.java
public class UseCashReg
{
	public static void main(String args[])
	{
		CashRegister cashReg1 = new CashRegister();
		System.out.println(cashReg1.RegisterCount());

		CashRegister cashReg2 = new CashRegister();
		System.out.println(cashReg1.RegisterCount());
	}
}

You can even use the other five methods you will create to increment and total amounts.

commented: Thanks that was very helpfull +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.