Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Money Class This class is used to track a USD amount consisting of two integers to manage dollars and cents. All dollars and cents

The Money Class

This class is used to track a USD amount consisting of two integers to manage dollars and cents. All dollars and cents will be positive or 0, and cents will never exceed 99. The data and methods below will be called from the test driver Ill use, so be sure to adhere to the names of the functions, as well as the number, order, and type of arguments handed to each function, as indicated below. Also, previous labs and lectures contains hints and details on how to build and test the Money or Date class.

Data Members

You should define a pair of instance variables for use in tracking dollars and cents These should be private and avoid privacy leaks.

Method Members

Money(int dol)

This constructor initializes using dollars input and assumes no cents

Remeber: Cents can never be higher than 99

Money(int dol, int cent)

This constructor initializes dollars and cents accordingly

Money(Money other)

This constructor could redirect to the one above

Getters/setters for dollars and cents

These should be careful to not invalidate class invariants

Also these functions should avoid privacy leaks

double getMoney()

A getter for the total monetary amount, as a double

Returns 5.75, for example

void setMoney(int dol, int cent)

Sets our dollars and cents, accordingly

This function should make use of setters for dollars and cents

void add(int dol)

Adds the int passed into the function to dollars

void add(int dol, int cents)

Adds to dollars and cents the two ints passed into the function.

void add(Money other)

Adds to this object the dollars and cents stored in the other object.

boolean equals(Object o)

Determines if this money object is equal to that Money object

String toString()

Prints out a Money object as a String, such as $3.75

The Bill Class

Construct a class for use as a bill that contains data related to an outstanding or paid bill of a specific amount of money. The class should contain the amount of the bill as a Money object, the due date of the bill (a Date object) and a Date object to track the date paid (null if not yet paid). Check to be sure that when paying the bill, the date isnt past the due date if so, either quit (System.exit()) with an error message or throw an exception. (Note: either build a Date class(more simple and direct) or use Javas Date class.)

Data as Instance Variables:

amount a Money object

dueDate a Date object

paidDate a Date object, null if not yet paid

originator a String containing the company or institution who issued the bill

Methods in the Public Interface:

Bill(Money amount, Date dueDate, String originator)

constructor (null for paidDate)

Bill(Bill toCopy)

copy constructor

Date getDueDate() return the dueDate*

String getOriginator() return the originator

boolean isPaid() return true if bill has been paid

void setPaid(Date onDay) make the bill paid, save the date*

void setUnpaid() make the bill unpaid

void setDueDate(Date nextDate) set the due date of the bill*

void setAmount(Money amount) change the amount*

Money getAmount() provide the Money object for the bill that is the amount*

void setOriginator(String originator)* - change the originator

String toString() build a string that reports the amount, when its due, to whom, whether paid, and if paid, the date paid.

boolean equals(Bill toCompare) determine if the two bills are identical

*Note: The items starred above are to be considered critical sections in your code where it could be very easy to violate the class invariants that weve defined above. Proceed carefully in these functions and be sure that, for example, calling setPaid() with a date that is after the due date will fail, or that calling setDueDate() with a date that is before the paid date will also fail.

The Date Class

This should be similar to the Date classes weve covered in class and in the textbook. Do not use any built-in Date classes for this assignment, and provide all of the common class components for this Date. For example, you should add:

Data Members

These data items should be private or final

Constructors & copy constructors

Getters/setters for month, day and year

boolean equals(Object o)

String toString()

Method Members

Follow the Savitch examples for how to build the methods needed in a Date class.

The Driver should test all methods

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Alcohols 33 Ethers 3 Aromatic Compounds

Answered: 1 week ago

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago