Sreelatha Sankaranarayanan

+ Follow
since Dec 10, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sreelatha Sankaranarayanan

Annotations and marker interfaces are pretty much used for the same purpose, however annotations can be used on class,method or variable whereas marker interfaces can be used only on classes , maybe the only disadvantage of marker interfaces over annotations.
10 years ago

Here you have assigned items = null and in the next line you are doing items.getFieldName() , which will result in NullPointerException, you will need to initialize items before doing any operations on it.
The way recursion works is that, when a method calls itself recursively, the method invocation is kept on a stack each time the method is invoked (the parent method does not return as completed), once the recursive calls exit, then the method invocation completes itself from the stack , prior to the method completion or return the sysout gets printed, which is why you see the sysout printed the number of times the method was invoked.
10 years ago
File I/O also can be expensive considering you have 1000s of records to persist. Have you considered using an XML repository or something on those lines so that fetching data can be more streamlined . You would need to decide on the data structure first and that would enable you to choose a solution.
10 years ago
Hi Kuyni,

As Mohammad said it, in your prg you had the sys out in a method that was recursively called, and it will be called for total months+1 times which is 4 in your case, this was the reason why you had it printed 4 times when you expected it to be printed only once.
10 years ago

I have modified your code to achieve what you want , please take a look and see if this what you want.

This is the output you get after running the modified program, which i think is what you want to achieve (I have formatted the output a little for clarity)

Month 1 : Amount Deposited = 2000.0
Interest = 19.2
Total = 2019.2
Month 2 : Amount Deposited = 2000.0
Interest = 38.58432
Total = 4057.78432
Month 3 : Amount Deposited = 2000.0
Interest = 58.15472947200001
Total = 6115.939049472
After 3 months you will get 115.93904947200008 for 6000.0
10 years ago
This is what will help what you want , note the first 2 lines after the while loop starts -----------

10 years ago
You need to go in a staged manner. First pick up a good book, there are quite a few good books out there, below is one of the most recommended one

Thinking in Java (4th Edition)
by: Bruce Eckel

Besides there are several online tutorials that are available directly from Sun. Lay your hands on any of these and start your journey.
make sure you practise everything you read, that will be a good way to go.
Also consider studying for SCJP certification which is an exam from Sun, this will prepare you well enough with basics and more on Java
Good luck.
10 years ago