import java.util.UUID; public record Money(String currency, java.math.BigDecimal amount) { public Money add(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.add(other.amount)); } public Money subtract(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.subtract(other.amount)); } } public final class Order { private final String id = UUID.randomUUID().toString(); private final String customerEmail; private Money total; private boolean paid; public Order(String customerEmail, Money total) { this.customerEmail = customerEmail; this.total = total; } public String id() { return id; } public String customerEmail() { return customerEmail; } public Money total() { return total; } public boolean isPaid() { return paid; } public void markPaid() { this.paid = true; } public void applyDiscount(Money discounted) { this.total = discounted; } } public record PaymentResult(boolean success, String txId, String message) { }
import java.util.UUID; public record Money(String currency, java.math.BigDecimal amount) { public Money add(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.add(other.amount)); } public Money subtract(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.subtract(other.amount)); } } public final class Order { private final String id = UUID.randomUUID().toString(); private final String customerEmail; private Money total; private boolean paid; public Order(String customerEmail, Money total) { this.customerEmail = customerEmail; this.total = total; } public String id() { return id; } public String customerEmail() { return customerEmail; } public Money total() { return total; } public boolean isPaid() { return paid; } public void markPaid() { this.paid = true; } public void applyDiscount(Money discounted) { this.total = discounted; } } public record PaymentResult(boolean success, String txId, String message) { }
// Пример кода
function hello(name) {
console.log(`Hi, ${name}!`);
}
hello("Sergey");