/
GermanezZ
/
JavaExercises
Обзор
Документация
Войти
/
GermanezZ
/
JavaExercises
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
TestTasks/Tests.java
102 строки
2 KB
germa
Калибровка
22 дек 2024, 23:02
22 дек 2024, 23:02
faefd60
Код
Авторство
О чём код?
package TestTasks; public class Tests { public static void main(String[] args) { Rectangle rectangle = new Rectangle(10,20); rectangle.getArea(); Circle circle = new Circle(10); circle.getCircumference(); Employee employee = new Employee("John",100000,"Java-developer"); System.out.println(employee); System.out.println("---------------------"); BankAccount bankAccount = new BankAccount(121,1000); bankAccount.deposit(500); bankAccount.withdraw(200); } } class Rectangle{ private int width; private int height; Rectangle(int width, int height) { this.width = width; this.height = height; } public void getArea() { System.out.println("Площадь прямоугольника: " + width * height); } } class Circle{ private int radius; Circle(int radius) { this.radius = radius; } public void getCircumference() { System.out.println("Длина окружности: " + 2 * Math.PI * radius); } } class Employee{ private String name; private int salary; private String position; public Employee(String name, int salary, String position) { this.name = name; this.salary = salary; this.position = position; } @Override public String toString() { return "Имя: " + name + '\n' + "Должность:" + position + "\nЗарплата:" + salary; } } class BankAccount{ private double balance; private int accountNumber; BankAccount(int accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; System.out.println("Баланс после пополнения: " + balance); } public void withdraw(double amount) { balance -= amount; System.out.println("Баланс после снятия: " + balance); } }