Results 1 to 3 of 3
Thread: Need Help with Java
- 04-04-2011, 05:24 AM #1Member
- Join Date
- Apr 2011
- Rep Power
Need Help with Java
Please help me with the following:
1. Create a CreditCard class according to the UML Diagram on the back. It
should have data fields that include an owner of type Person, a balance of type Money, and a creditLimit of type Money.
2. It should have a constructor that has two parameters, a Person to initialize the owner and a Money value to initialize the creditLimit. The balance can be initialized to a Money value of zero. Remember you are passing in objects (pass by reference), so you have passed in the address to an object. If you want your CreditCard to have its own creditLimit and balance, you should create a new object of each using the copy constructor in the Money class.
3. It should have accessor methods to get the balance and the available credit.
Since these are objects (pass by reference), we donít want to create an insecure credit card by passing out addresses to components in our credit card, so we must return a new object with the same values. Again, use the copy constructor to create a new object of type money that can be returned.
4. It should have an accessor method to get the information about the owner, but in the form of a String that can be printed out. This can be done by calling the toString method for the owner (who is a Person).
5. It should have a method that will charge to the credit card by adding the
amount of Money in the parameter to the balance if it will not exceed the credit limit. If the credit limit will be exceeded, the amount should not be added, and an error message can be printed to the console.
6. It should have a method that will make a payment on the credit card by subtracting the amount of Money in the parameter from the balance.
7. Compile, debug, and test it out completely by running CreditCardDemo.java. (attached to this post)
You should get the output:
Diane Christie, 237J Harvey Hall, Menomonie, WI 54751
Credit Limit: $1000.00
Attempt to charge $200.00
Attempt to charge $10.02
Attempt to pay $25.00
Attempt to charge $990.00
Exceeds credit limit
- 04-04-2011, 05:40 AM #2
This is not a code generation site. It is your homework so you must write it. Make an attempt, post your code here, post any error message(s) and ask a specific question.
- 04-04-2011, 07:42 AM #3
- Join Date
- Sep 2008
- Voorschoten, the Netherlands
- Blog Entries
I have the stamina of a seal; I lie on the beach instead of running on it.
- Rep Power