aspose file tools*
The moose likes Beginning Java and the fly likes Having trouble understanding an error code i keep getting. Please help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having trouble understanding an error code i keep getting. Please help!" Watch "Having trouble understanding an error code i keep getting. Please help!" New topic
Author

Having trouble understanding an error code i keep getting. Please help!

dannygirl sylvest
Greenhorn

Joined: Oct 18, 2010
Posts: 9
I'm doing an assignment where i have to Design a SavingsAccount class that stores a savings account's annual interest rate and balance. the class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of withdrawal, add the amount of deposit, and adding the amount of monthly interest to the balance. The monthly interest rate is the annual interest rate divided by 12.


45 minutes ago - 1 week left to answer.
Additional Details
I forgot to mention what my project consisted of: Design a SavingsAccount class that stores a savings account's annual interest rate and balance. the class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of withdrawal, add the amount of deposit, and adding the amount of monthly interest to the balance. The monthly interest rate is the annual interest rate divided by 12. To add the monthly interest to the balance, multiply the monthly interest rate by the balance, and add the result to the balance. ( this is compound interest ) Use DecimalFormat class to format output.





I'm new at this and i am still trying to grasp the concept of calling methods and the use of constructors. When i run my code this is what happens
Your total deposit is 0.0
Your total withdrawls were 0.0
Your total interest is 0.008333333333333333
Your total balance is $ 1,000.01
Calculate the month 2 (Y/N)
Exception in thread "main" java.lang.StringIndexOutOfBoundsExceptio… String index out of range: 0
at java.lang.String.charAt(String.java:686)
at assignment06.testAccount.main(testAccoun…
Java Result: 1
BUILD SUCCESSFUL (total time: 11 seconds)

i'm still not sure exactly what is going wrong . Thanks for your input

[fbr - added code tags]
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
Welcome to the Java Ranch!
Please can you use UseCodeTags when posting code samples.
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
first lets look at your exception stack trace.

...StringIndexOutOfBoundsException. This indicates that your String does not contain a character at the index you've asked for. For the String "abcd" which has a length of 4 characters but the maximum index you can ask for is 3 (Strings are zero indexed). Your stack trace says "String index out of range: 0". This indicates you've asked for index 0 of the String and it wasn't found so its an empty String (if it was null you would get a NullPointerException instead).

...String.charAt. This first line tells you exactly where the exception was thrown (line 686 of the String class in the chatAt method). I can't see anywhere in your code where the charAt method is called. Is your code listing complete?

...testAccount.main. This is a very useful line in your stack trace and tells you from where the String.charAt method was called. The stack trace will include the line number to help you but you haven't included the full stack trace in your post.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11476
    
  16

I added code tags to make your post slightly more readable.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble understanding an error code i keep getting. Please help!