i did this code for this question. Write a class called PocketChange that models a handful of change you might find in your pocket. The class has the following specifications:
• Instance Variables - all instance variables are private!
- int toonies - the number of toonies in the user's pocket
- int loonies - the number of loonies in the user's pocket
- int quarters - the number of quarters in the user's pocket
- int dimes - the number of dimes in the user's pocket
- int nickels - the number of nickels in the user's pocket
- int pennies - the number of pennies in the user's pocket
• Methods:
- PocketChange() - default constructor assigns 0 as a default value to all instance variables.
- PocketChange(toonies, loonies, quarters, dimes, nickels, pennies) - sets the values of all the instance variables to the programmer-specified parameter values.
- calculateTotal method will
calculate and return the total amount of money in the user's pocket, based on the values in each of the instance variables.
- toString() - returns a String with the following format:
- Toonies: t
- Loonies: L
- Quarters: q
- Dimes: d
- Nickels: n
- Pennies: p
where t, L, q, d, n, and p are the number of toonies, loonies, quarters, dimes, nickels and pennies.
In the main method:
Write a test program to test your class.
Get user input for the pocket change he has right now. And then calculate the total value of the change. i did this code but there one line that is not working:this(toonies:0,loonies=0,quaters=0,dimes=0,nickels=0,pennies=0);

the code that i did is:
private int toonies;
private int loonies;
private int quaters;
private int dimes;
private int nickels;
private int pennies;

public PocketChange(){
// this(toonies:0,loonies=0,quaters=0,dimes=0,nickels=0,pennies=0);
public PocketChange(int toonies,int loonies, int quarters, int dimes, int nickels, int pennies){
public double calculateTotal(){
return toonies*2+ loonies*1 +quaters*0.25+dimes*0.10+nickels*0.05+pennies*0.01;
public String toString(){
return "Toonies: "+toonies+ "\nLoonies"+loonies+"\nQuaters: "+quaters+

  1. 👍 0
  2. 👎 0
  3. 👁 51
asked by Anonymous
  1. looks reasonable. Did you run it?

    1. 👍 0
    2. 👎 0
    posted by Steve
  2. yes but this line is giving me error: toonies and the semicolon this(toonies:0,loonies=0,quaters=0,dimes=0,nickels=0,pennies=0);

    1. 👍 0
    2. 👎 0
    posted by Anonymous

Respond to this Question

First Name

Your Response

Similar Questions

  1. Programming

    Here is the question that I need help to write the code for the following program in Visual Basic 2010. I am trying to write the code but it has a run time error. If your could helps me to write the code it would be greatly

    asked by Solomon on May 18, 2011
  2. Programming

    The code below shows some of the text for a class called City. Now write a complete public constructor with two formal parameters: a String parameter called cityName, and an int parameter called cityPop. Your code should

    asked by Natalie on November 9, 2009
  3. Math fraction

    I took a handful of M&Ms. One third of them were red. What might my handful look like? How would a mathematician represent it? This is a fraction question. Can you please help me with this. Thank you.

    asked by math eagle on November 9, 2016
  4. math fraction

    I took a handful of M&Ms. One third of them were red. What might my handful look like? How would a mathematician represent it? This is a fraction question. Can you please help me with this. Thank you.

    asked by math eagle on November 9, 2016
  5. basic programming principles

    2.Write only the select case statements for the following problem statement. The marital code of a person is stored in the variable called marCode. Display the corresponding description on the screen. Provide for an incorrect

    asked by victor on March 31, 2015
  6. Math,Science,Algebra,geography

    The 3 Letter code that summaries your 3 strongest career types is called your? A.)Holland-Code B.)Myers-Briggs Type C.)Teamwork Profile D.)Beblin Code

    asked by DJ on September 30, 2015
  7. brcm

    diffrent models of computer What is your question? What is your thinking on it? If you're looking for different models of computers, I would look at web sites that sell computers. Even better- go to ebay. Look under the computer

    asked by vikas on June 15, 2007
  8. pseudo code algorithm

    Convert your algorithm from Question One into a complete Java application. Marks will be allocated based upon: ● Your Java code matching your pseudo code algorithm from Question One. ● Your Java code being syntactically

    asked by husanpreet on April 27, 2016
  9. math

    A handful of paper clips is 5.2 grams. A handful of push pins is 500 centigram a. Which handful weighs more? So 1c equals .o1 grams so isn't it 5.2 g compared to .05 grams which then means the paper clips are heavier? Thx for any

    asked by Jen on April 10, 2015
  10. C++

    class professor {}; class teacher : public virtual professor {}; class researcher : public virtual professor {}; class myprofessor : public teacher, public researcher {}; Referring to the sample code above, if an object of class

    asked by Jason on July 25, 2007
  11. C code

    Write a .c file named calc that: - Takes arguments from the command line - Solves a simple math problem - Returns the result as an exit status calc.c: //this is the function that gets called when the executable is run. int

    asked by Nick on February 7, 2013

More Similar Questions