Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Storing and retrieving information?

  1. #1
    KeldonWarlord is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Storing and retrieving information?

    Question for the ever-wise and wonderful people here on the Java forums. I'll start with a quick TL;DR of my problem, which is quite elementary.

    I need to have a way of entering, storing, and then retrieving- but NOT editing- a series of data values in a Java program. Essentially speaking, I need all of my input/output contained within my Main class, and I need a Book and BookSpec class as well.
    Taken directly from my task at hand:

    Problem Statement:
    A collection of books used by the software development staff needs to be cataloged and it has been decided to put the resulting catalog online. For the initial phase of this project, the following functional requirements will be addressed:

    • The following facts about each book will be recorded:
    o title; author; copyright date; isbn; primary topic; list price; acquisition price
    • A book that has been created must provide a means for accessing each individual fact that has been recorded
    • A book must also provide a means for providing a single String that summarizes its facts

    Note the following specific technical requirements:

    • Design an interface named BookSpec and a class named Book that would be appropriate for the preceding requirements. Take care that all of the stated requirements are addressed in your class. Use any design tool that you wish, and note that the design does NOT need to be expressed in formal Java syntax.
    o The Book class may not do any input or output (I/O) - absolutely none.
    • Design a Main class that will exercise ("test") your implementation in order to verify that all requirements as stated have been properly implemented.
    o All I/O must be performed in the Main class.
    o The Main class may contain as many methods as desired (and must contain the standard "main()" method).

    Now, I've got my coding down for entering the values- my question is, what do I need to code to enable me to store and retrieve all of the listed data values for several different books?

    For those of you who want to ask, by the by, yes this is for a course- and yes, I have attempted to collaborate with other students, but haven't had much luck making heads or tails of their advice. (Getting someone who is learning the material themselves to explain is in a simple, concise fashion is about as much fun as having teeth pulled)

    A little more information:

    Basically, here is what I have so far for meaningful code that gives me the input options to get the required data values:


    Java Code:
    package main;
    
    import java.util.Scanner;
    
    public class Main {
    
        public static void main(String[] args) {
            String bookTitle = "";
            Scanner input = new Scanner(System.in);
            System.out.print("Please enter the title of the book: ");
            bookTitle = input.nextLine();
            System.out.println();
            System.out.println("The title of the book has been entered as: " + bookTitle + ".");
            System.out.println();
    
            String author = "";
            System.out.print("Please enter the author's name, in format [Last, First]: ");
            author = input.nextLine();
            System.out.println();
            System.out.println("The author's name has been entered as: " + author + ".");
            System.out.println();
    
            String copyright = "";
            System.out.print("Please enter the book's copyright date: ");
            copyright = input.nextLine();
            System.out.println();
            System.out.println("The copyright date has been entered as: " + copyright + ".");
            System.out.println();
    
            String isbn = "";
            System.out.print("Please enter the book's ISBN: ");
            isbn = input.nextLine();
            System.out.println();
            System.out.println("The ISBN has been entered as: " + isbn + ".");
            System.out.println();
    
            String topic = "";
            System.out.print("Please enter the book's primary topic: ");
            topic = input.nextLine();
            System.out.println();
            System.out.print("The topic has been entered as: " + topic + ".");
            System.out.println();
            System.out.println();
    
            String listprice = "";
            System.out.print("Please enter the list price of the book: ");
            listprice = input.nextLine();
            System.out.println();
            System.out.print("The list price of the book has been entered as: " + listprice + ".");
            System.out.println();
    
            String acquisitionprice = "";
            System.out.print("Please enter the acquisition price of the book: ");
            acquisitionprice = input.nextLine();
            System.out.println();
            System.out.print("The acquisition price of the book has been entered as: " + acquisitionprice + ".");
            System.out.println();
        }
    }
    My question is, how can I take all of those data values (Strings bookTitle, author, copyright, isbn, topic, listprice and acquisitionprice) and store them all elsewhere for retrieval?
    Last edited by Fubarable; 10-21-2011 at 10:03 PM. Reason: QUOTE TAGS CHANGED TO CODE TAGS

  2. #2
    dheaven is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Storing and retrieving information?

    The easiest way to store/retrieve data is to use .txt files. Java has built-in methods that allow you to write/read data from a text file.
    Alternatives are using binary files or databases, but this may you may find working with them a little complicated. Since I don't think that you require the encrypt your data, I think that text files are your best choice.

    Here are some tutorials on how to use text files in Java:
    Dystopian Code: Text File I/O in Java
    Dystopian Code: Text File I/O with Strings that Contain Spaces in Java

  3. #3
    gladwda is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: Storing and retrieving information?

    I'd store em to excel frankly. Couple of tutorials on this kicking around the net, I was reading one the other day, I'll see if I can dig one up.

  4. #4
    gladwda is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: Storing and retrieving information?


  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Storing and retrieving information?

    Quote Originally Posted by gladwda View Post
    I'd store em to excel frankly. Couple of tutorials on this kicking around the net, I was reading one the other day, I'll see if I can dig one up.
    I wouldn't bother. This is for a course, involves storing information for only a few books, and so all he has to do is store in a text file, perhaps a very simple comma-delimited file. My main suggestion to the OP is that he read the Oracle Tutorials section on text I&O.

  6. #6
    gladwda is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: Storing and retrieving information?

    Ah, I didn't see the post above mine. I thought this had 0 responses so I'd give it a crack helping out. But .txt makes much more sense.

  7. #7
    KeldonWarlord is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: Storing and retrieving information?

    Thanks to all of the above for the help- saved the links for later use.
    Something I should have mentioned- this is an Introduction to Java course- we haven't even begun covering use of .txt archived-materials.
    Anyone have any good suggestions for what code I'd need to use to prompt and return specific variables?

    Basically I need a way, internal to the Java coding itself without an external .txt archive, to store all of that material for several different books, and then retrieve it later.

  8. #8
    dheaven is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Storing and retrieving information?

    The simplest way to store it without using external files it's by using arrays.
    See the tutorial bellow for more insight:
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Storing and retrieving information?

    Yep, either an array or an ArrayList if you're allowed to use them.

  10. #10
    KeldonWarlord is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: Storing and retrieving information?

    This is the part where I want to shoot my instructor, because we haven't talked about Arrays either.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Storing and retrieving information?

    Quote Originally Posted by KeldonWarlord View Post
    This is the part where I want to shoot my instructor, because we haven't talked about Arrays either.
    But this shouldn't stop you from reading about them and using them. I would venture to say that most of us here are self-taught Java programmers, and you can be one too!
    GA5MA5KOP likes this.

  12. #12
    gladwda is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: Storing and retrieving information?

    Alternatively define them as strings. This would be a massive pain in the arse though. Arrays are the way forward

Similar Threads

  1. Storing/retrieving arrays in a data structure...
    By pbandjay in forum New To Java
    Replies: 0
    Last Post: 11-03-2010, 01:39 AM
  2. storing information
    By bsebal28 in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 09:10 AM
  3. Help in storing Information
    By care in forum New To Java
    Replies: 1
    Last Post: 12-01-2008, 10:16 PM
  4. storing and retrieving a file as such
    By anil_manu in forum Advanced Java
    Replies: 0
    Last Post: 03-11-2008, 02:27 PM
  5. Problem with storing and retrieving from a textfile
    By Albert in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:01 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
  •