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
65 lines (54 loc) · 1.87 KB

File metadata and controls

65 lines (54 loc) · 1.87 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
64
65
import java.util.Arrays;
import java.util.Map;
import com.h2.BestLoanRates;
import com.h2.MortgageCalculator;
import com.h2.SavingsCalculator;
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 final static 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>");
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;
default:
return false;
}
}
private static void executeCommand(String command, String[] arguments) {
switch(command) {
case BEST_LOAN_RATES:
System.out.println("Finding best loan rates ...");
BestLoanRates.main(arguments);
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);
return;
}
}
public static void main(String[] args) {
String command = args[0];
if(!commandsToUsage.containsKey(command)) {
System.out.println(command + ": command not found");
return;
}
boolean isValidCommand = validateCommandArguments(args);
if(!isValidCommand) {
System.out.println(commandsToUsage.get(args[0]));
return;
}
executeCommand(command, Arrays.copyOfRange(args, 1, args.length));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.