I'm trying to create a Cash register that accepts euros. I don't even know where to begin. So far I have:

public class Coin
{
public Coin()
{
name = " ";
value = 0;
}
public Coin(String n, int v)
{
name = n;
value = v;
}
public String getName()
{
return name;
}
public int getValue()
{
return value;
}
public static final int AEURO_vALUE = .01;
public static final int SEURO_VALUE = .02;
public static final int FEURO_VALUE = .05;
public static final int TEURO_VALUE = .10;
public static final int TWEURO_VALUE =.20;
public static final int FFEURO_VALUE =.50;
public static final int HEURO_VALUE = 100;
public static final int THEURO_VALUE = 200;

Edited 3 Years Ago by happygeek: fixed formatting

So you want to be able to add money to the cash register basically right? So so the user wants to add 5 euros, they type in 5 or whatever and it adds it to the total value/money in the register already?

If you explain exactly what the program has to do I could probably help with this.

That's basically it. Since my last post I've been working hard on it. I was able to get it to compile and it does; but now I'm having problems getting it to return a value. I'm currently not at home and of course I forgot my flash drive that has the program. I will send you what I have so far later on around 5 or 5:30. I have to create a CashRegister and a Coin class as well as a tester program. The coins will have names and values. The Coin constructor will take a name and a value parameter. The coin class will have getName and getValue methods.

It will have coin names that represent real coins. There are 8 coins to be represented as follows:
1 = 1 cent euro
2 = 2 cent euro
5 = 5 cent euro
10 = 10 cent euro
20 = 20 cent euro
50 = 50 cent euro
100 = 1 euro
200 = 2 euro

Thanx.

Sorry it took so long to get back to you. Here is the code:

public class Coin
{
    public Coin()
    {
        value = 0;
        valueone = 0;
        name = " ";
    }
    public Coin(double v, double m, String n)
    {
        value = v;
        valueone = m;
        name = n;
    }
    public Coin(String n)
    {
        name = n;
    }
    public double getValue()
    {
        double total = value + valueone; 
        return total;

    }
    public String getName() 
    {
        return name;
    }

    public static final double AEURO_vALUE = .01;
    public static final double SEURO_VALUE = .02;
    public static final double FEURO_vALUE = .05;
    public static final double TEURO_VALUE = .10;
    public static final double TWEURO_VALUE = .20;
    public static final double FFEURO_VALUE = .50;
    public static final double ONEEURO_VALUE = 1.00;
    public static final double TWOEURO_VALUE = 2.00;


    private double value;
    private double valueone;
    private String name;



}


//Note:  After compiling if it runs well, then try
//       to add name.getName to value.getValue, so amt and
//   string are on the same line.



import java.util.*;

public class CoinTester
{
    public static void main(String [] args)
    {
        Scanner in = new Scanner(System.in);

        //Coin name = new Coin("Euro");


        System.out.println("Enter amount: "); // + worth.getValue() );
        double value = in.nextDouble();

        Coin worth = new Coin();

        //System.out.println("What is the value of: ");
        //double value = in.nextDouble();

        System.out.print("The value is =");
        System.out.println(worth.getName());

        //System.out.print("The name is called:");
        //System.out.println(name.getName());
    }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I think what would be helpful to start is not your code but your algorithm; better, what exactly it is that your program is supposed to do.

For example, let's say that the program is supposed to accept an input in euro cents, and comes up with a list of the smallest number of coins that should be returned as change. Thus, an input of 532 euro cents would return:

2: two euro coins
1: one euro coins
1: twenty cent euro
1: ten cent euro
1: two cent euro

Once I know what the problem is, I can make plans to solve it. For example, I'll need to have the names of the coin types somewhere, either in an array or as a series of print commands in a conditional statement. I might then use modular division to come up with the amounts in each category.

I'm not sure what exactly it is that your cash register is supposed to do. Actually modelling the various requirements after they're known is relatively easy.

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