• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Reading file Input and Output

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You guys have been great at helping figure things out so I'm appreciating your responses!!

My next problem is this, I am suppose to have a program that opens a file and read it as and prints it out. I've done that and that is great. But I then need to open a new file and have that print out as well. I've been going in circles with that. I've already created the new file. here's the code that I have now.



Here's what I thought I could do:



So what the second part of the program is suppose to do is read another file that contains the same names that were in the first file, but in alphabetical order. I'm suppose to show both. I already created that file, like I said, in alpha order, so it's all ready to go. sigh. Any takers?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?
 
Mel Ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Tangen wrote:I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?



Ok.. here's what the problem states. FYI, this problem is not taken from any textbook. This is a problem from the teacher himself.

Write a program that reads a file of names where each name is a string consisting of a person’s first name, followed by a blank, then followed by the person’s last name. (Assume that the file contains at most twenty names.) Create a new file with the same names, but where each name is in the form: last name, followed by a comma, followed by a space, then followed by the person’s first name. Assume that the original file is in no particular order, and write the new file in alphabetical order based on last name.


 
Marshal
Posts: 76884
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is a case for some slightly more old-fashioned technology. Write a file of names, on paper, like this

Mel Ram
Andrew Tangen
Campbell Ritchie

Write down some way of putting them into some sort of collection. Write down a way of sorting them, then write how you think you can put them into a new file. And remember you want this in Object-Oriented format. So you need a class to record the names in.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic