Browse Source

Kapselung in neue Klasse

Eduard2
eduardD 5 years ago
parent
commit
55f860689c
  1. 36
      Budget Projekt/src/MeinBudgetView/Calculations.java
  2. 15
      Budget Projekt/src/MeinBudgetView/MeinGui.java
  3. 34
      Budget Projekt/src/MeinBudgetView/MyTest.java

36
Budget Projekt/src/MeinBudgetView/Calculations.java

@ -0,0 +1,36 @@
package MeinBudgetView;
import java.util.*;
public class Calculations {
private static int budget;
ArrayList<Integer> all_expenses = new ArrayList<>();
private static int expense;
private static int balance;
public static int getBudget() {
return budget;
}
public static void setBudget(int budgetEingabe) {
budget = budgetEingabe;
}
public static int getExpense() {
return expense;
}
public static void setExpense(int expenseEingabe) {
expense = expenseEingabe;
}
public static int getBalance() {
return balance;
}
public static void setBalance(int balanceEingabe) {
balance = balanceEingabe;
}
}

15
Budget Projekt/src/MeinBudgetView/MeinGui.java

@ -38,9 +38,6 @@ public class MeinGui extends JFrame implements ActionListener {
public static JLabel budgetDispaly;
public static JLabel expensesDisplay;
public static JLabel balanceDisplay;
public static int budget;
public static int expenses;
public static int balance;
private JTextField textExpensesName;
/**
@ -199,15 +196,15 @@ public class MeinGui extends JFrame implements ActionListener {
leerButton();
}
budget = Integer.parseInt(text1.getText());
Calculations.setBudget(Integer.parseInt(text1.getText()));
if (ae.getSource() == this.senden && (text1 != null && text2 != null)) {
budgetDispaly.setText(setBudgetView());
}
if (ae.getSource() == this.berechne && (text1 != null && text2 != null)) {
expenses = budget - Integer.parseInt(text2.getText());
Calculations.setExpense(Calculations.getBudget() - Integer.parseInt(text2.getText()));
expensesDisplay.setText(setExpensesView());
balance = Integer.parseInt(text1.getText()) - Integer.parseInt(text2.getText());
Calculations.setBalance(Integer.parseInt(text1.getText()) - Integer.parseInt(text2.getText())) ;
balanceDisplay.setText(setBalanceView());
}
@ -227,17 +224,17 @@ public class MeinGui extends JFrame implements ActionListener {
public static String setBudgetView() {
String result = budget + " €";
String result = Calculations.getBudget() + " �";
return result;
}
public static String setExpensesView() {
String result = expenses - budget + " €";
String result = Calculations.getExpense() - Calculations.getBudget() + " �";
return result;
}
public static String setBalanceView() {
String result = balance + " €";
String result = Calculations.getBalance() + " �";
return result;
}
}

34
Budget Projekt/src/MeinBudgetView/MyTest.java

@ -8,31 +8,35 @@ class MyTest {
@Test
public void testSetBudgetView() {
assertEquals(MeinGui.budget + " €", MeinGui.setBudgetView());
assertNotEquals(MeinGui.budget + " ", MeinGui.setBudgetView());
assertNotEquals(MeinGui.budget + "€ ", MeinGui.setBudgetView());
assertNotEquals(MeinGui.budget + " € ", MeinGui.setBudgetView());
assertNotEquals(MeinGui.budget + " ", MeinGui.setBudgetView());
assertEquals(Calculations.getBudget() + " �", MeinGui.setBudgetView());
assertNotEquals(Calculations.getBudget() + " ", MeinGui.setBudgetView());
assertNotEquals(Calculations.getBudget() + "� ", MeinGui.setBudgetView());
assertNotEquals(Calculations.getBudget() + " � ", MeinGui.setBudgetView());
assertNotEquals(Calculations.getBudget() + " ", MeinGui.setBudgetView());
}
@Test
public void testSetExpensesView() {
assertEquals(MeinGui.expenses - MeinGui.budget + " €", MeinGui.setExpensesView());
assertNotEquals(MeinGui.expenses - MeinGui.budget, MeinGui.setExpensesView());
assertNotEquals(MeinGui.expenses - MeinGui.budget + "€ " , MeinGui.setExpensesView());
assertNotEquals(MeinGui.expenses - MeinGui.budget + " € " , MeinGui.setExpensesView());
assertNotEquals(MeinGui.expenses - MeinGui.budget + "", MeinGui.setExpensesView());
assertEquals(Calculations.getExpense() - Calculations.getBudget() + " �", MeinGui.setExpensesView());
assertNotEquals(Calculations.getExpense() - Calculations.getBudget(), MeinGui.setExpensesView());
assertNotEquals(Calculations.getExpense() - Calculations.getBudget() + "� " , MeinGui.setExpensesView());
assertNotEquals(Calculations.getExpense() - Calculations.getBudget() + " � " , MeinGui.setExpensesView());
assertNotEquals(Calculations.getExpense() - Calculations.getBudget() + "", MeinGui.setExpensesView());
}
@Test
public void testSetBalanceView() {
assertEquals(MeinGui.balance + " €", MeinGui.setExpensesView());
assertNotEquals(MeinGui.balance, MeinGui.setExpensesView());
assertNotEquals(MeinGui.balance + "€ " , MeinGui.setExpensesView());
assertNotEquals(MeinGui.balance+ " € " , MeinGui.setExpensesView());
assertNotEquals(MeinGui.balance*2 + " € ", MeinGui.setExpensesView());
assertEquals(Calculations.getBalance() + " �", MeinGui.setExpensesView());
assertNotEquals(Calculations.getBalance(), MeinGui.setExpensesView());
assertNotEquals(Calculations.getBalance() + "� " , MeinGui.setExpensesView());
assertNotEquals(Calculations.getBalance()+ " � " , MeinGui.setExpensesView());
assertNotEquals(Calculations.getBalance()*2 + " � ", MeinGui.setExpensesView());
}
@Test
public void add_expanse() {
}

Loading…
Cancel
Save