From 8ca517e597cf929e743925aa45eb6b459f1ee8db Mon Sep 17 00:00:00 2001 From: 2sage4thyme <2sage4thyme@gmail.com> Date: Wed, 20 Sep 2023 13:57:50 -0700 Subject: [PATCH 1/2] Completed Lab 002 --- .idea/misc.xml | 1 - README.md | 6 +++++- src/LikeAGirl.java | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 03f397c..ca950ab 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/README.md b/README.md index b866789..1321fe8 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,15 @@ Take note of the various variables and their data types. Write a brief summary i 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! +* There are many variable types, including String, int, float, double, boolean, and Scanner. The String variables are often called stringTemplateLine1-5, and because they are strings, they are assigned a string of characters whereas the integers are assigned integers and the floats and doubles are assigned numbers with decimal points. +* Wrong variable names: Wrong variable assignments: + ### 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) +![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 diff --git a/src/LikeAGirl.java b/src/LikeAGirl.java index 30b943b..f1ca325 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -15,16 +15,16 @@ public static void main(String[] args) { 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 likeAGirl = "Like a Boy"; // 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! - // double precision floating point variable - double dEmotionalDamage = 100.0; // Double precision + double dEmotionalDamage = 50.0; // Double precision // boolean variable + float emotionalDamage = 100.0f; // 32 Bit, but it does exist! + // double precision floating point variable boolean trueOrFalse; // Scanner variable for reading input. Scanner s = new Scanner(System.in); @@ -44,12 +44,15 @@ public static void main(String[] args) { System.out.println( String.format(scriptTemplateLine5, answer, - (answer == good) ? - String.format(ansGood, dEmotionalDamage) : String.format(ansBad, emotionalDamage) + (answer != good) ? + String.format(ansGood, emotionalDamage) : String.format(ansBad, dEmotionalDamage) ) ); - trueOrFalse = (answer != good); // if answer == 1 (i.e. good), then trueOrFalse should be False + trueOrFalse = (answer == good); // if answer == 1 (i.e. good), then trueOrFalse should be True System.out.printf("Did you answer like a nice person? %B%n", trueOrFalse); + //LikeAGirl text was altered to LikeABoy text. Answer option 0 became answer option 1, and answer option 1 + //became answer option 2. emotionalDamage became 100.0 from 0 and dEmotionalDamage became 50.0 from 100.0. + // != and == were swapped to create answer option 1 to produce a True response, and answer option 2 creates a False response. } } From f0a720f249830c893c80809f13ae5b3db207ea3d Mon Sep 17 00:00:00 2001 From: 2sage4thyme <2sage4thyme@gmail.com> Date: Wed, 20 Sep 2023 14:18:17 -0700 Subject: [PATCH 2/2] Completed Lab 002 --- src/LikeAGirl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LikeAGirl.java b/src/LikeAGirl.java index f1ca325..89912b5 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -17,6 +17,7 @@ public static void main(String[] args) { String ansBad = "Good for you.%nEmotional Damage %f"; String likeAGirl = "Like a Boy"; + // integer variable int good = 1; int bad = 2;