Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
63 lines (54 loc) · 2.31 KB

File metadata and controls

63 lines (54 loc) · 2.31 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import com.h2.BestLoanRates;
import com.h2.MortgageCalculator;
import com.h2.SavingsCalculator;
import java.util.Arrays;
import java.util.Map;
public class Finance {
public static final String BEST_LOAN_RATES = "bestLoanRates";
public static final String SAVINGS_CALCULATOR = "savingsCalculator";
public static final String MORTGAGE_CALCULATOR = "mortgageCalculator";
public static final Map<String, String> commandsToUsage = Map.of(
BEST_LOAN_RATES, "usage: bestLoanRates",
SAVINGS_CALCULATOR, "usage: savingsCalculator <credits separated by ','> <debits separated by ','>",
MORTGAGE_CALCULATOR, "usage: mortgageCalculator <loanAmount> <termInYears> <annualRate>"
);
public static void main(String[] args) {
final String command = args[0];
if (!commandsToUsage.containsKey(command)) {
System.out.println(command + ": command not found");
System.exit(-1);
}
final boolean isValidCommand = validateCommandArguments(args);
if (!isValidCommand) {
System.out.println(commandsToUsage.get(args[0]));
System.exit(-1);
}
executeCommand(command, Arrays.copyOfRange(args, 1, args.length));
}
private static void executeCommand(String command, String[] arguments) {
switch (command) {
case BEST_LOAN_RATES:
System.out.println("Finding best loan rates ..."); // for testing just log
BestLoanRates.main(arguments); // for another test call these methods and have executeCommand add to main method
return;
case SAVINGS_CALCULATOR:
System.out.println("Finding your net savings ...");
SavingsCalculator.main(arguments);
return;
case MORTGAGE_CALCULATOR:
System.out.println("Finding your monthly payment ...");
MortgageCalculator.main(arguments);
}
}
private static boolean validateCommandArguments(String[] args) {
switch (args[0]) {
case BEST_LOAN_RATES:
return args.length == 1;
case SAVINGS_CALCULATOR:
return args.length == 3;
case MORTGAGE_CALCULATOR:
return args.length == 4;
}
return false;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.