java/programming

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){
this.toonies=toonies;
this.loonies=loonies;
this.quaters=quarters;
this.dimes=dimes;
this.nickels=nickels;
this.pennies=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+
"\ndimes:"+dimes+"\nnickels:"+nickels+"\nPennies"+pennies;
}

  1. 👍 0
  2. 👎 0
  3. 👁 63
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. java/programming

    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

    asked by Anonymous on December 6, 2018
  2. 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
  3. 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
  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 8, 2016
  5. 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 8, 2016
  6. 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
  7. 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
  8. 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
  9. 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
  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

More Similar Questions