• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help with my program on Input/Output

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having some trouble with this program. I'm new to the java programming language so I don't know much. Can someone help me?

The instructions are: To process the transactions, you will need to read one line at a time from the transactions.txt file and parse the String that you retrieve. You can use the Scanner class for this. The delimiter will be a colon. Then process the transaction; you do not need to check the type of transaction. Just add the amount of the transaction to the checkbook balance. Adding a negative transaction amount will decrease the balance as expected. Be sure to use try/catch blocks where appropriate.

After you have processed each transaction, call the animate method. This method belongs to the Accounting class, so you will call animate without using an object reference. The API if the animate method is the following

public void animate { String currentTransaction, double currentAmount, double currentBalance, }

As you can see, the animate method takes three arguments: currentTransaction is the transaction name ("Deposit," for example), currentAmount is the amount of the transaction (-45.00, for example), and currentBalance is the current balance of the checkbook. Assuming that you have a String variable called transactionName, a double variable called amount, and another double called balance, a call to animate will look like the following:

animate( transactionName, amount, balance);

When you call the animate, the window will display the current transaction geographically. It will also display the transaction amount (red, if negative, blue if positive), and the current checkbook balance (in black). By adding the previous checkbook balance to the current amount, you will be able to compute in your head what the current checkbook valance should be and determine if your program is working correctly.

When you reach the end of the file, print the final balance and write it to a file named balance.txt

So far, I have coded this much in the Accounting class:



Can someone please help?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.
Also I think this would be better in the beginners forum so I'll move it to there for you.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So far, I have coded this much in the Accounting class:


Please can you show which bits of the class you have coded because to me that looks like the class you have been provided by your teacher.

Can someone please help?


Certainly, but you have to tell us what you are stuck on. Just dumping your homework question and saying "please help" isn't enough information for us to be able to advise you.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K Pallete wrote:Can someone please help?



I would suggest you do this:

//
// Using a while loop, read the file transactions.txt
// The file transactions.txt contains
// transactions between you and your bank
//
// You will need to call the animate method inside
// the body of the loop that reads the file contents
//
// The animate method takes three arguments:
// a String, representing the type of transaction
// a double, representing the transaction money amount
// a double, representing the new checkbook balance
// So if these three variables are:
// transactionName, currentAmount, and balance,
// then the call to animate will be:
//
// animate( transactionName, currentAmount, balance );
//
// You should make that call in the body of your while
// loop, after you have updated the checkbook balance
//

If there is some specific part of that you need help with, let us know.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic