Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Classes and Objects -------------------------------------- Define a class named Money that stores a monetary amount. The class should have two private integer variables, one to

Java Classes and Objects

--------------------------------------

Define a class named Money that stores a monetary amount. The class should have two private integer variables, one to store the number of dollars and another to store the number of cents. Include a default constructor that initializes the amount to $0.00 and an overloaded parameterized constructor to initialize any non-zero amount (as demonstrated in the example program below). You must develop your solution with two separate files; your class file and your file containing your main function Add the following accessor member functions: getDollars( ): returns the privateintdollars. Should not be able to modify the data. getCents( ): returns the privateintcents. Should not be able to modify the data. Add the following mutator member functions: setDollars( ): sets the privateintdollars. Does not return anything. setCents( ): sets the privateintcents. Does not return anything. Add a condition to your setCents() mutator that will update the dollars member if the cents input argument is 100 or larger. For example: a function call to setCents(135)would set the cents member to 35, and increase the current dollar amount by 1. setCents(235)would set the cents member to 35, and increase the current dollar amount by 2. Add another member function named getAmount() that returns the monetary amount as a single double number. Write a main() program that tests all of your member functions with at least two different Money objects. In addition to testing your mutators, your code should be able to print the following output (or similar) using your getDollars() and getCents(), or just the getAmount() member functions as shown in the sample console output below:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

ISBN: 0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago