oopex5
oopex5
30/08/24 URK23AI1035
Aim
Develop an application in Java for automating the Banking Operations using interfaces.
Create an interface called “Transaction” which contains the functions such as deposit,
withdraw, and viewBalance. Create another interface called “Displayable” which
contains the Display () function to display the account details.
Create an abstract class called “Account” with bank account details such as acc_name,
acc_no, and balance. Add necessary constructors.
Create a “Bank” class which implements the “Transaction”, “Displayable” interfaces
and inherits “Account” class.
Perform menu driven operations like Deposit, Withdraw and Balance Enquiry, View
Account Details from a Main class. Write logics in the corresponding methods.
Description
1. Transaction Interface: Contains the deposit(), withdraw(), and viewBalance() methods that define
basic transaction operations.
2. Displayable Interface: Contains the display() method to show account details.
3. Account Abstract Class: Stores the common account information such as account name, number,
and balance. It serves as a base class for Bank.
4. Bank Class: Implements the interfaces and provides the logic for depositing, withdrawing, viewing
balance, and displaying account details.
5. Main Class: Uses a menu-driven system to allow the user to choose between depositing,
withdrawing, viewing balance, and displaying account details.
6.
How the Application Works:
• The user is prompted to enter account details when the program starts.
• The menu allows for various banking operations:
1. Deposit: Allows the user to deposit an amount.
2. Withdraw: Allows the user to withdraw an amount if sufficient balance is available.
3. View Balance: Displays the current balance.
4. View Account Details: Displays account holder’s name, account number, and current balance.
5. Exit: Exits the program.
Program
import java.util.Scanner;
// Transaction Interface
interface Transaction {
void deposit(double amount);
void withdraw(double amount);
double viewBalance();
}
// Displayable Interface
interface Displayable {
void display();
}
switch (choice) {
case 1: // Deposit
System.out.println("Enter amount to deposit:");
double depositAmount = scanner.nextDouble();
bankAccount.deposit(depositAmount);
break;
case 2: // Withdraw
System.out.println("Enter amount to withdraw:");
double withdrawAmount = scanner.nextDouble();
bankAccount.withdraw(withdrawAmount);
break;
case 3: // View Balance
System.out.println("Current Balance: " + bankAccount.viewBalance());
break;
case 4: // View Account Details
bankAccount.display();
break;
case 5: // Exit
System.out.println("Exiting the application...");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please choose a valid option.");
}
}
}
}
Output;
Program
package pkg1;
import pkg1.Books;
import java.util.ArrayList;
package pkg3;
import pkg1.Books;
import java.util.Scanner;
// Menu-driven system
do {
System.out.println("\nLibrary Information System:");
System.out.println("1. Add Book");
System.out.println("2. Search Book");
System.out.println("3. List All Books");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
switch (choice) {
case 1:
// Add a book
System.out.print("Enter Book Title: ");
String title = scanner.nextLine();
System.out.print("Enter Book Author: ");
String author = scanner.nextLine();
System.out.print("Enter Book ISBN: ");
String isbn = scanner.nextLine();
admin.addBook(title, author, isbn);
break;
case 2:
// Search for a book
System.out.print("Enter the title of the book to search: ");
String searchTitle = scanner.nextLine();
Books foundBook = admin.searchBook(searchTitle);
user.viewBookDetails(foundBook);
break;
case 3:
// List all books
admin.listBooks();
break;
case 4:
// Exit the program
System.out.println("Exiting the Library Information System.");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 4);
scanner.close();
}
}
Output
Result
Successfully implemented and executed the creation and manipulation of classes and objects in
Java to solve real-world problems using inheritance, method overriding, and runtime
polymorphism.