[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

Experiment No 4

The document contains two JAVA programs: the first simulates a banking application using classes and objects, allowing users to input account details, withdraw, and deposit funds while maintaining a minimum balance. The second program performs addition of two 2D matrices and displays the result. Both programs demonstrate basic programming concepts such as user input, array manipulation, and method implementation.

Uploaded by

Madhura Tambe
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)
12 views5 pages

Experiment No 4

The document contains two JAVA programs: the first simulates a banking application using classes and objects, allowing users to input account details, withdraw, and deposit funds while maintaining a minimum balance. The second program performs addition of two 2D matrices and displays the result. Both programs demonstrate basic programming concepts such as user input, array manipulation, and method implementation.

Uploaded by

Madhura Tambe
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/ 5

EXPERIMENT NO 4

1. Write a JAVA Program to display working of banking application using classes


and objects
import java.util.Scanner;

public class Bank {

// Instance variables

private int balance;

private int accountNumber;

private String accountType;

private String accountHolderName;

// Method to input account details

public void input() {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter account holder's name: ");

accountHolderName = scanner.nextLine();

System.out.print("Enter account type: ");

accountType = scanner.nextLine();

System.out.print("Enter account number: ");

accountNumber = scanner.nextInt();

System.out.print("Enter initial balance: ");

balance = scanner.nextInt();
// Space for better readability

System.out.println();

// Method to display account details

public void display() {

System.out.println("Name of the account holder: " + accountHolderName);

System.out.println("Account type: " + accountType);

System.out.println("Account number: " + accountNumber);

System.out.println("Account balance: " + balance);

// Space for better readability

System.out.println();

// Method to withdraw amount from account

public void withdraw() {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter amount you want to withdraw: ");

int withdrawalAmount = scanner.nextInt();

if (balance - withdrawalAmount < 1000) {

System.out.println("Insufficient funds! Minimum balance must be 1000.");

} else {

balance -= withdrawalAmount;

System.out.println("Withdrawal successful. New balance: " + balance);

}
// Space for better readability

System.out.println();

// Method to deposit amount to account

public void deposit() {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter amount you want to deposit: ");

int depositAmount = scanner.nextInt();

balance += depositAmount;

System.out.println("Deposit successful. New balance: " + balance);

// Space for better readability

System.out.println();

// Main method to run the program

public static void main(String[] args) {

Bank bankAccount = new Bank();

bankAccount.input();

bankAccount.display();

bankAccount.withdraw();

bankAccount.display();

bankAccount.deposit();

bankAccount.display();
}

}OUTPUT:
2. Write a JAVA Program to perform Addition of Matrix using 2D array
import java.util.Scanner;
public class Exp4{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,3,4},{2,4,3},{3,4,5}};
int b[][]={{1,3,4},{2,4,3},{1,2,4}};

//creating another matrix to store the sum of two matrices


int c[][]=new int[3][3];
//3 rows and 3 columns

//adding and printing addition of 2 matrices


for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j]=a[i][j]+b[i][j];
//use - for subtraction
System.out.print(c[i][j]+" ");
}
System.out.println();//new line
}
}}
OUTPUT:

You might also like