diff --git a/.idea/misc.xml b/.idea/misc.xml index 03f397c..0548357 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index b866789..d1525e2 100644 --- a/README.md +++ b/README.md @@ -58,16 +58,23 @@ Take note of the various variables and their data types. Write a brief summary i * Variable name * Its data type * and example values you can assign them. - +* "scriptTemplateLine1" - string - "abc" +* "good" - int - "123" +* "emotionalDamage" - float - "decimals and negatives, 32 bit size" +* "dEmotionalDamage" - double - "decimals and negatives like float, but 64 bit size" +* "trueOrFalse" - boolean - "1 or 0, true or false" +* "s" - scanner - "System.in" Next give TWO example variable names and TWO example variable assignments that are **WRONG** and explain why. * Hint: your IDE can help you discover wrong assignments or variable names! - +int Main = "Hello" (You can't name a variable the same as the class name and you can't assign a string to an int) +string float = "12" + "3" (Can't use keywords for variable names and this math won't work like you want, this will concatonate and give you "123" not add those two numbers) ### Part 3 - Bonus: Play around with Java String Format Specifiers. Pick several of the Java format specifiers below and define variables of the correct type utilize **sout** and **String.format** to view the resulting formats. ![Format Specifiers](JavaStringFormatSpecifiers.png) + ### Part 4 - Submission * Just as you did last week (Reference the Lab video in your Week 1 module), create a Feature1 branch of your code * Commit your working code to your local copy diff --git a/src/LikeAGirl.java b/src/LikeAGirl.java index 30b943b..d5b25dd 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -7,21 +7,24 @@ public class LikeAGirl { **/ public static void main(String[] args) { // String variables, some with format specifiers - String scriptTemplateLine1 = "What does it mean to do something, \"%s\"?"; + String scriptTemplateLine1 = "What does it mean to do something, \"%s\"%s?"; String scriptTemplateLine2 = "Show me what it looks like to run, \"%s.\"%n"; String scriptTemplateLine3 = "Show me what it looks like to fight, \"%s.\""; String scriptTemplateLine4 = "How do you think it affects them when somebody uses \"%s\" as an insult? Choice (good: %d, bad: %d) "; String scriptTemplateLine5 = "You answered %d%n%s."; - String ansGood = "Always wants to change that.%nEmotional Damage %f"; - String ansBad = "Good for you.%nEmotional Damage %f"; - String likeAGirl = "Like a Girl"; + String ansGood = "Good for you.%nEmotional Damage %f%c"; + String ansBad = "Always wants to change that.%nEmotional Damage %f"; + String likeABoy = "Like a boy"; + String question = "?"; //experimenting with format specifiers + char heart = '\u2665'; //experimenting with format specifiers + // integer variable - int good = 0; - int bad = 1; + int good = 1; + int bad = 2; // 32 bit floating point variable - float emotionalDamage = 0.0f; // 32 Bit, but it does exist! + float emotionalDamage = 50.0f; // 32 Bit, but it does exist! // double precision floating point variable double dEmotionalDamage = 100.0; // Double precision // boolean variable @@ -30,26 +33,26 @@ public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println( - String.format(scriptTemplateLine1, likeAGirl)); + String.format(scriptTemplateLine1, likeABoy, question)); // Example of using printf and platform specific line separator "%n" to // format instead of String.format - System.out.printf(scriptTemplateLine2, likeAGirl); + System.out.printf(scriptTemplateLine2, likeABoy); - System.out.println(String.format(scriptTemplateLine3, likeAGirl)); + System.out.println(String.format(scriptTemplateLine3, likeABoy)); - System.out.printf(scriptTemplateLine4, likeAGirl, good, bad); + System.out.printf(scriptTemplateLine4, likeABoy, good, bad); int answer = Integer.parseInt(s.nextLine()); System.out.println( String.format(scriptTemplateLine5, answer, (answer == good) ? - String.format(ansGood, dEmotionalDamage) : String.format(ansBad, emotionalDamage) + String.format(ansGood, emotionalDamage, heart) : String.format(ansBad, dEmotionalDamage) ) ); - trueOrFalse = (answer != good); // if answer == 1 (i.e. good), then trueOrFalse should be False + trueOrFalse = (answer != bad); // if answer == 1 (i.e. good), then trueOrFalse should be False System.out.printf("Did you answer like a nice person? %B%n", trueOrFalse); } }