Please Help Me!

Please, please Help

Page 1 of 1

2 Replies - 517 Views - Last Post: 09 February 2009 - 12:11 PM Rate Topic: -----

#1 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Please Help Me!

Posted 09 February 2009 - 10:31 AM

import java.io.*;
import java.util.*;
import java.net.*;

public class MenuApp
{
	public static void main(String[] argStrings)
	{
		Scanner keyboard = new Scanner(System.in);
		BufferedReader in;
				String read;

		
		
				
		int selection = 0;

		do
		{
			System.out.println("0 - exit");
			System.out.println("");
			System.out.println("1 - Import Citys & Temperatures from File");
			System.out.println("");
			System.out.println("2 - Display Citys & Temperatures on Screen");
			System.out.println("");
			System.out.println("3 - Sort City's into Alphabetical Order");
			System.out.println("");
			System.out.println("4 - Sort Temperatures into descending order");	
			System.out.println("");
			System.out.println("5 - Display Highest Temperature on Screen");
			System.out.println("");
			System.out.println("6 - Display Lowest Temperature On Screen");
			System.out.println("");
			System.out.println("7 - Enter New Data");	
			System.out.println("");
													

			System.out.print("Enter selection > ");
			selection = keyboard.nextInt();

			switch (selection)
			{
			case 0: System.out.println("Exit selected");
				break;
			case 1: try {
 
								String sCurrentLine;
 
							BufferedReader br = new BufferedReader(new FileReader("C:\\test.txt"));
 
								while ((sCurrentLine = br.readLine()) != null) {
							System.out.println(sCurrentLine);
								} 
 
							   } catch (FileNotFoundException e) {
 
								e.printStackTrace();
 
							   } catch (IOException e) {
 
							   e.printStackTrace();
								   }

								break;
			case 2: System.out.println("My telephone number is 01202999111");
				break;
			case 3: System.out.println("My telephone number is 01202999111");
				break;
			case 4: System.out.println("My telephone number is 01202999111");
				break;
			case 5: System.out.println("My telephone number is 01202999111");
				break;	
			case 6: System.out.println("My telephone number is 01202999111");
				break;
			case 7: System.out.println("My telephone number is 01202999111");
				break;																	
			
			default:
				System.out.println("Error: " + selection + " input. selection must be in the range 0 to 2");
			}
				
		} while (selection != 0);
	}
}




This is my Code, I'm trying to get it to read a text file that contains citys and temperatures.


when I press Option 1 I need it to read the file and store it, not print to screen.
The 2nd option then needs to print the file to screen.
then I need to sort the citys into alphabetical order using some sort of an array.

Please help me, as I havent got a clue how to do this!

Thanks







Mode Edit: :code:

This post has been edited by Addio569: 09 February 2009 - 12:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Please Help Me!

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4424
  • View blog
  • Posts: 12,293
  • Joined: 18-April 07

Re: Please Help Me!

Posted 09 February 2009 - 11:34 AM

Well you have the BufferedReader object created, now you just need to set it up to open a file. Then you can use that object to read lines of the file.

BufferedReader in =  new BufferedReader(new FileReader("<path to the file here>"));



Then you can use the methods of the BufferedReader class to read in text. Check out the link below to see the class' methods. Notice there is one called readLine(). This will read a line from the file and returns NULL when it hits the end of the file.

BufferedReader Class Documentation

:)
Was This Post Helpful? 0
  • +
  • -

#3 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Re: Please Help Me!

Posted 09 February 2009 - 12:11 PM

View PostMartyr2, on 9 Feb, 2009 - 10:34 AM, said:

Well you have the BufferedReader object created, now you just need to set it up to open a file. Then you can use that object to read lines of the file.

BufferedReader in =  new BufferedReader(new FileReader("<path to the file here>"));



Then you can use the methods of the BufferedReader class to read in text. Check out the link below to see the class' methods. Notice there is one called readLine(). This will read a line from the file and returns NULL when it hits the end of the file.

BufferedReader Class Documentation

:)


I figured out how to read the file but I now need to, get it not to print to screen first, then my 2nd option prints to screen then I need to sort the data in alphabetical order using an array (I think) but I have no clue how to do this! (see revised 1st post)

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1