KEMBAR78
Methods Class2 | PDF
0% found this document useful (0 votes)
8 views2 pages

Methods Class2

The document is a Java program that implements a simple banking system allowing users to deposit, withdraw, and check their balance. It uses a loop to continuously prompt the user for input until they choose to exit. The program includes methods for depositing and withdrawing funds, with basic validation for input amounts.

Uploaded by

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

Methods Class2

The document is a Java program that implements a simple banking system allowing users to deposit, withdraw, and check their balance. It uses a loop to continuously prompt the user for input until they choose to exit. The program includes methods for depositing and withdrawing funds, with basic validation for input amounts.

Uploaded by

rejuana.islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.mycompany.

labmethods;

import java.util.Scanner;

public class LabMethods {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int balance =0;
for(int i=0; ;i++)
{
System.out.println("Choose your option:\n press 1 "
+ "to Deposit\n press 2 to"
+ " Witdraw\n press 3 to"
+ " check Balance\n press 4 to exit.");
int n = sc.nextInt();
if(n == 1)
{
double amount = sc.nextDouble();
balance = deposit(amount,balance);
}
else if(n == 2)
{
double amount2 = sc.nextDouble();
balance = withdraw(amount2,balance);
}
else if(n == 3)
{
System.out.println("Your current balance is = "+balance);
}
else if(n == 4)
{
break;
}
else
{
System.out.println("Invalid input. Try again..");
}
}
}

public static int deposit(double amount, int balance) {


if(amount > 0)
{
balance += amount;
}
else{
System.out.println("Enter a valid number.\n");}
System.out.println("Balance after deposit"+balance);
return balance;
}

private static int withdraw(double amount2, int balance) {


if(amount2 > 0)
{
balance -= amount2;
}
else{
System.out.println("Enter a valid number.\n");}
System.out.println("Balance after withdrawal"+balance);
return balance;
}
}

You might also like