0% found this document useful (0 votes)
4 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)
4 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
You are on page 1/ 4

// method overloading // Rectangle input

System.out.print(“Enter length of rectangle: “);

Import java.io.*; Double length = Double.parseDouble(reader.readLine());

System.out.print(“Enter breadth of rectangle: “);

Class Shape { Double breadth = Double.parseDouble(reader.readLine());

// Area of rectangle: length * breadth System.out.println(“Rectangle Area: “ + shape.area(length, breadth));

Public double area(double length, double breadth) {

Return length * breadth; // Triangle input

} System.out.print(“Enter base of triangle: “);

Double base = Double.parseDouble(reader.readLine());

// Area of triangle: 0.5 * base * height System.out.print(“Enter height of triangle: “);

Public double area(double base, double height, boolean isTriangle) { Double height = Double.parseDouble(reader.readLine());

If (isTriangle) { System.out.println(“Triangle Area: “ + shape.area(base, height, true));

Return 0.5 * base * height;

} // Circle input

Return -1; // Invalid case System.out.print(“Enter radius of circle: “);

} Float radius = Float.parseFloat(reader.readLine());

System.out.println(“Circle Area: “ + shape.area(radius));

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

Public double area(float radius) { }

Return Math.PI * radius * radius;

Public class Exam {

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

Bu eredReader reader = new Bu eredReader(new InputStreamReader(System.in));

Shape shape = new Shape();

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

Balance -= amount;

Import java.io.*; System.out.println(“Withdrawn: “ + amount);

} else {

Class Account { System.out.println(“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() {

This.acno = acno; System.out.println(“Account: “ + acno);

This.name = name; System.out.println(“Name: “ + name);

} System.out.println(“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(System.in);

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

Super(acno, name);

This.balance = initialBalance >= MIN_BALANCE ? initialBalance : MIN_BALANCE; // Create an Account and Savings object

} System.out.print(“Enter Account Number: “);

String acno = br.readLine();

Public void deposit(double amount) { System.out.print(“Enter Account Holder’s Name: “);

Balance += amount; String name = br.readLine();

System.out.println(“Deposited: “ + amount);

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

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


While (!exit) { }

System.out.println(“\nBank Menu:”); }

System.out.println(“1. Deposit”);

System.out.println(“2. Withdraw”); Br.close();

System.out.println(“3. Display Balance”); }

System.out.println(“4. Exit”); }

System.out.print(“Choose an option: “);

Int choice = Integer.parseInt(br.readLine());

Switch (choice) {

Case 1:

System.out.print(“Enter deposit amount: “);

Double depositAmount = Double.parseDouble(br.readLine());

Account.deposit(depositAmount);

Break;

Case 2:

System.out.print(“Enter withdrawal amount: “);

Double withdrawAmount = Double.parseDouble(br.readLine());

Account.withdraw(withdrawAmount);

Break;

Case 3:

Account.displayBalance();

Break;

Case 4:

System.out.println(“Exiting…”);

Exit = true;

Break;

Default:

System.out.println(“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 java.io.*; }

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(); }

Obj.calculate();

} System.out.println(“Eligible. Total Percentage: “ + percentage + “%”);

} catch (ArithmeticException e) {

Class Index { System.out.println(e.getMessage());

Public void calculate() throws IOException { }

InputStreamReader isr = new InputStreamReader(System.in); }

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

Try {

System.out.print(“Enter Math marks: “);

Int math = Integer.parseInt(br.readLine());

System.out.print(“Enter Physics marks: “);

Int phy = Integer.parseInt(br.readLine());

System.out.print(“Enter Chemistry marks: “);

Int chem = Integer.parseInt(br.readLine());

Double total = math + phy + chem;

Double percentage = total / 3.0;


// multi level inheritance }

Import java.io.*; 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) {

This.regNo = regNo; Return “A”;

This.name = 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);

This.ceMarks = ceMarks; Public void displayDetails() {

} System.out.println(“Registration Number: “ + regNo);

} System.out.println(“Name: “ + name);

System.out.println(“CE Marks: “ + ceMarks + “/50”);

Class ESE_Marks extends CE_Marks { System.out.println(“ESE Marks: “ + eseMarks + “/75”);

Double eseMarks; // End-Semester Exam marks System.out.println(“Total Marks: “ + calculateTotalMarks());

System.out.println(“Grade: “ + calculateGrade());

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

Super(regNo, name, ceMarks); }

This.eseMarks = eseMarks;

Public class Exam { // interface

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

InputStreamReader isr = new InputStreamReader(System.in); Import java.io.*;

Bu eredReader br = new Bu eredReader(isr);

Interface Savings {

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

System.out.print(“Enter Registration Number: “); Double MIN_BAL = 500;

String regNo = br.readLine(); }

System.out.print(“Enter Name: “);

String name = br.readLine(); Class Account implements Savings {

System.out.print(“Enter CE Marks (out of 50): “); String acno;

Double ceMarks = Double.parseDouble(br.readLine()); String name;

System.out.print(“Enter ESE Marks (out of 75): “); String address;

Double eseMarks = Double.parseDouble(br.readLine()); 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); This.acno = acno;

Student.displayDetails(); This.name = name;

} This.address = address;

} This.bal = bal >= MIN_BAL ? bal : MIN_BAL;

Public void deposit(double amount) {

If (amount > 0) {

Bal += amount;

System.out.println(“Deposited: “ + amount);

} else {

System.out.println(“Invalid deposit amount.”);

}
} System.out.print(“Enter Address: “);

String addr = br.readLine();

Public void withdraw(double amount) { System.out.print(“Enter Initial Balance: “);

If (amount > 0 && (bal – amount) >= MIN_BAL) { Double bal = Double.parseDouble(br.readLine());

Bal -= amount;

System.out.println(“Withdrawn: “ + amount); Account account = new Account(acno, name, addr, bal);

} else {

System.out.println(“Cannot withdraw. Balance would fall below minimum.”); Boolean running = true;

} While (running) {

} System.out.println(“\n--- Menu ---“);

System.out.println(“1. Deposit”);

Public void enquiry() { System.out.println(“2. Withdraw”);

System.out.println(“\nAccount Details:”); System.out.println(“3. Enquiry”);

System.out.println(“Account Number: “ + acno); System.out.println(“4. Exit”);

System.out.println(“Name: “ + name); System.out.print(“Choose an option: “);

System.out.println(“Address: “ + address); Int choice = Integer.parseInt(br.readLine());

System.out.println(“Current Balance: “ + bal);

} Switch (choice) {

} Case 1:

System.out.print(“Enter deposit amount: “);

Public class Exam { Double dep = Double.parseDouble(br.readLine());

Public static void main(String[] args) throws IOException { Account.deposit(dep);

Bu eredReader br = new Bu eredReader(new InputStreamReader(System.in)); Break;

// Get account details before menu Case 2:

System.out.print(“Enter Account Number: “); System.out.print(“Enter withdrawal amount: “);

String acno = br.readLine(); Double wdr = Double.parseDouble(br.readLine());

System.out.print(“Enter Name: “); Account.withdraw(wdr);

String name = br.readLine(); Break;

Case 3:

Account.enquiry();

Break;

Case 4:

Running = false;

System.out.println(“Exiting…”);

Break;

Default:

System.out.println(“Invalid choice.”);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy