0% found this document useful (0 votes)
29 views5 pages

ABSTRACT Mini Project

This document defines a Bool class that contains methods for managing a book database. The class contains arrays to store book IDs, names, authors, and prices. It defines methods to search the database by ID, name, or author, add new books, list all books, and display a menu to prompt the user for input. The main method implements a loop that displays the menu, takes user input, and calls the appropriate method to handle searches, additions, or listing all books.

Uploaded by

nehaneha13268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

ABSTRACT Mini Project

This document defines a Bool class that contains methods for managing a book database. The class contains arrays to store book IDs, names, authors, and prices. It defines methods to search the database by ID, name, or author, add new books, list all books, and display a menu to prompt the user for input. The main method implements a loop that displays the menu, takes user input, and calls the appropriate method to handle searches, additions, or listing all books.

Uploaded by

nehaneha13268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

package strings;

import java.util.Scanner;

public class Bool {

static int[][] a = new int[10][2];

static String name[][] = new String[10][2];

static int p = 0;

static void display(int i) {

System.out.println();

static boolean searchID(int id) {

for (int i = 0; i < p; i++) {

if (id == a[0][i]) {

System.out

.println("ID: " + a[i][0] + "\t Name: " + name[i][0] + "\tAuthor: " + name[i][1] + "\tPrice: "

+ a[i][1]);

return true;

return false;

static boolean searchName(String n) {

for (int i = 0; i < p; i++) {

if (n.equalsIgnoreCase(name[i][0])) {

System.out

.println("ID: " + a[i][0] + "\tName: " + name[i][0] + "\tAuthor: " + name[i][1] + "\tPrice: "
+ a[i][1]);

return true;

return false;

static boolean searchAuthor(String au) {

for (int i = 0; i < p; i++) {

if (au.equalsIgnoreCase(name[i][1])) {

System.out

.println("ID: " + a[i][0] + "\tName: " + name[i][0] + "\tAuthor: " + name[i][1] + "\tPrice: "

+ a[i][1]);

return true;

return false;

static boolean list() {

if (p != 0) {

for (int i = 0; i < p; i++) {

System.out

.println("ID: " + a[i][0] + "\tName: " + name[i][0] + " \tAuthor: " + name[i][1] + " \tPrice: "

+ a[i][1]);

return true;

} else

return false;

}
static boolean add(String n, String au, int id, int price) {

for (int i = 0; i < p; i++) {

if (name.equals(name[i][0]) || id == a[i][0]) {

return false;

a[p][0] = id;

a[p][1] = price;

name[p][0] = n;

name[p][1] = au;

p++;

return true;

static void choice() {

System.out.println("Enter the choice");

System.out.println("1: enter the new book datails");

System.out.println("2: Search the book");

System.out.println("3:List of books");

System.out.println("4:exit");

static {

System.out.println("Welcome");

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


int ch = 0;

while (ch < 4) {

choice();

ch = sc.nextInt();

switch (ch) {

case 1:

System.out.println("enter the name");

String na = sc.next();

System.out.println("enter the author");

String au = sc.next();

System.out.println("enter the id");

int id = sc.nextInt();

System.out.println("enter the price");

int price = sc.nextInt();

if (!add(na.toLowerCase(), au.toLowerCase(), id, price)) {

System.out.println("Name or id already exists");

break;

case 2:

int c = 0;

System.out.println("Enter 1: to search on id");

System.out.println("Enter 2: to search on name");

System.out.println("Enter 3: to search on author name");

c = sc.nextInt();

if (c == 1) {

System.out.println("enter the id");

int id1 = sc.nextInt();

if (!searchID(id1))
System.out.println("invalid input");

} else if (c == 2) {

System.out.println("enter the name");

String n1 = sc.next();

if (!searchName(n1)) {

System.out.println("invaid input");

} else if (c == 3) {

System.out.println("enter the author");

String n2 = sc.next();

if (!searchAuthor(n2)) {

System.out.println("invail input");

} else {

System.out.println("invail input");

break;

case 3:

list();

break;

System.out.println();

You might also like