1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alexgriva [62]
3 years ago
12

2. Using the Book class developed in HW 4, write an application, BookLibrary, that creates a library (array) of up to 10 books a

nd gives the user three options: to add a book, to delete a book from the library or to change a book’s information (i.e. number of pages and/or title) in the library. a. If the user selects the add option, issue an error message if the library is full. Otherwise, prompt the user for a book title. If the book with that title exists, issue an error message (no duplicated books titles are allowed). Otherwise, prompt the user for the number of pages and add the book. b. If the user selects the delete option, issue an error message if the library is empty. Otherwise, prompt the user for a book title. If the book with that title does not exist, issue an error message. Otherwise, "delete" (do not access the book for any future processing). c. If the user selects the change option, issue an error message if the library is empty. Otherwise, prompt the user for a book title. If the requested book title does not exist, issue an error message. Otherwise, prompt the user for a new title and/or number of pages and change the book information.
Computers and Technology
1 answer:
qwelly [4]3 years ago
6 0

BookLibrary, that creates a library (array) of up to 10 books. If the user selects the add option, issue an error message if the library is full.If the book with that title exists, issue an error message

Explanation:

import java.util.Scanner;

import java.util.Arrays;

public class Derro_BooksLibrary {

public static void main(String[] args) {

 Derro_Books[] Library = new Derro_Books[10];

 Scanner scan = new Scanner(System.in);

 Derro_Books book1 = new Derro_Books("", 20);

 Derro_Books book2 = new Derro_Books("hi", 10);

 Library[0] = book1;

 Library[1] = book2;

 System.out.println("Enter 1 for add, 2 for delete, 3 for change, 4 to stop application: ");

 int answer = scan.nextInt();

 int counter = 0;

 int z = 0;

 while (true) {

  if (answer == 1) {

   for (Derro_Books book : Library) {

    counter = counter + 1;

   }

   if (counter == 10) {

    System.out.println("Library full");

   }

   System.out.println("Enter Title: ");

   String title = scan.nextLine();

   for (int i = 0; i < Library.length; i++) {

    if (title == Library[i].getTitle()) {

     System.out.println("No Duplicated Books Titles Are Allowed");

     break;

    }

    else {

     z++;

    }

   }

   if (z < Library.length) {

   System.out.println("Enter number of pages: ");

   int pages = scan.nextInt();

   Library[z + 1] = new Derro_Books(title, pages);

  }

  if (answer == 2){

   if (Library.length == 0) {

    System.out.println("Library is empty");

   }

   System.out.println("Enter title of book: ");

   String title2 = scan.nextLine();

   for (int d = 0; d < Library.length; d++) {

    if (title2 == Library[d].getTitle())

     // Delete book

     System.out.println("Deleted book: " + title2);

    else

     System.out.println("Book does not exist");

   }

  }

  if (answer == 3) {

   if (Library.length == 0) {

    System.out.println("Library is empty.");

   } else {

    System.out.println("Enter book title: ");

    String title3 = scan.nextLine();

    for (int y = 0; y < Library.length; y++) {

     if (title3 != Library[y].getTitle())

      continue;

     else {

      System.out.println("Enter number of pages: ");

      int pages = scan.nextInt();

      Library[y] = new Derro_Books(title3, pages);

     }

    }

   }

  }

  String[] StringList = new String[10];

  for (int y = 0; y < Library.length; y++) {

   StringList[y] = Library[y].getTitle();

  }

  Arrays.sort(StringList);

  for (String bookt : StringList) {

   System.out.println(bookt + Library);

  }

 }

}

}

}

You might be interested in
What is hub.pls ans from pic. for computers​
schepotkina [342]

<h3>what is hub? </h3>

<h3>✅An Ethernet hub, active hub, network hub, repeater hub, multiport repeater, or simply hub is a network hardware device for connecting multiple Ethernet devices together and making them act as a single network segment.</h3>
5 0
3 years ago
Read 2 more answers
A town decides to publicize data it has collected about electricity usage around the city. The data is freely available for all
tigry1 [53]
The answer is C.open data
8 0
3 years ago
Why did artists use pinhole cameras during the renaissance?
murzikaleks [220]
<span>Pinhole cameras were one of the most sophisticated devices of the period, it made tasks much easier it basically worked exactly like the human eye and is something just like tracing.

Hope it helps! :)</span>
3 0
3 years ago
What do you find when you first open a word processor and how do you adjust the document Indentitions
Ilia_Sergeevich [38]

When you first open a word processor document you will find a document with the default indents and margins.

In order to adjust the document indentations the easiest way to do this is to place the cursor where you want the indent to be and then adjust the indent arrow on the ruler at the top of the document to the appropriate value.

7 0
3 years ago
What is the function of a text box in Microsoft word?​
Lisa [10]
A text box is an object you can add to your document that lets you put and type text anywhere in your file. Text boxes can be useful for drawing attention to specific text and can also be helpful when you need to move text around in your document.
4 0
3 years ago
Other questions:
  • Please help
    14·1 answer
  • (Best Buy Part A) At a Best Buy store, the forecast for the annual demand of a Motorola cell phone is 15600. Demand forecasts ar
    12·1 answer
  • Similarly, the Windows server OS can run regular workstation applications such as MS Office or Adobe Photoshop. Why is this a ba
    5·1 answer
  • Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme
    15·1 answer
  • How was WiFi discovered?
    8·1 answer
  • How can you say that a painting is real? ​
    7·2 answers
  • Snippet 1: check_file_permissions.c #include
    9·1 answer
  • Does any of yall play rob lox?
    5·2 answers
  • Aaaaaaaaaaaaaaaaplssssssssssssssssssssssssssssshelpppppppppppppppppppppppp
    11·2 answers
  • balance exercises used for introducing balance training should initially involve little joint motion and improve what type of co
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!