/
vikkkka
/
development_tools_lesson_2
Обзор
Документация
Войти
/
vikkkka
/
development_tools_lesson_2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Account.java
75 строк
2 KB
Vika
First commit
15 дек 2025, 12:10
15 дек 2025, 12:10
d82b2c6
Код
Авторство
О чём код?
import java.util.Date; public class Account { // Скрытые поля данных private int id; private double balance; private static double annualInterestRate = 0; private Date dateCreated; // Конструкторы public Account() { this.id = 0; this.balance = 0; this.dateCreated = new Date(); } public Account(int id, double balance) { this.id = id; this.balance = balance; this.dateCreated = new Date(); } // Getter и Setter методы public int getId() { return id; } public void setId(int id) { this.id = id; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public static double getAnnualInterestRate() { return annualInterestRate; } public static void setAnnualInterestRate(double annualInterestRate) { Account.annualInterestRate = annualInterestRate; } public Date getDateCreated() { return dateCreated; } // Метод для получения ежемесячного процента public double getMonthlyInterest() { double monthlyInterestRate = annualInterestRate / 12 / 100; return balance * monthlyInterestRate; } // Метод для снятия денег public void withdraw(double amount) { if (amount > 0 && amount <= balance) { balance -= amount; } else { System.out.println("Недостаточно средств или неверная сумма для снятия!"); } } // Метод для пополнения счета public void deposit(double amount) { if (amount > 0) { balance += amount; } else { System.out.println("Неверная сумма для пополнения!"); } } }