9 Replies - 911 Views - Last Post: 19 January 2014 - 07:38 PM Rate Topic: -----

#1 Ren3gade   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 14

FileIO with Parallel Arrays?

Posted 19 January 2014 - 05:42 PM

So I am working on a program where I need to be able to manage a list of items such as Computers, using parallel arrays.

The user will need to have choices to add items to the list, remove items from the list, edit items in the list.
I was thinking managing a list of computers. So for each computer they would need to input: Computers Brand, Computers CPU Speed, and Computers Price.

Where should I start? I'm guessing the file input/output so I can test it as I go.. but I am new with fileIO :/ So if someone could help me, that would be great. If possible, I want to put my fileIO in its own method to keep it all organized.

Is This A Good Question/Topic? 0
  • +

Replies To: FileIO with Parallel Arrays?

#2 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 05:52 PM

Do you really want to use parallel arrays? I recommend you read this tutorial:

Moving Away From Parallel Arrays

Java is an object-oriented programming language and the earlier you move away from parallel arrays the better.

Also, a quick search and you will find many links and tutorials about reading a file's content:

Reading and Writing Text Files

There is also a tutorials link at the top of this page.

This post has been edited by andrewsw: 19 January 2014 - 05:53 PM

Was This Post Helpful? 1
  • +
  • -

#3 Ren3gade   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 14

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 05:56 PM

I really don't want to use Parallel Arrays, but it is required by my Professor. (I keep being told that it's insane we have to use parallel arrays) Plus, I've never used parallel arrays at all.. barely regular arrays because last semester my programming professor didn't stay on track, so we crammed arrays and other things into like 2 days lol. >.>

I will take a look at them links :)

This post has been edited by andrewsw: 19 January 2014 - 06:02 PM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 06:06 PM

Well, with or without the parallel approach, reading the content of a file is important, so it's probably a good place to start.

Note: There is no need to quote the previous post, there is a large Reply button further down the page.
Was This Post Helpful? 1
  • +
  • -

#5 Flukeshot   User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 06:09 PM

It's not the first time - or even the 20th time - that I've seen someone say "The professor is forcing us to use parallel arrays" as part of an Object Oriented assignment, doesn't make sense.. Why do they do this?
Was This Post Helpful? 0
  • +
  • -

#6 Ren3gade   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 14

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 06:18 PM

View PostFlukeshot, on 19 January 2014 - 06:09 PM, said:

It's not the first time - or even the 20th time - that I've seen someone say "The professor is forcing us to use parallel arrays" as part of an Object Oriented assignment, doesn't make sense.. Why do they do this?


Is it possible because my professors are.. "older"?
My professor learned coding like 30 years ago probably lol. When there wasn't even java.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 06:41 PM

Possibly, but then he has also had 30 years to get up-to-speed with OOP.

Optimistically, maybe he is using parallel arrays as a means to then convince students of the benefits of a class-based approach ;)
Was This Post Helpful? 0
  • +
  • -

#8 Ren3gade   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-January 14

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 07:03 PM

So what I am lost on, is how to write to a file using a Parallel array.
Then to read from that and be able to edit parts of it, or remove parts of it, etc.
Was This Post Helpful? 0
  • +
  • -

#9 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 07:08 PM

You need a RandomAccessFile to be able to read/edit it
Has nothing to do with parallel array
... actually it is possible to edit a file built based on parallel array ... won't be possible if the file was built out of Java objects.... or will be a lot lot complicated

If it was built using basic datatype, at least you know the size of them and can actually edit the file
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: FileIO with Parallel Arrays?

Posted 19 January 2014 - 07:38 PM

View PostRen3gade, on 20 January 2014 - 02:03 AM, said:

So what I am lost on, is how to write to a file using a Parallel array.
Then to read from that and be able to edit parts of it, or remove parts of it, etc.

It is up to you how you want to structure the data when writing to a file. You could separate each detail for a particular computer with commas, then have other computer's information could be on separate lines. Or you could make it more structured:

Quote

Computers Brand: HP
Computers CPU Speed: quick
Computers Price: úlots
// repeats

You still need to start, though, by reading and writing ANYTHING to a file. Then you can decide on how you want to structure your data.

As pbl says, it is possible but complicated to edit a file. You are only just starting with File IO, so you should read all the information from the file, make any changes to this information, and then write it back to the file, over-writing the original version.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1