|
import java.util.Scanner;
public class
|
bet | 7/7 | Sana | 26.11.2023 | Hajmi | 0,52 Mb. | | #105710 |
Bog'liq Types of Exceptionsimport 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;
}
}
|
| |