Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Shouldn't "list" be a parameter of the method Create()?

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default Shouldn't "list" be a parameter of the method Create()?

    PHP Code:
        static LinkedList<PeopleCreate(String nameFile)
            
    throws IOException
        
    LinkedList<People> list = new LinkedList<People>();
          
    boolean Fileexists true ;

           
    FileReader fi null


           try {
                 
    fi = new FileReader (nomFichier) ;
           }

           catch ( 
    java.io.FileNotFoundException erreur) {
                
    System.out.println("Probleme d'ouvrir le fichier " +
                     
    nameFile);
                
    Fileexists false ;
           }

           if (
    Fileexists) {


              
    BufferedReader enter = new BufferedReader(fi);
              
    boolean endFile false ;


              while ( !
    endFile ) {


               
    String aLine enter.readLine();


               if (
    aLine == null)
                    
    endFile true ;
               else {
              
                    
    String name aLine.substring(010);
                    
    char   sex   aLine.charAt(30);
                    
    double height Double.parseDouble(aLine.substring(3741));
                     
    double weight  Double.parseDouble(aLine.substring(5156).trim());
                     
    int    number Integer.parseInt(aLine.substring(64));

                    
    liste.add(new People(namesexheightweightnumber));
               }
              }
             
    enter.close();
            }

          return list;
        } 


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    Please explain your question.

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    Since we return list, shouldn't list be a parameter of the method create()?

    I thought we'd have to write: "create(String nameFile, List[] list)" or something similar.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    It all depends on what the create method is supposed to do. With a name like: create, I'd assume that it would create the list and return it It would not be a parameter to the method. A method named: update() might take a list as a parameter.

  5. #5
    Member
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    Wait, I think I remember now... You don't need to declare it if it's an array that's returned, only if it's an integer double or a string and so on. Right?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    It all depends on what the method is supposed to do.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Shouldn't "list" be a parameter of the method Create()?

    Quote Originally Posted by wholegrain View Post
    Wait, I think I remember now... You don't need to declare it if it's an array that's returned, only if it's an integer double or a string and so on. Right?
    Why do you mean, "don't need to declare".
    Clarify please.

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  3. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  4. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM