Falorthint
September 28th, 1999, 04:36 PM
Writing a program using multiple source files.
Problem: Assume you have a stack of bills and are sitting down to write monthly checks. You don't know beforehand how many bills you can pay with your limited funds. but you do know you can't pay them all. Your bills are arranged in order of the payment due date. You simply pay bills until you money runs out.
Analysis: You will pay each bill in order and stop writing checks when you run out of money. In other words, you should continue writing checks as long as your account balance is positive(greater than zero). The state at which to stop is when the "account balance is equal to zero or there is a negative balance." The problem inputs are you intial account balance and the amount of each bill. Since the bills are already in order. you do not need to worry about the due date. The problem outputs are the amount paid on each bill and the final account balance.
Data requirements:
Problem Inputs:
initial account balance
each bill amount
Problem Output:
amount paid on each bill
final account balance
Revelant formulas:
account balance = account balance - amount paid
Design: There are really two class in this problem. One is the class Bill and the other is the class Chekcing Account. Class checking account has a data field for the account balance and methods to read the inital balance, pay all bills, and update account balance.
Specifications for Checking Account class
Data fields: double balance - account balance
Methods:
readBalance - reads the intial account balance
payAllbills - pays as many bills as possible
displayBalance - displays the account balance
Relevant formulas: balance = balance - amount paid
Specification for Bill class
Data fields: doulbe amount - amount of current bill
Mehtods:
readBill- reads the bill
payBill pays the bill in full or part and updates the balance.
Algorithm for payBill class (class Checking Account)
1. Create a Bill object
2. While the account balance is positive
3. Get the next bill.
4. Pay the next bill and update account balance.
Algorithm for payBill(class Bill)
1. if the account balance >= bill amount
2. Pay the full amount of the bill and deduct it from the account balance.
3. Else
4. Pay the amount of the account balance and set balance to zero.
Algorithm for main (class BillPayer)
1. Read the intial account balance.
2. Pay all bills showing the amount paid for each bill.
3. Display the final balance.
Sample run
Starting balance $
30
Pay bill in full. new balance si $70.0
Bill amount $
20
Pay bill in full. new balance is $50.0
Bill amount $
3
Pay bill in full. new balance is $20.0
Bill amount $
Pay bill in full. new balance is $0.0
Balance is $0.0
Problem: Assume you have a stack of bills and are sitting down to write monthly checks. You don't know beforehand how many bills you can pay with your limited funds. but you do know you can't pay them all. Your bills are arranged in order of the payment due date. You simply pay bills until you money runs out.
Analysis: You will pay each bill in order and stop writing checks when you run out of money. In other words, you should continue writing checks as long as your account balance is positive(greater than zero). The state at which to stop is when the "account balance is equal to zero or there is a negative balance." The problem inputs are you intial account balance and the amount of each bill. Since the bills are already in order. you do not need to worry about the due date. The problem outputs are the amount paid on each bill and the final account balance.
Data requirements:
Problem Inputs:
initial account balance
each bill amount
Problem Output:
amount paid on each bill
final account balance
Revelant formulas:
account balance = account balance - amount paid
Design: There are really two class in this problem. One is the class Bill and the other is the class Chekcing Account. Class checking account has a data field for the account balance and methods to read the inital balance, pay all bills, and update account balance.
Specifications for Checking Account class
Data fields: double balance - account balance
Methods:
readBalance - reads the intial account balance
payAllbills - pays as many bills as possible
displayBalance - displays the account balance
Relevant formulas: balance = balance - amount paid
Specification for Bill class
Data fields: doulbe amount - amount of current bill
Mehtods:
readBill- reads the bill
payBill pays the bill in full or part and updates the balance.
Algorithm for payBill class (class Checking Account)
1. Create a Bill object
2. While the account balance is positive
3. Get the next bill.
4. Pay the next bill and update account balance.
Algorithm for payBill(class Bill)
1. if the account balance >= bill amount
2. Pay the full amount of the bill and deduct it from the account balance.
3. Else
4. Pay the amount of the account balance and set balance to zero.
Algorithm for main (class BillPayer)
1. Read the intial account balance.
2. Pay all bills showing the amount paid for each bill.
3. Display the final balance.
Sample run
Starting balance $
30
Pay bill in full. new balance si $70.0
Bill amount $
20
Pay bill in full. new balance is $50.0
Bill amount $
3
Pay bill in full. new balance is $20.0
Bill amount $
Pay bill in full. new balance is $0.0
Balance is $0.0