Skip to content

Commit a5d3f26

Browse files
Add files via upload
0 parents  commit a5d3f26

File tree

12 files changed

+290
-0
lines changed

12 files changed

+290
-0
lines changed

1.a.png

1.3 MB
Loading

1.b.png

1.32 MB
Loading

1.c.png

1.38 MB
Loading

1.d.png

1.36 MB
Loading

2.png

1.11 MB
Loading

Book.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package Task3;
2+
3+
import java.util.Scanner;
4+
5+
// creating a class Book
6+
public class Book {
7+
// creating the attributes
8+
private int bookId;
9+
private String author;
10+
private String title;
11+
private boolean isAvailable;
12+
13+
// creating default constructor
14+
public Book() {
15+
super();
16+
}
17+
18+
// creating parameterized constructor
19+
public Book(int bookId, String author, String title, boolean isAvailable) {
20+
super();
21+
this.bookId = bookId;
22+
this.author = author;
23+
this.title = title;
24+
this.isAvailable = isAvailable;
25+
}
26+
27+
// creating getters and setters
28+
public int getBookId() {
29+
return bookId;
30+
}
31+
public void setBookId(int bookId) {
32+
this.bookId = bookId;
33+
}
34+
public String getAuthor() {
35+
return author;
36+
}
37+
public void setAuthor(String author) {
38+
this.author = author;
39+
}
40+
public String getTitle() {
41+
return title;
42+
}
43+
public void setTitle(String title) {
44+
this.title = title;
45+
}
46+
public boolean isAvailable() {
47+
return isAvailable;
48+
}
49+
public void setAvailable(boolean isAvailable) {
50+
this.isAvailable = isAvailable;
51+
}
52+
53+
// creating a method bookMenu
54+
public void bookMenu() {
55+
Scanner sc = new Scanner(System.in);
56+
System.out.println("1: Enter Id of a Book : ");
57+
58+
this.bookId = sc.nextInt();
59+
System.out.println("2: Enter Book Author : ");
60+
61+
this.author = sc.next();
62+
System.out.println("3: Enter Book Title : ");
63+
64+
this.title = sc.next();
65+
66+
}
67+
68+
// creating toString
69+
@Override
70+
public String toString() {
71+
return "Book [bookId=" + bookId + ", author=" + author + ", title=" + title + "]";
72+
}
73+
74+
75+
76+
77+
}

BookManagementSystem.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package Task3;
2+
3+
import java.util.Scanner;
4+
// creating a class that has main method
5+
public class BookManagementSystem {
6+
public static void main(String[] args) {
7+
Library library = new Library();
8+
9+
10+
do {
11+
library.displayMainMenu();
12+
Scanner sc = new Scanner(System.in);
13+
System.out.println("Enter your choice: ");
14+
System.out.println("******************************");
15+
int choice = sc.nextInt();
16+
if (choice == 1) {
17+
Book book = new Book();
18+
book.bookMenu();
19+
library.addBook(book);
20+
}else if (choice == 2) {
21+
System.out.println("Enter the books id that you want to search : ");
22+
int userChoice = sc.nextInt();
23+
int indexUser = library.findBook(userChoice);
24+
System.out.println("The book with the given id is: " + "\r\n" + library.getBook(library.findBook(userChoice)));
25+
}else if (choice == 3) {
26+
System.out.println("Enter the books Id Number that you want to Delete : ");
27+
int userChoice = sc.nextInt();
28+
Book book = library.getBook(library.findBook(userChoice));
29+
library.removeBook(book);
30+
} else if(choice == 4) {
31+
library.getAllBook();
32+
}
33+
} while (true);
34+
}
35+
}
36+
37+

