Initial commit

This commit is contained in:
Kashey committed 2026-10-15 22:08:52 +03:00
commit 357f494a56
14 files changed
+230

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}
+40
View File
@@ -0,0 +1,40 @@
package model;
import java.util.Objects;
public class Account {
private String name;
private final Long id;
public Account(Long id, String name) {
this.id = Objects.requireNonNull(id, "Не указан идентификатор");
setName(name);
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Не указано имя счёта");
}
this.name = name;
}
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Account account = (Account) o;
return Objects.equals(id, account.id);
}
@Override
public int hashCode() {
return id.hashCode();
}
}
+22
View File
@@ -0,0 +1,22 @@
package model;
public class Category {
private String name;
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
+25
View File
@@ -0,0 +1,25 @@
package model;
import java.math.BigDecimal;
import java.time.LocalDate;
public class LedgerEntry {
private LocalDate date;
private Operation operation;
private Account account;
private Category category;
public BigDecimal getDeltaAmount() {
return deltaAmount;
}
private BigDecimal deltaAmount;
public LocalDate getDate() {
return date;
}
public Account getAccount() {
return account;
}
}
+15
View File
@@ -0,0 +1,15 @@
package model;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.time.LocalDate;
public class Operation {
private LocalDate date;
private Long id;
private OperationType type;
private Account sourceAccount;
private Account destinationAccount;
private BigDecimal total;
private final ArrayList<OperationLine> lines = new ArrayList<>();
}
+8
View File
@@ -0,0 +1,8 @@
package model;
import java.math.BigDecimal;
public class OperationLine {
private Category category;
private BigDecimal amount;
}
+8
View File
@@ -0,0 +1,8 @@
package model;
public enum OperationType {
OPENING_BALANCE,
INFLOW,
OUTFLOW,
MOVEMENT
}
+33
View File
@@ -0,0 +1,33 @@
package service;
import model.Account;
import model.LedgerEntry;
import model.Operation;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.time.LocalDate;
public class Ledger {
private final ArrayList<LedgerEntry> entries = new ArrayList<>();
public void post(Operation operation) {
}
public BigDecimal balance(Account account, LocalDate date) {
BigDecimal result = BigDecimal.ZERO;
for (LedgerEntry entry: entries) {
boolean sameAccount = entry.getAccount().equals(account);
boolean withinPeriod = !entry.getDate().isAfter(date);
if (sameAccount && withinPeriod) {
result = result.add(entry.getDeltaAmount());
}
}
return result;
}
}