Tuesday, 24 June 2025

Implement a robust Java calculator program that computes user input dynamically. ( OOPCGL 2024 Course)



PCC-205-COM: Object Oriented programming and Computer Graphics Lab (2024 Course)



Group A

1. Title: Implement a robust Java calculator program 


2. Objective: To explore & understand the principles of Object-Oriented Programming (OOP).


3. Problem Statement: Implement a robust Java calculator program that captures user input dynamically, processes mathematical operations using conditional logic and looping constructs, and ensures efficient error handling.


4. Outcomes:

After implementing the above problem statement, the expected output is as follows:

1. Dynamically user can accept any input.

2. User can perform following mathematical operations using conditional logic (operational rules R) and looping constructs.

    2.1 Addition of input a, b (a + b)

    2.2 Subtraction of input a, b (a - b)

   2.3 Multiplication of input a, b (a * b)

    2.4 Division of input a, b (a / b)

    2.5 Reminder of input a, b (a % b)

3. Error like divide by zero error gets handle by using try and catch block.


5. Software and Hardware Requirements:

5.1 Software Requirements: 

1. Operating System: 64-bit Open-source Linux or its derivative

2. Programming tools: - Open-Source Java Open JDK,

3. Programming IDE: BlueJ, Eclipse, NetBeans, JDeveloper.

5.2 Hardware Requirements:

13th Gen Intel(R) Core (TM) i5-13400   2.50 GHz, 8 GB RAM


6. Mathematical Model:

The model can be expressed as:

Given a, b ∈ R and O ∈ {+×÷%} 

Compute R using the operation rules given in Output Section above, Subject to b 0 if O∈ {÷, %}.

Where,

Input: a, b, : operator chosen by user

Operations: The calculator performs operations O on inputs a and b

Error: if b = 0 and O∈ {÷, %}.

Constraints: b! = for division (/) and modulus (%)


7. Algorithm:

Step 1: Start

Step 2: Accept input a, b and operator O belongs to +, -, x, / and mod from user dynamically.

Step 3: Now as per the operator following operations are going to be performed.

Step 3.1: if operator is + then show result = a + b

Step 3.2: if operator is - then show result = a - b

Step 3.3: if operator is * then show result = a * b

Step 3.4: if operator is / then check the constraint b (b! =0) is not equal to zero if this constraint is true then you have to throw the exception and handle it by using catch block. else if this constraint is false you have to do normal operation & show result = a / b.

Step 3.5: if operator is % (mod) then check the constraint b (b! =0) is not equal to zero if this constraint is true then you have to throw the exception and handle it by using catch block. else if this constraint is false you have to do normal operation & show result = a % b.

Step 4: Stop


8. Flowchart:


9. Program Code:



10. Sample Output:

Test Case: 01 Inputs to test all basic operation of calculator using valid inputs.


Test Case: 02 Inputs to test Exception Handling



11. Conclusion:

Hence, we learn how to apply fundamental programming constructs in Java for implementing an application.


Note: 

Dear Readers,
    if you have any suggestions or find any misconception in above implemented code, please guide me for the same. so that i can improve myself for the same. Thanking you in advance. Please reply to your valuable feedback here in comments or DM me on +91 9096454130

data structures and algorithms Web Developer

Saturday, 21 June 2025

Group A: Library Management System using Python (SPPU SE Computer New Syllabus 2024 PAT)


National Education Policy (NEP)-2020 Compliant Curriculum
SE - Second Year Engineering (2024 Pattern) 
in
Computer Engineering
&
Computer Science and Engineering


Problem Statement:

Write a Python program to manage the borrowing records of books in a library. Implement the following functionalities:

 • Compute the average number of books borrowed by all library members. 

 • Find the book with the highest and lowest number of borrowings 

    in the library. 

 • Count the number of members who have not borrowed any books 

    (denoted by a borrow count of 0). 

 • Display the most frequently borrowed book (i.e. the mode of 

    borrow counts).

 After performing, determine the time and Space complexity of each operation


Dear Reader,

By reading the above problem statement, we come to know that we want to implement Library Management System using Python Programming language with some specific functionalities.


Algorithm:

First thing we need to implement Class with some basic functionalities.
1. Types of Data Structures we are using such as Dictionary, Nested Dictionary, List of      Tuples.
2. Basic Functionalities are as follows:
    2.1 Register Users or Enroll users inside the library.
    2.2 Display all the enrolled or registered users from the library.
    2.3 Add book information inside the library.
    2.4 Display all books information added inside the library.
    2.5 Borrow book functionality through which user can borrow books available                      inside library.
    2.6 Display the borrow log of books.
3. Finding the book with the highest and lowest number of borrowings in the library.
4. Display the most frequently borrowed book.
5. Count the number of members who have not borrowed any books.
6. Compute the average number of books borrowed by all library members.


Let's start the implementation of above problem statement.

1. Types of Data Structures we are using such as Dictionary, Nested Dictionary, List of      Tuples.




2. Basic Functionalities are as follows:
    2.1 Register Users or Enroll users inside the library.
    2.2 Display all the enrolled or registered users from the library.
    2.3 Add book information inside the library.
    2.4 Display all books information added inside the library.
    2.5 Borrow book functionality through which user can borrow books available                      inside library.
    2.6 Display the borrow log of books.




3. Finding the book with the highest and lowest number of borrowings in the library.



From line number 96 we have created the object (nmshivalelibrary) of MyLibrary Class and through that object we are calling all member function of that respective MyLibrary class.



After calling all the member functions let's check how our code is going to execute. let's understand it through below output:




4. Display the most frequently borrowed book.

Algorithm:
1. Start

2. First check is their book in books dictionary, if not say No books else go to next step.

3. As we know in book dictionary, we store every book information along with book id - book name and it borrow count. for e.g. 101, {'book_name':'TOC', 'borrow_count': 2} 
we also know dictionary stores data in key value pair so here book id is key and remaining like book_name and borrow_count acts as a value. now from this value we want to find out the max borrow_count for that purpose we write lambda function inside max function so that we will get max value of borrow count.

4. once we get the max value i:e max_borrow from borrow_count of books dictionary then we will search for book name of that particular max_borrow from book_name and stored it inside most_borrowed variable.

5. finally we display the most borrowed book or frequently borrowed book.


By referring the code of above function, we can find out the most frequently borrowed book.

5. Count the number of members who have not borrowed any books.

Algorithm:

1. Start

2. First of all, from the borrower_log you have to find out the user id of users who borrow the book into the set of borrowed_user_ids. To do this we iterate inside the borrower_log list where we store user_id and book_id in tuple format like (user_id, book_id).

3. Now from that tuple we just want to deal with 0th index record of each tuple so to do this we have written a code like user_id = record [0] by doing this we are just collecting the user id from borrower_log and store it inside the borrower_user_ids set using add ( ) method

4. Once we get all user ids from borrower_log next, we have to search user_id from user's dictionary who is not in  borrower_user_ids set. Those who are not in borrower_user_ids set we put or store them inside users_without_books list.

5. finally we display them as users who have not issued or borrowed any book with its user id and username.

6. Stop




6. Compute the average number of books borrowed by all library members.

Algorithm:

1. Start

2. Find out the total number of books borrowed in sum_of_book_borrow

3. Find the length of number of users registered inside library system in 
    no_of_lib_members

4. Find out the average = (sum_of_book_borrow / no_of_lib_members)

5. Show the computed average number of books borrowed by 
    all library members.

6. Stop




Note: Dear readers if you have any suggestion, please guide me for the same write your comment in comment box so that I can correct myself. Thanking you in advance.


data structures and algorithms Web Developer