Skip to content

Commit

Permalink
manually revert to mod3 task1 to test out task 12 test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snychka committed May 20, 2020
1 parent ef265e2 commit 9031fc5
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions src/main/java/com/h2/SavingsCalculator.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
package com.h2;

import java.time.LocalDate;
import java.time.YearMonth;

public class SavingsCalculator {
private final float[] credits;
private final float[] debits;

public SavingsCalculator(float[] credits, float[] debits) {
this.credits = credits;
this.debits = debits;
}

public float calculate() {
return sumOfCredits() - sumOfDebits();
}

private float sumOfCredits() {
float sum = 0.0f;
for (float credit : credits) {
sum += credit;
}
return sum;
}

private float sumOfDebits() {
float sum = 0.0f;
for (float debit : debits) {
sum += debit;
}
return sum;
}

private static int remainingDaysInMonth(LocalDate d) {
YearMonth yearMonth = YearMonth.of(d.getYear(), d.getMonth());
int totalDaysInMonth = yearMonth.lengthOfMonth();
return totalDaysInMonth - d.getDayOfMonth();

}

public static void main(String[] args) {


final String[] creditsAsString = args[0].split(",");
final String[] debitsAsString = args[1].split(",");

final float[] credits = new float[creditsAsString.length];
final float[] debits = new float[debitsAsString.length];

for (int i = 0; i < creditsAsString.length; i++) {
credits[i] = Float.parseFloat(creditsAsString[i]);
}

for (int i = 0; i < debitsAsString.length; i++) {
debits[i] = Float.parseFloat(debitsAsString[i]);
}

SavingsCalculator c = new SavingsCalculator(credits, debits);
float netSavings = c.calculate();
System.out.println("Net Savings = " + netSavings + ", remaining days in month = " + remainingDaysInMonth(LocalDate.now()));
}
}

0 comments on commit 9031fc5

Please sign in to comment.