Employee.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Task3;
2+
// creating a class employee
3+
public class Employee implements Taxable{
4+
5+
int EmployeeId;
6+
String name;
7+
float salary;
8+
9+
// creating a parameterized constructor
10+
public Employee(int employeeId, String name, float salary) {
11+
super();
12+
EmployeeId = employeeId;
13+
this.name = name;
14+
this.salary = salary;
15+
}
16+
17+
// implementing the abstract method to calculate incomeTax
18+
@Override
19+
public void calcTax() {
20+
float calcTax = (incomeTax * salary) / 100;
21+
System.out.println("The IncomeTax of the employee is : " + calcTax);
22+
}
23+
}

Library.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package Task3;
2+
3+
// creating a library class
4+
public class Library {
5+
// creating attributes
6+
Book[] books;
7+
public int count;
8+
9+
// creating default constructor
10+
public Library() {
11+
12+
books = new Book[5];
13+
count = 0;
14+
}
15+
16+
// creating a method to count the number of books
17+
public int countBooks() {
18+
return count;
19+
}
20+
21+
// creating a method to search a book
22+
public int findBook(int bookId) {
23+
for (int i = 0; i < count; i++) {
24+
if (books[i].getBookId() == bookId) {
25+
return i;
26+
}
27+
}
28+
return -1;
29+
}
30+
// creating a method to get a book
31+
public Book getBook(int index) {
32+
if (index >= 0 && index <= count) {
33+
return books[index];
34+
}
35+
return null;
36+
}
37+
38+
39+
// creating a method to add a book
40+
public boolean addBook(Book b) {
41+
if (count < books.length && findBook(b.getBookId()) == -1) {
42+
books[count] = b;
43+
count++;
44+
return true;
45+
}
46+
return false;
47+
48+
}
49+
50+
// creating a book to remove book
51+
public boolean removeBook(Book b){
52+
int index = findBook(b.getBookId());
53+
if (index != -1) {
54+
for (int i = index; i < (count - 1); i++) {
55+
books[i] = books[i+1];
56+
}
57+
count--;
58+
return true;
59+
}
60+
return false;
61+
}
62+
63+
// creating a method to print all the books
64+
public void getAllBook() {
65+
System.out.println("All the book in the system are: " + "\r\n");
66+
67+
for(int i = 0; i < count; i++){
68+
System.out.println(books[i]);
69+
System.out.println("\r\n");
70+
}
71+
72+
}
73+
74+
// creating a method to display the menu
75+
public void displayMainMenu(){
76+
System.out.println("******************************");
77+
System.out.println(" Library Menu ");
78+
System.out.println("1: Add a book.");
79+
System.out.println("2: Get a book information.");
80+
System.out.println("3: Delete the book.");
81+
System.out.println("4: Print all books.");
82+
System.out.println("******************************" + "\r\n");
83+
}
84+
}

Main.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package Task3;
2+
3+
import java.util.Scanner;
4+
// creating a class main to implement main method
5+
public class Main {
6+
public static void main(String[]args){
7+
try (Scanner sc = new Scanner(System.in)) {
8+
System.out.println("Enter Employee Details");
9+
System.out.println("=============================================");
10+
System.out.println("Enter EmployeeId");
11+
int empId = sc.nextInt();
12+
System.out.println("Enter Employee Name");
13+
String name = sc.next();
14+
System.out.println("Enter Employee Salary");
15+
float salary = sc.nextFloat();
16+
Taxable tax = new Employee(empId, name, salary);
17+
System.out.println(" ");
18+
tax.calcTax();
19+
System.out.println("=============================================");
20+
System.out.println("Enter Employee Details");
21+
System.out.println("=============================================");
22+
System.out.println("Enter PID");
23+
int pId = sc.nextInt();
24+
System.out.println("Enter Price");
25+
float price = sc.nextFloat();
26+
System.out.println("Enter Quantity");
27+
int quantity =sc.nextInt();
28+
Taxable gst = new Product(pId,price,quantity);
29+
System.out.println(" ");
30+
gst.calcTax();
31+
System.out.println("=============================================");
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)