Skip to content

Commit

Permalink
Działa jak należy.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoph4822 committed Sep 8, 2020
1 parent d38b187 commit fa31357
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/DebtCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ private void resolveDebt1(){ //zależnie która kwota jest najmniejsza wybieramy

// wyrównujemy najgorszego
if(first.getBalance() > lastAbsBalance) {
debts.add(new Debt(first.getName(), last.getName(), lastAbsBalance));
first.addToBalance(-lastAbsBalance);
if(lastAbsBalance != 0){
debts.add(new Debt(first.getName(), last.getName(), lastAbsBalance));
first.addToBalance(-lastAbsBalance);
}
persons.remove(last);
}

//wyrównujemy najlepszego
else {
debts.add(new Debt(first.getName(), last.getName(), first.getBalance()));
last.addToBalance(first.getBalance());
if(first.getBalance() != 0){
debts.add(new Debt(first.getName(), last.getName(), first.getBalance()));
last.addToBalance(first.getBalance());
}
persons.remove(first);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="11" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="539" height="442"/>
<xy x="20" y="20" width="570" height="442"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -67,7 +67,7 @@
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Ratio (0-1)"/>
<text value="Ratio*"/>
</properties>
</component>
<scrollpane id="79aef">
Expand Down
18 changes: 11 additions & 7 deletions src/gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.ArrayList;

public class gui {
ArrayList<Person> persons = new ArrayList<>();
private ArrayList<Person> persons = new ArrayList<>();
public JPanel mainPanel;
private JTextField nameTextField;
private JTextField expenseTextField;
Expand All @@ -20,17 +20,21 @@ public gui() {
addPersonButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
persons.add(new Person(nameTextField.getText(), Double.parseDouble(expenseTextField.getText()), Double.parseDouble(ratioTextField.getText())));
personsTextArea.append(persons.get(persons.size() - 1) + "\n");
nameTextField.setText("");
expenseTextField.setText("");
ratioTextField.setText("");
if(nameTextField.getText().length()!=0 && expenseTextField.getText().length()!=0){
double ratio = ratioTextField.getText().length()!= 0 ? Double.parseDouble(ratioTextField.getText()) : 1;
persons.add(new Person(nameTextField.getText(), Double.parseDouble(expenseTextField.getText()), ratio));
personsTextArea.append(persons.get(persons.size() - 1) + "\n");
nameTextField.setText("");
expenseTextField.setText("");
ratioTextField.setText("");
}
}
});
resolveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DebtCalculator dc = new DebtCalculator(persons);
debtsTextArea.setText("");
DebtCalculator dc = new DebtCalculator((ArrayList<Person>) persons.clone());
if(simplifyDebtsRadioButton.isSelected())
dc.resolveDebt(1);
else
Expand Down

0 comments on commit fa31357

Please sign in to comment.