Merged categories into one file

This commit is contained in:
mirrerror
2023-09-21 11:48:43 +03:00
parent 0918a51f7a
commit 89faf93a66
7 changed files with 47 additions and 29 deletions

View File

@@ -0,0 +1,28 @@
package entities;
public class Categories {
public enum ExpenseCategory {
MISC;
public String getEffectiveName() {
return Categories.getEffectiveName(this.name());
}
}
public enum IncomeCategory {
MISC;
public String getEffectiveName() {
return Categories.getEffectiveName(this.name());
}
}
private static String getEffectiveName(String name) {
String[] arr = name.split("");
StringBuilder result = new StringBuilder(arr[0].toLowerCase());
for(int i = 1; i < name.length(); i++) result.append(arr[i]);
return result.toString();
}
}

View File

@@ -1,12 +1,12 @@
package entities; package entities;
public class Expense extends MoneyTransaction { public class Expense implements IMoneyTransaction {
private int userId; private int userId;
private int amount; private int amount;
private ExpensesCategory category; private Categories.ExpenseCategory category;
public Expense(int userId, int amount, ExpensesCategory category) { public Expense(int userId, int amount, Categories.ExpenseCategory category) {
this.userId = userId; this.userId = userId;
this.amount = amount; this.amount = amount;
this.category = category; this.category = category;
@@ -32,10 +32,10 @@ public class Expense extends MoneyTransaction {
@Override @Override
public String getCategory() { public String getCategory() {
return category.toString(); return category.getEffectiveName();
} }
public void setCategory(ExpensesCategory category) { public void setCategory(Categories.ExpenseCategory category) {
this.category = category; this.category = category;
} }
} }

View File

@@ -1,5 +0,0 @@
package entities;
public enum ExpensesCategory {
MISC;
}

View File

@@ -0,0 +1,9 @@
package entities;
public interface IMoneyTransaction {
long getUserId();
int getAmount();
String getCategory();
}

View File

@@ -1,12 +1,12 @@
package entities; package entities;
public class Income extends MoneyTransaction { public class Income implements IMoneyTransaction {
private long userId; private long userId;
private int amount; private int amount;
private IncomeCategory category; private Categories.IncomeCategory category;
public Income(long userId, int amount, IncomeCategory category) { public Income(long userId, int amount, Categories.IncomeCategory category) {
this.userId = userId; this.userId = userId;
this.amount = amount; this.amount = amount;
this.category = category; this.category = category;
@@ -24,7 +24,7 @@ public class Income extends MoneyTransaction {
@Override @Override
public String getCategory() { public String getCategory() {
return category.toString(); return category.getEffectiveName();
} }
public void setUserId(long userId) { public void setUserId(long userId) {
@@ -35,7 +35,7 @@ public class Income extends MoneyTransaction {
this.amount = amount; this.amount = amount;
} }
public void setCategory(IncomeCategory category) { public void setCategory(Categories.IncomeCategory category) {
this.category = category; this.category = category;
} }
} }

View File

@@ -1,5 +0,0 @@
package entities;
public enum IncomeCategory {
MISC;
}

View File

@@ -1,9 +0,0 @@
package entities;
public abstract class MoneyTransaction {
public abstract long getUserId();
public abstract int getAmount();
public abstract String getCategory();
}