Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Summary Build two classes (Money and Bill) for use in managing a set of outstand

ID: 3625990 • Letter: S

Question

Summary

Build two classes (Money and Bill) for use in managing a set of outstanding and paid bills. Submit these two classes and a test driver that exercises all functionality for these classes.
Introduction

Just as in previous assignments, we will not only be focusing on code, but also taking a “bigger picture” view of the overarching design, using the software development techniques learned this week (specifically, class invariants, privacy leaks, and more on object composition). You experimented with interface design in the last lab (as you built the BlogEntry interface), and in this assignment, both interfaces are already defined for you. Once you have classes implemented for Money and Bill, you will need to develop a test harness (or testing strategy) to exercise the functionality of your class. I’ve provided a sample driver that may need additional testing as a starting point (HW3.java), but this is simply a starting point and will not test every function in Bill or Money (and your final driver should). Since a Bill makes use of a Money object, we can start our development there, but first, a bit on the class invariants we will want to build into our system…


Enforce the Following Class Invariants

(1) Our internal cents should be between [0,…,99] at all times

(2) Our internal Cents and Dollars should never be < 0, at all times

(3) Data privacy should be maintained at all times; verify there are no privacy leaks such as returning aliases to an private object instance variable when you really should be returning a copy of that object instead. (be sure to make prevent a similar type of privacy leak by making copies of all incoming objects as well in set methods)

(4) The Bill class’s internal paid date should be on or earlier than the due date.


The Money Class

See Lab3.doc for the specific details on how to build and test the Money class.


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 isn’t past the due date – if so, either quit (System.exit()) with an error message or throw an exception.




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

Money getAmount() – return the amount*

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*

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 we’ve 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.




Hints

· First, test out HW3.java with your classes – then extend that to test each function in Bill and Money.

· Be sure to document your code with comments, highlighting the class invariants where they are relevant

· Watch out for privacy leaks in your getters, setters, and constructors!

//
/**
HW3.java: Simple driver to test Money and Bill classes

*/
public class HW4
{

/**
main driver function
pre: none
post: exercises the methods in Bill and Money
*/
public static void main(String[] args)
{
//Construct some money
Money money1 = new Money(10);
Money money2 = new Money(money1);
money1.setMoney(30,50);
//TODO: do more functional exercises with the money class


System.out.println("Money objects output:");
System.out.println(money1);
System.out.println(money2);


//Construct some bills
Money amount = new Money(20);
Date dueDate = new Date(4, 30, 2007);
Bill bill1 = new Bill(amount, dueDate, "The phone company");

Bill bill2 = new Bill(bill1);
bill2.setDueDate(new Date(5, 30, 2007));
amount.setMoney(31, 99);
dueDate.setDay(29);
Bill bill3 = new Bill(amount, dueDate, "The record company");

System.out.println("Bill objects output:");
System.out.println(bill1);
System.out.println(bill2);
System.out.println(bill3);

}
}

Explanation / Answer

use http://www.wolframalpha.com/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote