Defining Classes Write and document the definition for the Money class. The Money class represents an amount in U.S. dollars. Money Class e Fields cents : int dollars : int e Methods getValue() : double Money(int d, int c) setCents(int c) : void setDollars(int d) : void toString() : String • Each Money object has two int instance variables: dollars and cents. • The class has one constructor that takes two int parameters. The first int represents whole dollars, and the second int represents cents. • The class has one accessor method named getValue() which returns the amount as a double. (Just divide cents by 100.0 and add it to dollars. Return that amount.) • The class has two mutator methods-setDollars() and setCents()–that modify the corresponding instance variables. • The class has a toString() method that returns the amount as a String in the form: $ 2345.75. Use concatenation to produce the output. Do not worry about the decimal places.
Defining Classes Write and document the definition for the Money class. The Money class represents an amount in U.S. dollars. Money Class e Fields cents : int dollars : int e Methods getValue() : double Money(int d, int c) setCents(int c) : void setDollars(int d) : void toString() : String • Each Money object has two int instance variables: dollars and cents. • The class has one constructor that takes two int parameters. The first int represents whole dollars, and the second int represents cents. • The class has one accessor method named getValue() which returns the amount as a double. (Just divide cents by 100.0 and add it to dollars. Return that amount.) • The class has two mutator methods-setDollars() and setCents()–that modify the corresponding instance variables. • The class has a toString() method that returns the amount as a String in the form: $ 2345.75. Use concatenation to produce the output. Do not worry about the decimal places.
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
Related questions
Question
![Defining Classes
Write and document the definition for the Money class. The Money class represents an amount in U.S.
dollars.
Money
Class
e Fields
cents : int
dollars : int
e Methods
getValue() : double
Money(int d, int c)
setCents(int c) : void
setDollars(int d) : void
toString() : String
• Each Money object has two int instance variables: dollars and cents.
• The class has one constructor that takes two int parameters. The first int represents whole dollars,
and the second int represents cents.
• The class has one accessor method named getValue() which returns the amount as a double. (Just
divide cents by 100.0 and add it to dollars. Return that amount.)
• The class has two mutator methods-setDollars() and setCents()–that modify the corresponding
instance variables.
• The class has a toString() method that returns the amount as a String in the form: $ 2345.75. Use
concatenation to produce the output. Do not worry about the decimal places.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3200e892-7b83-4670-8aa5-c4c84f2a6adb%2F82861ae8-51ab-44a8-9e5a-f776667bb9da%2F8yiz7xq.jpeg&w=3840&q=75)
Transcribed Image Text:Defining Classes
Write and document the definition for the Money class. The Money class represents an amount in U.S.
dollars.
Money
Class
e Fields
cents : int
dollars : int
e Methods
getValue() : double
Money(int d, int c)
setCents(int c) : void
setDollars(int d) : void
toString() : String
• Each Money object has two int instance variables: dollars and cents.
• The class has one constructor that takes two int parameters. The first int represents whole dollars,
and the second int represents cents.
• The class has one accessor method named getValue() which returns the amount as a double. (Just
divide cents by 100.0 and add it to dollars. Return that amount.)
• The class has two mutator methods-setDollars() and setCents()–that modify the corresponding
instance variables.
• The class has a toString() method that returns the amount as a String in the form: $ 2345.75. Use
concatenation to produce the output. Do not worry about the decimal places.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT