- //##########################################
- //# Assignment 7 #
- //# #
- //# Finally done... #
- //##########################################
- import java.util.Date;
- import java.util.Calendar;
- import java.util.Scanner;
- /**
- *
- * This class will make and call books that are stored in a bookshelf.
- *
- */
- public class Bookmain
- {
- public static void main (String[] args)
- // making a new bookshelf object called shelf
- BookShelf shelf = new BookShelf();
- Scanner scan = new Scanner(System.in);
- // getting ready for the while loop by setting up some variables that will control it.
- boolean istrue = true;
- System.out.println("Lets add some books to our shelf");
- // while loop to add a book.
- while(istrue)
- {
- System.out.println("What is the books title? ");
- String title = scan.next();
- System.out.println("Who is the author of the book? ");
- String author = scan.next();
- System.out.println("What is the value of the book in dollars? ");
- Double price = scan.nextDouble();
- System.out.println("What is the Publisher? ");
- String publisher = scan.next();
- System.out.println("What is the copyright year? ");
- int year = scan.nextInt();
- Calendar greg = Calendar.getInstance();
- // set the calendar basically just for year.
- greg.set (year, 1, 1);
- Date copyright = greg.getTime();
- System.out.println("would you like to make another book? Y or N");
- String answer = scan.next();
- // if statement inside of the while loop that allows you to either make a new book or stop making books.
- // in either case it adds the book to shelf.
- if (answer.equals ("Y"))
- {
- istrue = true;
- Book abook = new Book(title, author, price, publisher, copyright);
- shelf.add(abook);
- }
- else
- {
- istrue = false;
- Book abook = new Book(title, author, price, publisher, copyright);
- shelf.add(abook);
- }
- }
- // this is the code to find the book
- System.out.println("Type the title of the book you want to find: ");
- String titlesearch = scan.next();
- Book result = shelf.find(titlesearch);
- // if statement that says if the result is NOT null then print out what was found, IE found a book with that title.
- if(result != null)
- {
- System.out.println(result);
- }
- // if it is null then the book doesnt exist.
- else
- {
- System.out.println("That book doesnt exist");
- }
- // this variable sets up the next while loop
- boolean istrue2 = true;
- // while loop for removing a book.
- while(istrue2)
- {
- System.out.println("Would you like to remove a book? Y or N");
- String removeanswer = scan.next();
- // this if statement matches what the user enters.
- if (removeanswer.equals ("Y"))
- {
- // in this case they want to remove a book, so enter the title and then it searches for the book.
- System.out.println("enter title to remove: ");
- String removesearch = scan.next();
- Book removeresult = shelf.find(removesearch);
- // this if statement says that if removeresult does NOT equal null then remove the book, meaning it exists and is a match. if(removeresult != null)
- {
- System.out.println(removeresult);
- shelf.remove(removeresult);
- }
- }// end of answer is Yes
- // if you dont want to remove a book then END the loop.
- if(removeanswer.equals("N"))
- {
- istrue2 = false;
- }
- }// end while
- }
- }
Undefined
By: Guest | Date: Apr 8 2009 21:25 | Format: None | Expires: never | Size: 3.49 KB | Hits: 1166
Latest pastes
1 days ago
2 days ago
4 days ago
6 days ago
6 days ago