Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2012
    Location
    Dublin
    Posts
    21
    Rep Power
    0

    Default Sorting and printing multiple lines of data

    Hi,

    I have an assessment for college. I have to input name, surname and phnumber and print it out surname, name phnumber

    Here's what i have all ready

    class Name {
    ........private String forename, surname;
    ........private int phNum;
    ........void getName() {
    ...............forename = Console.readToken(); // Console is a class file generated by lecturer, exactly like scanner
    ...............surname = Console.readToken();
    ................phNum = Console.readInt();
    ........}

    ........void putName() {
    ...............System.out.print(surname + "," + forename + " " + phNum);
    ........}

    .......boolean lte(Name s) {
    .................return(surname.compareTo(s.surnam e))<0 || (surname.equals(s.surname));
    ....}
    }
    public class PhoonBook2 {
    ..............public static void main(String[]args){

    .....................Name least = new Name();
    ......................least.getName();
    ......................while(!Console.endOfFile()) {
    .................................Name temp = new Name();
    ..................................temp.getName();

    .............................. if(temp.lte(least)) {
    ..........................................least = temp;
    ...............................}
    .......................}
    .................least.putName();
    ............}
    }

    This will only print out the first one in the alphabet. I know I need to store the data and print it. So my question is how would I print lets say I enter 10 lines of text, print the 10??

    Any info would be GREATLY appreciated

    Cheers
    Last edited by ManInTheMiddle; 03-26-2012 at 09:35 PM. Reason: easier to read

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Sorting and printing multiple lines of data

    A moderator added code tags to your first post. That won't be done for you every time; learn how to post code correctly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Printing to the screen specific lines from a file
    By stevenhaynes5 in forum New To Java
    Replies: 9
    Last Post: 08-15-2011, 05:28 PM
  2. reading lines from URL and printing backwards
    By luxurymode in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2011, 08:18 AM
  3. Multiple lines in arrayList
    By Lund01 in forum Advanced Java
    Replies: 6
    Last Post: 10-15-2010, 12:34 PM
  4. Sorting and Printing file
    By spry.chipper in forum New To Java
    Replies: 3
    Last Post: 12-13-2009, 08:15 PM
  5. Replies: 3
    Last Post: 12-17-2007, 02:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •