CSCI 51, Fall 2008
Problem Set 4
4%
100 points
Assigned: Tuesday, October 7, 2008
Due: Sunday, October 12 at 11:59pm
Description
This assignment, as the first, has parts. Please be sure to name
the classes as I specify. Turn in DecimalToBinary.java and
BankAccount.java.
Program 1: 50pts
Create a class called DecimalToBinary. This class
for example might contain only the main
method that was the problem on page 5 of the midterm, but I'm
looking for better abstraction.
Start by making the main method
only ask for an input number, negative to quit. As long the
user continues to enter in non-negative numbers, the main method should
call on the convert
method, which takes an integer and returns a String that is the 12 bit
binary representation of
the entered integer. The convert
method in turn calls on the pow
method to compute powers
of 2. The pow method
takes two integers a and b and returns the integer a ^ b.
Program 2: 50pts
Create a class called BankAccount. Have the data
members of the BankAccount be a String
representing an account name and a double representing an account
balance. Have the
constructor method take a String and double accordingly. The
class should also implement
the methods:
equals(BankAccount
other) that returns true if the two bank accounts are the same.
getAccount()
that returns the bank account name of this account.
getBalance()
that returns the balance.
deposit(double
amount) that adds amount to the account balance.
withdraw(double
amount) that subtracts the amount from the account balance.
toString()
that returns a String that represents the account.
Remember to check for impossible activities, such as depositing a
negative amount or
withdrawing from an account with a negative balance.
I will test your BankAccount class with a BankAccountTester class whose main
method
instantiates an account, adds and withdraws and prints the
account. You should consider
writing your own.