Exemplo n.º 1
0
  private void Deletebook() throws SQLException {
    boolean exit_Add = false;

    int id;
    Map<Integer, Book> m = as.listBooksFirstLevel2();
    Book b = new Book();
    System.out.println("\nBook ID        |       Title        |      Publisher ID");
    System.out.println("----------------------------------------------------------");
    Set<Integer> sk = new HashSet<>();
    for (Map.Entry<Integer, Book> map : m.entrySet()) {
      b = map.getValue();
      if (b.getPublisher() != null) {
        System.out.println(
            map.getKey()
                + "  \t\t "
                + b.getBookId()
                + "  \t\t\t "
                + b.getPublisher().getPublisherId());
      } else {
        System.out.println(map.getKey() + "  \t\t " + b.getBookId() + "  \t\t\t NULL");
      }
    }
    do {

      System.out.println("Enter the Book Id you want to delete:");

      try {

        id = Integer.parseInt(sc.nextLine().trim());

        if (m.containsKey(id)) {
          b.setBookId(id);
          as.deletebook(b);
          System.out.println("Deletion successfull");
        } else {
          System.out.println("This Id does not exist.");
        }
      } catch (Exception e) {
        System.out.println("INFO:Should be an integer!");
      }

      if (!exit_Add) {
        System.out.println();
        System.out.println();
        System.out.println("Press ' q '  to return or any other key to continue");
        String option = (sc.nextLine());
        if (option.length() > 0) {
          switch (option.charAt(0)) {
            case 'q':
              exit_Add = true;
              break;

            default:
              exit_Add = false;
              break;
          }
        }
      }

    } while (!exit_Add);
  }