• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
sarah maani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for deposits: the deposit amount is simply returned by the function.

How would you do just that much?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!