diff --git a/uil/aplus-february-2015/5/Favorite.MD b/uil/aplus-february-2015/5/Favorite.MD new file mode 100644 index 0000000..0b2b919 --- /dev/null +++ b/uil/aplus-february-2015/5/Favorite.MD @@ -0,0 +1,11 @@ +# Favorite + +Run my solution on **[repl.it](https://repl.it/@Xevion/A-Computer-Science-February-2015-Favorite)!** + +I most definitely complicated this as much as possible, although, the code is still very, very small. + +I simply had two literal string primitive arrays setup with team member names and actor names. Actor or Actress could be varied using a expected prefix of `M` (for *actor*) or `F` (for *actress*). + +When printing, I simply substring'd it away using a ternary operator with two options (`"actor" : "actress"`), and then output it alongside a `.substring(1)` (which starts at index 1 and includes everything including and following it). + +`String.format` comes in handy here when it comes to regulating a more complex set of values quickly, I recommend those who don't use it to get more familiar (it's very, very useful when formatting/rounding floating point numbers off). \ No newline at end of file diff --git a/uil/aplus-february-2015/5/Favorite.java b/uil/aplus-february-2015/5/Favorite.java new file mode 100644 index 0000000..87717d4 --- /dev/null +++ b/uil/aplus-february-2015/5/Favorite.java @@ -0,0 +1,17 @@ +import static java.lang.System.out; + +class Main { + public static void main(String[] args) { + String[] names = new String[]{"John", "Sarah", "Mark"}; + String[] actors = new String[]{"MJohn Wayne", "FMeryl Streep", "MAl Pacino"}; + assert names.length == actors.length : "Team Names array and Actor/Actress names array must be equal in length."; + + for(int i = 0; i < names.length; i++) { + out.println( + String.format("My name is %s, and my favorite movie %s is %s.", + names[i], actors[i].substring(0, 1).equals("M") ? "actor" : "actress", actors[i].substring(1) + ) + ); + } + } +} \ No newline at end of file