import java.util.Scanner; public class




Download 0,52 Mb.
bet7/7
Sana26.11.2023
Hajmi0,52 Mb.
#105710
1   2   3   4   5   6   7
Bog'liq
Types of Exceptions

import java.util.Scanner;

public class AccountManagement {
private float currentBalance = 15000f;

public static void main(String[] args) {
Scanner inputDevice = new Scanner(System.in);
System.out.print("Iltimos, hisobingizga qo'shiladigan mablag'ni kiriting: ");
float yangiMablag = inputDevice.nextFloat();

try {
float umumiyMablag = new AccountManagement().AddAmount(yangiMablag);
System.out.println("Umumiy Hisob Mablag'i = " + umumiyMablag);
} catch (AccountBalanceException e) {
float fdMablag = e.getAccountBalance() - 20000;
System.out.println("Hisob mablag'ingiz hozirgi 20,000 dan ko'p, shuning uchun " +
"mablag'ning " + fdMablag + " miqdorida FD yaratilmoqda");
new AccountManagement().createFixDeposit(fdMablag);
System.out.println("Hisob Mablag'i = 20,000");
}
}

public float AddAmount(float mablag) throws AccountBalanceException {
float umumiy = currentBalance + mablag;
if (umumiy > 20000) {
throw new AccountBalanceException(umumiy);
}
return umumiy;
}

public void createFixDeposit(float fdMablag) {
// FD yaratishning amaliyoti
System.out.println("Fix Deposit yaratildi! Mablag': " + fdMablag);
}
}

class AccountBalanceException extends Exception {
private float accountBalance;

public AccountBalanceException(float mablag) {
super();
this.accountBalance = mablag;
}

public AccountBalanceException(String xabar) {
super(xabar);
}

public float getAccountBalance() {
return accountBalance;
}
}








Download 0,52 Mb.
1   2   3   4   5   6   7




Download 0,52 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



import java.util.Scanner; public class

Download 0,52 Mb.