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
58 lines (54 loc) · 2.22 KB

File metadata and controls

58 lines (54 loc) · 2.22 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
import com.h2.BestLoanRates;
import com.h2.MortgageCalculator;
import com.h2.SavingsCalculator;
import java.util.Arrays;
import java.util.Map;
import static java.util.Arrays.copyOfRange;
public class Finance {
public final static String BEST_LOAN_RATES = "bestLoanRates";
public final static String SAVINGS_CALCULATOR = "savingsCalculator";
public final static 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;
}
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.