Write a class which deals with Books: every Book has a title and an author. (You'll need a constructor and two getters, a toString method, but no setter methods.)
First, your program should read the title and author of books from a file1, storing the result in a List<Book> (or, in a Book2).
To create the data file, you can save this link to disk, or create the file yourself using any text editor (BlueJ or any other -- if using something like Microsoft Word be sure to File > Save as…, using the format “Text Only”! Be sure not to include any blank lines, or spaces at the start/end of each line). Here is a sample:
The Ground Beneath Her Feet
Song of Solomon
The Illustrated Man
Then, prompt the user to type in an author's (full) name;
Your program should create a list (or array3) containing all the Books whose author has the given name, and finally display that list on the screen.
(For style points, print something like “no books by author”, if we don't have any books by that author.)
GUI I/O and Stand-alone applications
We can convert this program to one that we can double-click. However, first we'll need to make several changes. Create a second project, separate from the previous problem, and copy everything over.
Unfortuately, when starting a java program by double-clicking it, the program doesn't have a console window, so we can't use System.out nor System.in! Instead, we'll use GUI dialog boxes. We'll need to replace every System.out.println and every reading-from-the-keyboard with the following two methods instead: /* Show a message. (Always use null for the first argument.) */
void javax.swing.JOptionPane.showMessageDialog( null, String msg )
/* Read a line of input, after displaying a prompt: */
String javax.swing.JOptionPane.showInputDialog( String prompt )
Go ahead and try calling these from the Code Pad, first: javax.swing.JOptionPane.showMessageDialog( null, "Hello there everybody!");
answer = javax.swing.JOptionPane.showInputDialog( "What is your quest?");
answer // look at the result, in Code Pad.
Be sure that main starts your whole program running — that's what will be called when your program is double-clicked.
From BlueJ (with the main Project window active), choose Project > Save Jar file…. You'll be prompted for which class's main to call upon double-clicking. BlueJ will then create a file (whose name ends in “.jar”); when you double-click that file, your program will run, ta-dum!
I dont even know where to start...................... how do you read text from a file and store it in an array list???