forked from DaivsP/Maven.Casino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leon Hunter
authored and
Leon Hunter
committed
Feb 21, 2019
1 parent
760ceda
commit 3ce85a1
Showing
3 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.zipcoder.casino.utilities; | ||
|
||
|
||
import java.io.InputStream; | ||
import java.io.PrintStream; | ||
import java.util.Scanner; | ||
|
||
/** | ||
* You are advised against modifying this class. | ||
*/ | ||
public final class Console { | ||
private final Scanner input; | ||
private final PrintStream output; | ||
|
||
public Console(InputStream in, PrintStream out) { | ||
this.input = new Scanner(in); | ||
this.output = out; | ||
} | ||
|
||
public void print(String val, Object... args) { | ||
output.format(val, args); | ||
} | ||
|
||
public void println(String val, Object... vals) { | ||
print(val + "\n", vals); | ||
} | ||
|
||
public String getStringInput(String prompt, Object... args) { | ||
println(prompt, args); | ||
return input.nextLine(); | ||
} | ||
|
||
public Double getDoubleInput(String prompt, Object... args) { | ||
String stringInput = getStringInput(prompt, args); | ||
try { | ||
Double doubleInput = Double.parseDouble(stringInput); | ||
return doubleInput; | ||
} catch (NumberFormatException nfe) { // TODO - Eliminate recursive nature | ||
println("[ %s ] is an invalid user input!", stringInput); | ||
println("Try inputting a numeric value!"); | ||
return getDoubleInput(prompt, args); | ||
} | ||
} | ||
|
||
public Long getLongInput(String prompt, Object... args) { | ||
String stringInput = getStringInput(prompt, args); | ||
try { | ||
Long longInput = Long.parseLong(stringInput); | ||
return longInput; | ||
} catch (NumberFormatException nfe) { // TODO - Eliminate recursive nature | ||
println("[ %s ] is an invalid user input!", stringInput); | ||
println("Try inputting an integer value!"); | ||
return getLongInput(prompt, args); | ||
} | ||
} | ||
|
||
public Integer getIntegerInput(String prompt, Object... args) { | ||
return getLongInput(prompt, args).intValue(); | ||
} | ||
} | ||
|