• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array vs files?  RSS feed

 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a computing maths assignment and I'm stuck on one part of the question:

Show that a two-dimensional array may be used to represent the contents of a table or a
matrix; and hence use a two-dimensional array to read in and hold the contents of a table.
Use self-documenting variable names.
Why is it appropriate in this case to use an array rather than a file (or files)?

Consider the table of test results:
Shorthand Typing Word Processing Audio Typing
Jenny 90 88 94 82
Ann 67 78 89 79
Mary 85 91 96 88



I need help on this part:

Why is it appropriate in this case to use an array rather than a file (or files)?

if anyone can answer this question it would help alot
 
Knute Snortum
Sheriff
Posts: 4284
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it has to do with access. Think about how you would access the data in a file and how that is different from a 2D array.
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you elaborate?...

what are the advantages of using an array rather than a file?
 
Knute Snortum
Sheriff
Posts: 4284
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the complications of accessing data in a file? What is easy about accessing data in an array?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris McBurn wrote:I need help on this part:
Why is it appropriate in this case to use an array rather than a file (or files)?

I don't want to muddy the waters too much, but I'm slightly puzzled by the question.

The fact is that we DO use files to store tables - and indeed matrices. After all, what is an Excel spreadsheet, if not a 2-D matrix (or set of matrices) in a file?

I think that Knute's on the right track though, because I suspect that "in this case" probably means "inside a Java program"; and the simple fact is that it's much easier to access elements in an array than it is to retrieve them from a file every time.

Which isn't to say it can't be done; but file I/O isn't one of Java's strong suits.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!