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..)
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.
Joined: Apr 18, 2012
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);
and this to the main:
for (int i = 0; i <= years; i++)