It's not a secret anymore!
The moose likes Beginning Java and the fly likes istream... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "istream..." Watch "istream..." New topic


Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok here is my code to extract what i need from a file...

ok, now in my assignment i have to do this, but input into a doubly linked

list as i go....

now that isn't too hard, but we have to use a method called input().

here is the constructor for the method input.

now, I think istream& is refering to a pointer in c++.

but in java, would i pass the file instead??


You down with OOP? Yeah you know me!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

That's not the "constructor" for the method: it's the "declaration" for the method. Methods don't have constructors!

The answer to your question is that your Scanner object is the Java equivalent of the C++ istream. An istream is an object that's all set up and opened to read data from, just as a Scanner is. The "&" means you're passing a reference; by default, without that "&", in C++ a copy of the istream object itself would be passed (unlike in Java, where it's always a copy of a reference that is passed.)

[Jess in Action][AskingGoodQuestions]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
i thought java didn't support "call-by-reference" parameters...??

anyways... i figured out a way to do what i needed...

but now im stuck..

we have to insert the nodes in order by employee number..

well i was just going to insert, then selectionSort the numbers


but I started to try and switch the values, and i came across 10,

sometimes more to changes to switch the nodes around.

so what im asking is, is there an easier way to get the nodes in order,

without having to find the right spot each time you input a node.



p.s here is my code...

this is the DDLL class...

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, i figured out how to arrange the nodes by employee number...

but i dont know how to arrange nodes' .EmpHrs afterwards...

or during...

yeah, i have no clue..

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
by the way,

ths is my new, revised code...

the main is the same, but the DDLL class is different..

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
IMO, you are doing too much in one class. A *more* object oriented design would be to have a number of classes with focused responsibilities. i.e.

  • DoublyLinkedList - responsible for the logic of maintaining a LinkedList of Objects.
  • TextFileReader - responsible for reading lines from a text file
  • Employee - responsible for maintaining information about each Employee (id/ wage/ etc.).
  • EmployeeIDComparator implements Comparator - responsible for implementing the logic about Employee ordering
  • ListSorter - responsible for sorting your DoublyLinkedList on the basis of whatever Comparator you provide it.
  • Your mileage may vary, but by organizing classes in terms of a focused responsibility, your code is more reusable and flexible.
    [ July 05, 2006: Message edited by: Garrett Rowe ]

    Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
    I agree. Here's the link:
    subject: istream...
    It's not a secret anymore!