wood burning stoves*
The moose likes Beginning Java and the fly likes Don't know where ot start!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Don Watch "Don New topic
Author

Don't know where ot start!!

Sarah Bushnell
Greenhorn

Joined: Oct 29, 2005
Posts: 5
After the great help I got on this forum from my last question, I am in DESPERATE need of your help again!!

I have been given a program to write, (bear in mind I've only been studying Java a month and haven't even been taught half of the stuff the program has to do yet!!!).It has to allow the user to input test marks, arrange them neatly in columns, store and save the data then reorganise delete and modify as needed.

So far I have managed to input the marks and format them using hte printf method. I thought i'd done ever so well, until someone mentioned that it had to use arrays and now I'm lost in the maze again. I'm the furthest ahead in my group but I feel so disorientated now. For the life of, I cannot find a way of inputting information, then arranging it so it can be stored, whilst also creating a loop so that inputted marks will be automatically arranged into a table!!! Pleeeeeeeeeeease help if you can!!!

Justin bob
Greenhorn

Joined: Nov 07, 2005
Posts: 3
you can set up an integer array by using
int [] A = new int [9];

[] = array symbol
[9] = says your going to create an array of ten references to intergers.
(since your counting from 0-9 not 1-9..
and to store the scores, you can use this.
A[0] = 100;
A[1] = 90;
and so on....
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If you use arrays, then the java.util.Arrays class provides some useful sorting capabilities...

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html

But for the flexibility you're describing, I'm not sure that an array is your best option. (For one thing, the size of the array is set upon instantiation, so this isn't very friendly for insertions/deletions.) So you might want to look at the Java Tutorial on collections...

http://java.sun.com/docs/books/tutorial/collections/index.html

As for saving, have you worked with the java.io package at all?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
I agree with Marc. Unless you have been specifically told to use an array then read the collections tutorial he linked above and then consider using something such as an ArrayList (java.util.ArrayList).

This has two methods add() and remove() which should be quite useful to you.

Now, you can add() and remove() Strings to an ArrayList, but, depending on how much you have learn't about OO yet, you may wish to consider writing a new class to represent a test result entry - that way you can encapsulate each test mark in an object which you would then add to the ArrayList one-by-one. Each test-result object might hold values for the test mark, candidate name, date taken etc depending on the project requirements.

When you need to get the results back out to display them you can use a method called iterator() on the ArrayList object to loop over each test-result entry.


SCJP 1.4, www.gsi3d.org.uk
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Originally posted by Justin bob:
you can set up an integer array by using
int [] A = new int [9];

[] = array symbol
[9] = says your going to create an array of ten references to intergers.
(since your counting from 0-9 not 1-9..


[9] = says you're going to create an array of nine integers indexed from 0 to 8.
[ November 09, 2005: Message edited by: Joanne Neal ]

Joanne
Sarah Bushnell
Greenhorn

Joined: Oct 29, 2005
Posts: 5
Thank you all for your time! Been il lwith food poisoning but tried it today and it worked like a charm! You've all been so helpful, now I've got to get my head around String tokenizers and reading from the outputted file!!

Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Don't know where ot start!!