Forums Register Login

How to write a method named “transaction” in the missing part?

+Pie Number of slices to send: Send
This is a program that works like a bank account. It has the deposit, withdrawal, and transaction. But, I have troubles doing the transaction part of the program. I need a method named transaction to help a local banker, and the method needs to utilize TWO input parameters and the method’s return value (for its output).

It should satisfy the following specification: – a method named transaction which takes : ∗ a customer’s current balance ∗ the amount of money to update the account by : · a positive dollar amount is a deposit · a negative dollar amount is a withdraw as input parameters, and then returns ∗ for deposits: the deposit amount is simply returned by the function. ∗ for withdraws: the balance must not become negative. If a withdraw is requested for more than the current balance then the amount (which would zero the balance if withdrawn) is returned by the method. Otherwise, the withdrawn amount is simply returned by the method.

This is the program I have so far(without the transaction method):
Thank you

+Pie Number of slices to send: Send
 

for deposits: the deposit amount is simply returned by the function.


How would you do just that much?
+Pie Number of slices to send: Send
Welcome to the Ranch

I am afraid, that is not a program which behaves like a bank account. It makes does not record owner or balance. You need a class called BankAccount or similar, and has appropriate methods to alter that. Make sure you have a constructor which initialises all the fields to “real” values and don't give the class any setXXX methods.
+Pie Number of slices to send: Send
Unfortunately you seem to have to write a method taking the balance and an amount. Not something I would do, but you are stuck with it.
+Pie Number of slices to send: Send
Welcome to the Ranch, sarah maani!

I'm curious, is this schoolwork? Is this a regular brick and mortar school or is this from an online course you're taking?
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 405 times.
Similar Threads
Help code problem please
Having trouble understanding an error code i keep getting. Please help!
How to pass input to other class methods
need help with code
Having troubles with a complex program, need help with an illegal start of type error.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:13:35.