All pastes #26303 Raw Edit

Someone

public text v1 · immutable
#26303 ·published 2005-10-22 19:25 UTC
rendered paste body
package money;
public class Money
{
	//data field
	public static final char SYMBOL = "$";
	private long dollars;
	private long cents;
	public Money()
	
	{
		dollars = 0;
		cents = 0;
	}
	
	public Money (long initDollars, long initCents)
	{
		dollars=initDollars;
		cents=initCents;
	}
	
	public void initialize (long newDollars, long newCents)
	
	{
		dollars = newDollars;
		cents = newCents;
	}
	
	public long dollarsAre()
	{
		return dollars;
	}
	
	public long centsAre()
	{
		return cents;
	}
	
	public void print ()
//Prints dollars and cents on System.out
	{
		System.out.print ("" +Money.SYMBOL +dollars + '.' +cents);
	}

public Money add (Money value)
//returns sum of objects plus value.
	{
		Money result = new Money();
		result.cents = cents + value.cents;
		result.dollars = dollars +value.dollars;
		return result;
	}
}

import money.*;

public class UseMoney
{
	public static void main (String[] args)
	{
		Money money1;
		Money money2;
		Money money3;
		money1 = new Money (10, 59);
		money2 = new Money (20, 70);
		money3 = money1.add(money2);
		System.out.println("" +Money.SYMBOL +money3.dollarsAre() + '.' +money3.centsAre());
// I think this is where the problem was -- inputting Money.SYMBOL might fix it because you're taking the SYMBOL which is in the // Money class in the package... that's my reasoning at least
	}
}