# Thread: Need Help !

1. Registered User
Join Date
Sep 2004
Posts
2

## Need Help !

Write a third class called Print that will be used to output information. Complete the class TestPurse.

import javax.swing.JOptionPane;
class Coin
{
//Set up variables for each denomination
private int count;
private String name;

Coin(String name, int count)
{
//Create a new Coin object
this.count = count;
this.name = name;
}

String nameOfCoin()
{
//Implementation - Return the name of the coin
return name;
}

int getValue()
{
//Implementation - Return the amount of money value of the coin
return count;
}
}

class Purse
{
private static final double NICKEL_VALUE = 0.05;
private static final double DIME_VALUE = 0.10;
private static final double QUARTER_VALUE = 0.25;

// Complete the declaration of the constants representing the coins
private double total;

Purse()
{
total = 0;
}

public void add(Coin aCoin)
{
// Calculate the amount of money in the purse.
if (aCoin.nameOfCoin().equalsIgnoreCase("NICKEL"))
total = total + aCoin.getValue()*NICKEL_VALUE;

else if (aCoin.nameOfCoin().equalsIgnoreCase("DIME"))
total = total + aCoin.getValue()* DIME_VALUE;

else if (aCoin.nameOfCoin().equalsIgnoreCase("QUARTER"))
total = total + aCoin.getValue()* QUARTER_VALUE;

}

double getTotal()
{
}

}

class Print
{

{
System.out.println(myPurse.nameOfCoin() + myPurse.getValue()+"amount of money is"+ myPurse.getTotal());
}//error, but why?
}

/**
This program tests the Purse class.
*/

class TestPurse
{
public static void main(String[] args)
{

// Create an empty Purse object here
Purse myPurse = new Purse ();

boolean done = false;
while (!done)
{
String input = JOptionPane.showInputDialog("Enter name of coin or click the Cancel button");

if (input.equals(""))
done = true;
else
{
input = JOptionPane.showInputDialog("Enter number of coins");
int numberOfCoin = Integer.parseInt(input);

// Create coin object
Coin myCoin = new Coin(input, numberOfCoin);

// Add coin object to purse

/* Pass the coin object to the print class to
(1)To print the name of each coin, and
(2)the total value of each coin object
*/
}
}

// Use the class Print to print the total amount of money in the purse.

myPurse.Print; //error

System.exit(0);
}
}

2. seems like a school assignment to me. I think a better option will be that you tried it out and then posted your specific concerns and questions...

3. Registered User
Join Date
Sep 2004
Posts
2
i made it work, thanks !!

4. Originally posted by Scar78
i made it work, thanks !!
thats awsome feeling isn't it...