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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
icon
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT