import java.time.LocalDateTime;
public class BankAccount {
String name;
LocalDateTime opened;
double balance;
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f",
name, opened.toString(), balance);
}
}
public class Main {
public static void main(String[] args) {
BankAccount account = new BankAccount();
System.out.println(account);
}
}
import java.time.LocalDateTime;
class BankAccount {
String name;
LocalDateTime opened;
double balance;
public BankAccount() {
name = "";
opened = LocalDateTime.now();
balance = 0.0d;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f",
name, opened.toString(), balance);
}
}
BankAccount account = new BankAccount();
import java.time.LocalDateTime;
class BankAccount {
String name;
LocalDateTime opened;
double balance;
public BankAccount() {
name = "";
opened = LocalDateTime.now();
balance = 0.0d;
}
public BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f",
name, opened.toString(), balance);
}
}
import java.time.LocalDateTime;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDateTime opened = LocalDateTime.of(1986, Month.MAY, 30, 4, 30, 0);
BankAccount account = new BankAccount("Tom", opened, 12_642.0f);
System.out.println(account);
}
}
import java.time.LocalDateTime;
public class BankAccount {
String name;
LocalDateTime opened;
double balance;
BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
}
public class Main {
public static void main(String[] args) {
BankAccount bankAccount = new BankAccount();
}
}
import java.time.LocalDateTime;
class BankAccount {
String name;
LocalDateTime opened;
double balance;
public BankAccount(BankAccount account) {
name = account.name;
opened = LocalDateTime.now();
balance = 0.0f;
}
public BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f ",
name, opened.toString(), balance);
}
}
import java.time.LocalDateTime;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDateTime opened = LocalDateTime.of(1986, Month.MAY, 30, 4, 30, 0);
BankAccount account = new BankAccount("Tom", opened, 12_642.0f);
BankAccount newAccount = new BankAccount(account);
System.out.println("Имя владельца для счета account = " + account.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.name);
System.out.println("\nРезультат выполнения кода после изменения имени владельца счета \n");
newAccount.name = "Thomas";
System.out.println("Имя владельца для счета account = " + account.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.name);
}
}
public class Customer {
String name;
public Customer(String name) {
this.name = name;
}
}
import java.time.LocalDateTime;
class BankAccount {
Customer customer;
LocalDateTime opened;
double balance;
public BankAccount(BankAccount account) {
customer = account.customer;
opened = LocalDateTime.now();
balance = 0.0f;
}
public BankAccount(Customer customer, LocalDateTime opened, double balance) {
this.customer = customer;
this.opened = opened;
this.balance = balance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f ",
customer.name, opened.toString(), balance);
}
}
import java.time.LocalDateTime;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDateTime opened = LocalDateTime.of(1986, Month.MAY, 30, 4, 30, 0);
BankAccount account = new BankAccount(new Customer("Tom"), opened, 12_642.0f);
BankAccount newAccount = new BankAccount(account);
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
System.out.println("\nРезультат выполнения кода после изменения имени владельца счета newAccount:\n");
newAccount.customer.name = "Thomas";
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
System.out.println("\nРезультат выполнения кода после изменения имени владельца счета account:\n");
account.customer.name = "Max";
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
}
}
import java.time.LocalDateTime;
class BankAccount {
Customer customer;
LocalDateTime opened;
double balance;
public BankAccount(BankAccount account) {
customer = new Customer(account.customer.name);
opened = LocalDateTime.now();
balance = 0.0f;
}
public BankAccount(Customer customer, LocalDateTime opened, double balance) {
this.customer = customer;
this.opened = opened;
this.balance = balance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f ",
customer.name, opened.toString(), balance);
}
}
import java.time.LocalDateTime;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDateTime opened = LocalDateTime.of(1986, Month.MAY, 30, 4, 30, 0);
BankAccount account = new BankAccount(new Customer("Tom"), opened, 12_642.0f);
BankAccount newAccount = new BankAccount(account);
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
System.out.println("\nРезультат выполнения кода после изменения имени владельца счета newAccount:\n");
newAccount.customer.name = "Thomas";
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
System.out.println("\nРезультат выполнения кода после изменения имени владельца счета account:\n");
account.customer.name = "Max";
System.out.println("Имя владельца для счета account = " + account.customer.name);
System.out.println("Имя владельца для счета newAccount = " + newAccount.customer.name);
}
}
import java.time.LocalDateTime;
class BankAccount {
String name;
LocalDateTime opened;
double balance;
public BankAccount() {
this("", LocalDateTime.now(), 0.0d);
}
public BankAccount(BankAccount account) {
this(account.name, LocalDateTime.now(), 0.0f);
}
public BankAccount(String name) {
this(name, LocalDateTime.now(), 0.0f);
}
public BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f",
name, opened.toString(), balance);
}
}
public class Main {
public static void main(String[] args) {
BankAccount account = new BankAccount("Tom");
System.out.println(account);
}
}
import java.time.LocalDateTime;
public class VipBankAccount extends BankAccount {
String status;
public VipBankAccount(String name, String status) {
super(name, LocalDateTime.now(), 0.0f);
this.status = status;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f \nСтатус: %s",
name, opened.toString(), balance, status);
}
}
public class Main {
public static void main(String[] args) {
VipBankAccount vipAccount = new VipBankAccount("Thomas", "VIP");
System.out.println(vipAccount);
}
}
import java.time.LocalDateTime;
public class Transaction {
final BankAccount bankAccount;
final LocalDateTime date;
final double amount;
/*
Код ниже приведет к ошибке компиляции, если переменная amount будет final
public Transaction(BankAccount account, LocalDateTime date) {
this.bankAccount = account;
this.date = date;
}
*/
public Transaction(BankAccount account, LocalDateTime date, double amount) {
this.bankAccount = account;
this.date = date;
this.amount = amount;
}
@Override
public String toString() {
return String.format("Проведена транзакция на сумму - %s, \n\nС банковского счета 17: - %s. \n\nДата и время транзакции: %s", amount, bankAccount, date.toString());
}
}
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime actionDate = LocalDateTime.now();
BankAccount account = new BankAccount("Tom");
Transaction transaction = new Transaction(account, actionDate, 1234);
System.out.println(transaction);
}
}
import java.time.LocalDateTime;
public class BankAccount {
String name;
LocalDateTime opened;
double balance;
BankAccount() {
name = "";
opened = LocalDateTime.now();
balance = 0.0d;
}
BankAccount(String name) {
this.name = name;
}
BankAccount(String name, LocalDateTime opened) {
this.name = name;
this.opened = opened;
}
BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
}
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime actionDate = LocalDateTime.now();
BankAccount bankAccount1 = new BankAccount();
BankAccount bankAccount2 = new BankAccount("Tom");
BankAccount bankAccount3 = new BankAccount("Tom", actionDate);
BankAccount bankAccount4 = new BankAccount("Tom", actionDate, 0.0);
}
}
import java.time.LocalDateTime;
public class BankAccount {
String name;
LocalDateTime opened;
double balance;
BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
}
class VipBankAccount extends BankAccount {
}
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime actionDate = LocalDateTime.now();
VipBankAccount vipBankAccount = new VipBankAccount("Tom", actionDate, 0.0);
}
}
import java.time.LocalDateTime;
public class VipBankAccount extends BankAccount {
VipBankAccount(String name, LocalDateTime opened, double balance) {
super(name, opened, balance);
}
}
import java.time.LocalDateTime;
public class BankAccount {
private static BankAccount instance;
String name;
LocalDateTime opened = LocalDateTime.now();
double balance = 0.0f;
private BankAccount(String name) {
this.name = name;
}
public static BankAccount getInstance(String name) {
if (instance == null) {
instance = new BankAccount(name);
}
return instance;
}
@Override
public String toString() {
return String.format("Имя: %s \nДата создания: %s \nБаланс: %f\n", name, opened.toString(), balance);
}
}
public class Main {
public static void main(String[] args) {
BankAccount bankAccount1 = BankAccount.getInstance("Tom");
BankAccount bankAccount2 = BankAccount.getInstance("Elena");
System.out.println(bankAccount1);
System.out.println(bankAccount2);
}
}
public class BankAccountUtils {
private BankAccountUtils() {}
public static String namesConcatenate(String name, String surname) {
return name + " " + surname;
}
}
public class Main {
public static void main(String[] args) {
System.out.println(BankAccountUtils.namesConcatenate("Tom", "Jeferson"));
}
}
public class BankAccount { }
public BankAccount() { }
import java.time.LocalDateTime;
public class BankAccount {
String name;
LocalDateTime opened;
double balance;
public BankAccount(String name, LocalDateTime opened, double balance) {
this.name = name;
this.opened = opened;
this.balance = balance;
}
}
public class VipBankAccount extends BankAccount {
VipBankAccount() {}
}
VipBankAccount() {
super(); // метод вставлен компилятором автоматически
}