From 4c83db11a235af268a25d149b5d13c615b9008a2 Mon Sep 17 00:00:00 2001 From: Skyler Date: Wed, 20 Sep 2023 18:09:28 -0700 Subject: [PATCH] Revised code and added lab requirements in README.md --- .idea/misc.xml | 2 +- README.md | 30 ++++++++++++++++++++++++++++++ src/LikeAGirl.java | 15 +++++++++------ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 03f397c..862d09b 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..dd5e51d 100644 --- a/README.md +++ b/README.md @@ -59,15 +59,45 @@ Take note of the various variables and their data types. Write a brief summary i * Its data type * and example values you can assign them. +- String scriptTemplateLine1-5 // Strings of characters which provides templates where strings, digits, newlines, and floats are inserted +- int good/bad // Integers which are expected inputs for user response like 1 and 2 +- float emotionalDamage / double dEmotionalDamage // Used to display floating point numbers like 50.0 +- boolean trueOrFalse // Boolean assigns a true or false statement depending on input + 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 number = "5"; // expected integer returned String +- String = 5; // expected string returned integer + ### 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) +**Some format specifiers described** + +- %b // *Boolean format specifier* +- %s // *String format specifier* +- %f // *Float format specifier* +- %d // *Digit or int format specifier* + +**Listed below is an example snippet of code showcasing these format specifiers** + +```java + class FormatSpecifiers { + public static void main(String[] args) { + boolean x = true; + boolean x1 = false; + double y = 5.0; + int y1 = 5; + String z = "Lorem ipsum dolor sit amet"; + System.out.printf("Booleans can be \"%b\" or \"%b\"\nDoubles have a decimal, like %.1f, while Integers such as %d do not.\nStrings, on the other hand, can be just about any assortment of characters you want, shown here: %s.", x, x1, y, y1, z); + } + } +``` + ### 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..c57d40b 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -1,5 +1,8 @@ import java.util.Scanner; +/** + * @author Trevor Hartman, Skyler Means + */ public class LikeAGirl { /** * "Like a Girl," Super Bowl XLIX (2015) - Like a Girl @@ -15,13 +18,13 @@ 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! + float emotionalDamage = 50.0f; // 32 Bit, but it does exist! // double precision floating point variable double dEmotionalDamage = 100.0; // Double precision // boolean variable @@ -44,12 +47,12 @@ public static void main(String[] args) { System.out.println( String.format(scriptTemplateLine5, answer, - (answer == good) ? + (answer != good) ? String.format(ansGood, dEmotionalDamage) : String.format(ansBad, emotionalDamage) ) ); - 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 False System.out.printf("Did you answer like a nice person? %B%n", trueOrFalse); } }