GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java-Collections-Framework-Example/BookApp.java at main · dyneth02/Java-Collections-Framework-Example Expand file tree/ Copy pathBookApp.javaMore file actions 67 lines (56 loc) · 1.66 KB / Copy pathBookApp.javaFile metadata and controls67 lines (56 loc) · 1.66 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 package version_e.q2; import java.util.PriorityQueue; import java.util.Scanner; public class BookApp { public static PriorityQueue<String> books = new PriorityQueue<>(); @SuppressWarnings("resource") public static void main(String[] args) { Scanner read = new Scanner(System.in); String bookName; String needToRemove; do { System.out.print("Enter the Book Name : "); bookName = read.nextLine(); if (!bookName.equalsIgnoreCase("done")) { addBook(bookName); } } while (!"done".equalsIgnoreCase(bookName)); System.out.print("Do you want to remove a book ? : "); needToRemove = read.next(); if (needToRemove.equalsIgnoreCase("Yes")) { System.out.print("Enter the book's name that you want to remove : "); read.nextLine(); removeBook(read.nextLine()); } else if (needToRemove.equalsIgnoreCase("No")) { System.out.println("Okey"); } else { System.out.println("Wrong input"); } displayBooks(); } public static void addBook(String bookName) { books.offer(bookName); } public static void removeBook(String bookName) { if (books.contains(bookName)) { books.remove(bookName); System.out.println(); System.out.println("The book is removed successfully..!"); System.out.println(); } else { System.out.println(); System.out.println("The book is not in the this list..!"); System.out.println(); } } public static void displayBooks() { System.out.println(); System.out.println("The total number of books in the list : " + books.size()); for (String displayedBook : books) { System.out.println(displayedBook); } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |