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
Which of the following has allowed computers to have more memory capabilities without making them extremely expensive Virtual me
lina2011 [118]

Virtual memory may provide a reasonably large storage capacity in an affordable cost.

<u>Virtual Memory:</u> the operating systems of all modern computers have virtual memory where a disk is used to transfer the data temporarily from the RAM when physical memory of the computer falls short. Though it is cheap but it does not allow computers to have more memory and frequent swapping even makes the PC slow.

<u>Tiered memory:</u> has the fastest data storage and even has a good storage capacity but is pretty expensive.

<u>Volatile memory:</u> volatile memories have good performance in terms of speed and storage but they still are a little expensive in comparison to non-volatile memory.

<u>Non-volatile memory:</u> they do not provide with large storage capacities.

7 0
3 years ago
Which line of code in this program is MOST likely to result in an error
rjkz [21]

Answer:

What are the choices?

Explanation:

7 0
3 years ago
Read 2 more answers
What part of a computer is the most important?
Nikitich [7]
The CPU is the most important. It is the brains of the Computer.
3 0
3 years ago
Read 2 more answers
According to the reading on the course web pages, the earliest usage of cooking began around _____ million years ago.
fenix001 [56]

Answer:

According to the reading on the course web pages, the earliest usage of clothes began around ____ million years ago. 3.4 1.5 0.8 0.5 1.7 2. According to the reading on the course web pages, lime mortar was probably discovered from annealing: Charcoal Obsidian Flint Glass 3.

Explanation:

6 0
3 years ago
Hilda is troubleshooting a problem with the encryption of data. at which layer of the osi reference model is she working?
Fittoniya [83]
The la<span>yer of the osi reference model that hilda is currently working on is: presentation
On Osi reference model, the presentation layer is created </span><span>to take care of the semantics and syntax of the information exchanged between two systems. The presentation layer will make sure that the receiver of the information will understand the data that being given.</span>
7 0
3 years ago
Other questions:
  • What is the term for the process of gathering information through images taken at a distance?
    13·1 answer
  • Please I need all the help I can get Thank You So Much
    14·1 answer
  • Identify the four basic categories of hardware in a microcomputer system. system unit, modem, ram, and microprocessor system uni
    5·1 answer
  • Oracion con punto focal​
    6·1 answer
  • Communications that take the form of electronic junk mail or unsolicited e-mail are referred to as
    13·2 answers
  • What is a benefit of the rise in citizen journalism? Multiple answer choice below
    13·1 answer
  • D State Six Impact of ICT the society​
    7·1 answer
  • There's a rising issue with bots sending links starting with 'bit'. These links are dangerous and harmful for any computer or de
    6·2 answers
  • The type value ____ for the input element may cause modern browsers to validate entries to ensure that they are valid web addres
    14·1 answer
  • QUESTION 5
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!