Results 1 to 12 of 12
- 10-21-2011, 08:01 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
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:
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?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(); } }Last edited by Fubarable; 10-21-2011 at 09:03 PM. Reason: QUOTE TAGS CHANGED TO CODE TAGS
- 10-21-2011, 09:32 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 15
- Rep Power
- 0
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
- 10-22-2011, 12:47 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
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.
- 10-22-2011, 12:48 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
Re: Storing and retrieving information?
-
Re: Storing and retrieving information?
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.
- 10-22-2011, 12:51 AM #6
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
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.
- 10-22-2011, 10:32 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
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.
- 10-22-2011, 10:35 PM #8
Member
- Join Date
- Oct 2011
- Posts
- 15
- Rep Power
- 0
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)
-
Re: Storing and retrieving information?
Yep, either an array or an ArrayList if you're allowed to use them.
- 10-22-2011, 10:53 PM #10
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Storing and retrieving information?
This is the part where I want to shoot my instructor, because we haven't talked about Arrays either.
-
- 10-22-2011, 11:19 PM #12
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Storing/retrieving arrays in a data structure...
By pbandjay in forum New To JavaReplies: 0Last Post: 11-03-2010, 12:39 AM -
storing information
By bsebal28 in forum New To JavaReplies: 3Last Post: 03-26-2009, 08:10 AM -
Help in storing Information
By care in forum New To JavaReplies: 1Last Post: 12-01-2008, 09:16 PM -
storing and retrieving a file as such
By anil_manu in forum Advanced JavaReplies: 0Last Post: 03-11-2008, 01:27 PM -
Problem with storing and retrieving from a textfile
By Albert in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 03:01 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks