Results 1 to 10 of 10
  1. #1
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default Confused on how populate a object with data from a file

    This is the question prompt followed by the code I wrote so far. I am confused on what to do next and how to populate the object from the file.

    Confused on how populate a object with data from a file-image1.jpg

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    7

    Default Re: Confused on how populate a object with data from a file

    The wardrobe instance is an ArrayList full of jeans(objects).
    Then there is a String that points to the file location and its name. I don't think you have to pass this string into the method here.
    Then open the file and read the objects while there are any. The file should have jeans objects in it. At the end return the wardrobe<jeans> object (and declare that return type in your method) and close the file again.
    Why do you use the scanner class?

  3. #3
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default Re: Confused on how populate a object with data from a file

    I called the scanner class so I could read the input file. Im new to using objects they confuse me and my instructor hasn't gone over it yet.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Confused on how populate a object with data from a file

    I'm going to assume (from that first para) that you have been provided with the Wardrobe and Jeans classes?

    So write the method, using the notes I see on that page.

    Don't try and do it all. Just get the method signature correct...then add the Wardrobe object (it's even written there in those notes).
    Does that all compile?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default Re: Confused on how populate a object with data from a file

    We haven't been provied with it you are supposed to assume that it is there. Our job is only to create the method. I have never wrote a method to return a object and the underline is usually where you put your return type.
    I wrote public _____ because I do not know what to put here. I put the string filename in the parameter like instructed. Then I instantiated the object and used to the scanner class to prepare to read the file ( only way I know how to read a file ) I do not know how to populate the object once instantiated.

  6. #6
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    7

    Default Re: Confused on how populate a object with data from a file

    Let us start here: " the wardrobe instance is an arraylist full of jeans objects"

  7. #7
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default Re: Confused on how populate a object with data from a file

    Quote Originally Posted by benji2505 View Post
    Let us start here: " the wardrobe instance is an arraylist full of jeans objects"
    So what we're populating is an Arrylist which is supposed to be filled with the data from the file?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Confused on how populate a object with data from a file

    Quote Originally Posted by benji2505 View Post
    Let us start here: " the wardrobe instance is an arraylist full of jeans objects"
    It's a class that has an array list of Jeans.
    Bit of a difference.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Confused on how populate a object with data from a file

    For the return value:
    Java Code:
    public MyClass doSomething() {
    
    }
    The above signature says that when the method doSomething is called that it will return an instance of the class MyClass.

    The requirement in your assignment that says "should return the populated Wardrobe object" tells you what class that method should return.
    You've already declared that object in the first line of the method, so you can return that...but you need to add the class to the method signature.

    Since you don't have Wardrobe or Jeans classes how are you supposed to compile this to check?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    7

    Default Re: Confused on how populate a object with data from a file

    Quote Originally Posted by Tolls View Post
    It's a class that has an array list of Jeans.
    Bit of a difference.
    agreed. my bad. sorry for any confusion I might have caused.

Similar Threads

  1. populate jCombobox with database data
    By joeyxaza in forum JDBC
    Replies: 2
    Last Post: 01-06-2014, 11:09 AM
  2. Replies: 2
    Last Post: 03-25-2011, 03:36 PM
  3. To populate the data processed into a .csv or excel file
    By jaiminparikh in forum Advanced Java
    Replies: 2
    Last Post: 02-27-2009, 12:56 AM
  4. populate jCombobox with database data
    By joeyxaza in forum JDBC
    Replies: 0
    Last Post: 01-19-2009, 05:30 PM
  5. how to populate data in drop-down box
    By ma-la in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-01-2008, 12:24 PM

Posting Permissions

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