aspose file tools
The moose likes Beginning Java and the fly likes help with ArrayList tables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "help with ArrayList tables" Watch "help with ArrayList tables" New topic
Author

help with ArrayList tables

tom jenkins
Greenhorn

Joined: Apr 18, 2012
Posts: 27
ArrayList series beginner question?
Hello I really need some help on my assignment. I'm nearly done but am having trouble
I'm trying to print out consecutive tables with the updated arraylists from years 0 to 10 for my invest.accumulate method which just accumulates interest and returns it based on the years elapsed...


My output now looks something like this: (The table is correct but this messes up the alignment. so no problem with the table..)

run:
Principal Interest Maturity Compound Mode Accum.Value Tot.Interest
========= ======== ======== ============= =========== ============
5000 8.25 5 quarterly 5000 0
12000 10.8 10 daily 12000 0
2000 7.3 5 quarterly 2000 0
10000 5.55 3 monthly 10000 0
2000 4.5 1 daily 2000 0
5000 9.15 10 monthly 5000 0


I can't figure out how to print more than one table with the accumulated values updated 10 times.. the accumulated value automatically updates the tot.interest.

I'm not sure how i can modify an array after I have already entered it into the list so that i can print out an updated table for all the arrays... can someone please help?? Thanks a lot

[Added code tags - see UseCodeTags for details]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Welcome to the Ranch

You have some very peculiar names for your variables. You don’t need two Scanners. You can read nextInt() etc directly from the file. If you are using nextLine() maybe you should use while(reader.hasNextLine())... as your loop test.
The reason the alignment is off is that (outside code tags) this website renders multiple spaces as a single space. You could try   instead of ordinary space.
You ought to override the toString() method in your CDlist class, rather than creating a toPrint() method. You can cheat by making toPrint private (or even not making it private) and writing this Then you simply print an instance of that class: System.out.println(minister);
You don’t any more than that in the main method; in my opinion the ideal length for a main method is 1 statement.
I am not quite sure about what you want, so I am guessing a bit, but let’s have a go: How about a matureAllInvestments(int years) method in CDlist. You can guess its intent from its name. Then you can loop, calling matureAllEtc several times and printing the CDlist object each time.
tom jenkins
Greenhorn

Joined: Apr 18, 2012
Posts: 27
Thanks! I think I resolved the problem:

I added your suggested method to the CDlist class:

public void matureAllInv(int years)
{
for (int i = 0; i < CDarrays.size(); i++)
{
CD pop = CDarrays.get(i);
pop.accumulate(years);

}
}

and this to the main:
for (int i = 0; i <= years; i++)
{

minister.matureAllInv(i);
System.out.println(minister.toString());

}

worked like a charm! big thanks!

p.s. i'd like to make the main method only 1 statement long also, but unfortunately my professor requires a different method for main..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with ArrayList tables
 
Similar Threads
New to ArrayList
Somebody please take a look at this
Printf and multi-dimensional array
Calculating a total after a "for" loop
resultset is not working properly