www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need Help !

  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Lightbulb 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()
    {
    return total;
    }

    }

    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
    myPurse.add(myCoin);

    /* 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. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,123
    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...
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Sep 2004
    Posts
    2

    Wink

    i made it work, thanks !!

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,123
    Originally posted by Scar78
    i made it work, thanks !!
    thats awsome feeling isn't it...
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles