13 Replies Latest reply: May 4, 2013 1:20 PM by rukbat RSS

    Import from file using Object Oriented Programing

    996672
      Hello,

      Would anyone be able to explain how to import data from a file using Object Oriented Programing? I know how to write OOP Java and I know how to read data from a file in Procedural Java but would like to know more about how to do it OOP. Is it the same as reading data process as in Procedural programming?

      Thank You
        • 1. Re: Import from file using Object Oriented Programing
          EJP
          What's in the file?
          • 2. Re: Import from file using Object Oriented Programing
            1002857
            Explain us which type of file you want to open or access from java.
            • 3. Re: Import from file using Object Oriented Programing
              996672
              The file has bank account information in it; for example name of the account holder, account number, account type, account number, etc.

              If you would like to see the file, it is located here: https://www.dropbox.com/s/b1qr9m5br9vvy4l/AcctInfo.txt

              Thank You!
              • 4. Re: Import from file using Object Oriented Programing
                TPD-Opitz
                Techergy wrote:
                The file has bank account information in it; for example name of the account holder, account number, account type, account number, etc.
                If you would like to see the file, it is located here: https://www.dropbox.com/s/b1qr9m5br9vvy4l/AcctInfo.txt
                This looks like an homework assignment. Real world files usually have all record data in one row separates by a special char (CSV). The way the data is organized makes it a little harter to process this file in an OO way.

                The OO way to parse such a file is to create a (static) factory class that takes The input for a single record and creates an object with the information if it.
                In your case you should create a <tt>BufferedReader</tt> from your input file and pass it to the factory method.
                The factory mmethod should take the next 5 lines from the input and create a new object instance that the factory method returns.
                then you should repeat this als long as ther are at leaset two more lines in the file.

                bye
                TPD
                • 5. Re: Import from file using Object Oriented Programing
                  996672
                  TPD you're right, this is an assignment that I am trying to gain more knowledge about. So, thank you very much for telling me about BufferedReader. My professor has a very specific way that she wants us to complete the code.

                  I have gotten the file that I call the main method in set up with the BufferedReader, and I also have one of the class files set up with all the getters and setters that I think I need. How would I go about linking the constructors that my professor wants us to use in the code and the BufferedReader in the main method? Could I set up the constructors as normal and then just call the constructors in the main method and it will gather information from the file while inputing certain items into the proper place?

                  Thank You,

                  Techergy
                  • 6. Re: Import from file using Object Oriented Programing
                    996672
                    Hello there everyone,

                    I have been waiting for a reply from someone for quite a while now. I have done some work for this and have come a good ways to finishing it.

                    Though, I still need some help in figuring out what to do next and working out the bugs.

                    I would be very appreciative if someone could look at what I have done, and give me some insight as to what I am doing wrong and where I need to go next.

                    All files and information about what I am working on, if you like more information, are located here: https://www.dropbox.com/sh/e17kntpswylnulr/G5V9MRMfMw

                    Once again, I would appreciate any help that can be given. I getting very frustrated about not knowing what I should do, and having everything I try not work.

                    Thank you,

                    Techergy
                    • 7. Re: Import from file using Object Oriented Programing
                      TPD-Opitz
                      Techergy wrote:
                      I would be very appreciative if someone could look at what I have done,
                      and give me some insight as to what I am doing wrong and where I need to go next.
                      Please tell us in which way your code does not do what you expect. Do you get any error messages from the compiler ort the runtime?

                      bye
                      TPD
                      • 8. Re: Import from file using Object Oriented Programing
                        996672
                        I guess I did not make that clear. I am not getting any sort of error messages, but I am not able to get the information to print out to the console.
                        • 9. Re: Import from file using Object Oriented Programing
                          EJP
                          I have been waiting for a reply from someone for quite a while now.
                          Moderator: Your expectations are misplaced. If you had posted the relevant code here you might have some chance. Very few people will chase a link to an external site and in any case it's beyond the purpose of these forums. To have permanent value here and not risk closure or deletion, questions should be self-contained and of at least some general interest. It's not a help desk.
                          • 10. Re: Import from file using Object Oriented Programing
                            996672
                            Yes, of course. I am very sorry.
                            • 11. Re: Import from file using Object Oriented Programing
                              gimbal2
                              Techergy wrote:
                              Yes, of course. I am very sorry.
                              ... but you're not doing anything about it. Post the code man. Use \
                               tags to make it readable.                                                                                                                                                                                                                                                                                                                                                                
                              • 12. Re: Import from file using Object Oriented Programing
                                996672
                                Yes, sorry about that as well. I have found the assistance I required through a program my college has. How do I close this thread, or does a mod need to do that?
                                • 13. Re: Import from file using Object Oriented Programing
                                  rukbat
                                  Techergy wrote:
                                  How do I close this thread, or does a mod need to do that?
                                  You post a finalizing reply that completely describes how to solve the issue you originally posted about, then you mark the thread as "Answered".