0% found this document useful (0 votes)
19 views4 pages

Oops Ssss

The document contains Java code demonstrating method overloading, inheritance, exception handling, and interface implementation in a banking and student management context. It includes classes for shapes to calculate areas, account management with deposit and withdrawal functionalities, and student grading based on marks. The code also shows user interaction through console input for various operations.

Uploaded by

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

Oops Ssss

The document contains Java code demonstrating method overloading, inheritance, exception handling, and interface implementation in a banking and student management context. It includes classes for shapes to calculate areas, account management with deposit and withdrawal functionalities, and student grading based on marks. The code also shows user interaction through console input for various operations.

Uploaded by

msreenath283
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// method overloading // Rectangle input

[Link](“Enter length of rectangle: “);

Import [Link].*; Double length = [Link]([Link]());

[Link](“Enter breadth of rectangle: “);

Class Shape { Double breadth = [Link]([Link]());

// Area of rectangle: length * breadth [Link](“Rectangle Area: “ + [Link](length, breadth));

Public double area(double length, double breadth) {

Return length * breadth; // Triangle input

} [Link](“Enter base of triangle: “);

Double base = [Link]([Link]());

// Area of triangle: 0.5 * base * height [Link](“Enter height of triangle: “);

Public double area(double base, double height, boolean isTriangle) { Double height = [Link]([Link]());

If (isTriangle) { [Link](“Triangle Area: “ + [Link](base, height, true));

Return 0.5 * base * height;

} // Circle input

Return -1; // Invalid case [Link](“Enter radius of circle: “);

} Float radius = [Link]([Link]());

[Link](“Circle Area: “ + [Link](radius));

// Area of circle: π * radius * radius }

Public double area(float radius) { }

Return [Link] * radius * radius;

Public class Exam {

Public static void main(String[] args) throws IOException {

Bu eredReader reader = new Bu eredReader(new InputStreamReader([Link]));

Shape shape = new Shape();

// single inheritance If (balance – amount >= MIN_BALANCE) {

Balance -= amount;

Import [Link].*; [Link](“Withdrawn: “ + amount);

} else {

Class Account { [Link](“Error: Insu icient balance or withdrawal would go below minimum balance.”);

String acno; // Account number }

String name; // Account holder’s name }

Public Account(String acno, String name) { Public void displayBalance() {

[Link] = acno; [Link](“Account: “ + acno);

[Link] = name; [Link](“Name: “ + name);

} [Link](“Current Balance: “ + balance);

} }

Class Savings extends Account {

Double balance; Public class Exam {

Final double MIN_BALANCE = 1000; Public static void main(String[] args) throws IOException {

InputStreamReader isr = new InputStreamReader([Link]);

Public Savings(String acno, String name, double initialBalance) { Bu eredReader br = new Bu eredReader(isr);

Super(acno, name);

[Link] = initialBalance >= MIN_BALANCE ? initialBalance : MIN_BALANCE; // Create an Account and Savings object

} [Link](“Enter Account Number: “);

String acno = [Link]();

Public void deposit(double amount) { [Link](“Enter Account Holder’s Name: “);

Balance += amount; String name = [Link]();

[Link](“Deposited: “ + amount);

} Savings account = new Savings(acno, name, 1500); // Initial balance 1500

Public void withdraw(double amount) { Boolean exit = false;


While (!exit) { }

[Link](“\nBank Menu:”); }

[Link](“1. Deposit”);

[Link](“2. Withdraw”); [Link]();

[Link](“3. Display Balance”); }

[Link](“4. Exit”); }

[Link](“Choose an option: “);

Int choice = [Link]([Link]());

Switch (choice) {

Case 1:

[Link](“Enter deposit amount: “);

Double depositAmount = [Link]([Link]());

[Link](depositAmount);

Break;

Case 2:

[Link](“Enter withdrawal amount: “);

Double withdrawAmount = [Link]([Link]());

[Link](withdrawAmount);

Break;

Case 3:

[Link]();

Break;

Case 4:

[Link](“Exiting…”);

Exit = true;

Break;

Default:

[Link](“Invalid choice. Please try again.”);

// exeption If (math < 60 || phy < 60 || chem < 60) {

Throw new ArithmeticException(“Not eligible: Marks in one or more subjects below 60%”);

Import [Link].*; }

Public class Exam { If (percentage < 50) {

Public static void main(String[] args) throws IOException { Throw new ArithmeticException(“Not eligible: Total percentage below 50%”);

Index obj = new Index(); }

[Link]();

} [Link](“Eligible. Total Percentage: “ + percentage + “%”);

} catch (ArithmeticException e) {

Class Index { [Link]([Link]());

Public void calculate() throws IOException { }

InputStreamReader isr = new InputStreamReader([Link]); }

Bu eredReader br = new Bu eredReader(isr); }

Try {

[Link](“Enter Math marks: “);

Int math = [Link]([Link]());

[Link](“Enter Physics marks: “);

Int phy = [Link]([Link]());

[Link](“Enter Chemistry marks: “);

Int chem = [Link]([Link]());

Double total = math + phy + chem;

Double percentage = total / 3.0;


// multi level inheritance }

Import [Link].*; Public double calculateTotalMarks() {

Return (ceMarks / 50.0) * 100 + (eseMarks / 75.0) * 100;

Class Student { }

String regNo; // Registration number

String name; // Name of the student Public String calculateGrade() {

Double totalMarks = calculateTotalMarks();

Public Student(String regNo, String name) { If (totalMarks >= 85) {

[Link] = regNo; Return “A”;

[Link] = name; } else if (totalMarks >= 70) {

} Return “B”;

} } else if (totalMarks >= 50) {

Return “C”;

Class CE_Marks extends Student { } else {

Double ceMarks; // Continuous Evaluation marks Return “F”;

Public CE_Marks(String regNo, String name, double ceMarks) { }

Super(regNo, name);

[Link] = ceMarks; Public void displayDetails() {

} [Link](“Registration Number: “ + regNo);

} [Link](“Name: “ + name);

[Link](“CE Marks: “ + ceMarks + “/50”);

Class ESE_Marks extends CE_Marks { [Link](“ESE Marks: “ + eseMarks + “/75”);

Double eseMarks; // End-Semester Exam marks [Link](“Total Marks: “ + calculateTotalMarks());

[Link](“Grade: “ + calculateGrade());

Public ESE_Marks(String regNo, String name, double ceMarks, double eseMarks) { }

Super(regNo, name, ceMarks); }

[Link] = eseMarks;

Public class Exam { // interface

Public static void main(String[] args) throws IOException {

InputStreamReader isr = new InputStreamReader([Link]); Import [Link].*;

Bu eredReader br = new Bu eredReader(isr);

Interface Savings {

// Get student details Void withdraw(double amount);

[Link](“Enter Registration Number: “); Double MIN_BAL = 500;

String regNo = [Link](); }

[Link](“Enter Name: “);

String name = [Link](); Class Account implements Savings {

[Link](“Enter CE Marks (out of 50): “); String acno;

Double ceMarks = [Link]([Link]()); String name;

[Link](“Enter ESE Marks (out of 75): “); String address;

Double eseMarks = [Link]([Link]()); Double bal;

// Create an instance of ESE_Marks and display the details Account(String acno, String name, String address, double bal) {

ESE_Marks student = new ESE_Marks(regNo, name, ceMarks, eseMarks); [Link] = acno;

[Link](); [Link] = name;

} [Link] = address;

} [Link] = bal >= MIN_BAL ? bal : MIN_BAL;

Public void deposit(double amount) {

If (amount > 0) {

Bal += amount;

[Link](“Deposited: “ + amount);

} else {

[Link](“Invalid deposit amount.”);

}
} [Link](“Enter Address: “);

String addr = [Link]();

Public void withdraw(double amount) { [Link](“Enter Initial Balance: “);

If (amount > 0 && (bal – amount) >= MIN_BAL) { Double bal = [Link]([Link]());

Bal -= amount;

[Link](“Withdrawn: “ + amount); Account account = new Account(acno, name, addr, bal);

} else {

[Link](“Cannot withdraw. Balance would fall below minimum.”); Boolean running = true;

} While (running) {

} [Link](“\n--- Menu ---“);

[Link](“1. Deposit”);

Public void enquiry() { [Link](“2. Withdraw”);

[Link](“\nAccount Details:”); [Link](“3. Enquiry”);

[Link](“Account Number: “ + acno); [Link](“4. Exit”);

[Link](“Name: “ + name); [Link](“Choose an option: “);

[Link](“Address: “ + address); Int choice = [Link]([Link]());

[Link](“Current Balance: “ + bal);

} Switch (choice) {

} Case 1:

[Link](“Enter deposit amount: “);

Public class Exam { Double dep = [Link]([Link]());

Public static void main(String[] args) throws IOException { [Link](dep);

Bu eredReader br = new Bu eredReader(new InputStreamReader([Link])); Break;

// Get account details before menu Case 2:

[Link](“Enter Account Number: “); [Link](“Enter withdrawal amount: “);

String acno = [Link](); Double wdr = [Link]([Link]());

[Link](“Enter Name: “); [Link](wdr);

String name = [Link](); Break;

Case 3:

[Link]();

Break;

Case 4:

Running = false;

[Link](“Exiting…”);

Break;

Default:

[Link](“Invalid choice.”);

You might also like