From ff641ca063789409e963e698a5676e99e79784fe Mon Sep 17 00:00:00 2001 From: Daniel Faulkner Date: Sat, 2 Sep 2023 23:32:45 -0700 Subject: [PATCH] finished lab 2 --- .idea/misc.xml | 1 - README.md | 10 ++++++++++ src/LikeAGirl.java | 15 ++++++++------- 3 files changed, 18 insertions(+), 8 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..71d7f39 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,19 @@ 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. +### Answer for Part 2 +* String is a declaration. ex: String message; +* int is an integer. ex int x = 123 +* float is a floating point. ex float exampleOne = 100.0f +* double is a double precision data type. ex double a = 100 +* boolean is a primitive data type. ex boolean trueOrFalse; + + 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 A = yes; this is wrong because the assignment for int is using letters instead of numbers. +* boolean = TrueOrFalse; this is wrong because the first letter of the assignment must not be capitalized. ### Part 3 - Bonus: Play around with Java String Format Specifiers. diff --git a/src/LikeAGirl.java b/src/LikeAGirl.java index 30b943b..397ecb3 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -14,14 +14,14 @@ public static void main(String[] args) { "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 ansBad = "Good for you..%nEmotional Damage %f"; + 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 +44,13 @@ public static void main(String[] args) { System.out.println( String.format(scriptTemplateLine5, answer, - (answer == good) ? + (answer == bad) ? String.format(ansGood, dEmotionalDamage) : String.format(ansBad, emotionalDamage) ) ); - 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); + } }