• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Array vs files?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you elaborate?...

what are the advantages of using an array rather than a file?
 
Knute Snortum
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the complications of accessing data in a file? What is easy about accessing data in an array?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic