From ef483ec04a7bb955bb406a30310984d12cc63c9c Mon Sep 17 00:00:00 2001 From: GinaD14 Date: Wed, 20 Sep 2023 13:11:46 -0700 Subject: [PATCH 1/2] Angelina Danna Lab 2 --- README.md | 9 +++++++-- src/LikeAGirl.java | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b866789..37e2aaa 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,15 @@ 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. + +* A variable is a named location that stores + a value. Values may be numbers, text, images, sounds, and other types of + data. Some variable examples are like int and char. These are called primitive data. Int could be int x; +char can be different characters. -Next give TWO example variable names and TWO example variable assignments that are **WRONG** and explain why. +* 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! - +Two variable names could be public or class. a type of variabe assignment that wouldnt work would be 123 instead of "123"; ### 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. diff --git a/src/LikeAGirl.java b/src/LikeAGirl.java index 30b943b..66d4f42 100644 --- a/src/LikeAGirl.java +++ b/src/LikeAGirl.java @@ -13,15 +13,15 @@ public static void main(String[] args) { 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 ansBad = "Always wants to change that.%nEmotional Damage %f"; + String ansGood = "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 @@ -45,11 +45,11 @@ public static void main(String[] args) { System.out.println( String.format(scriptTemplateLine5, answer, (answer == good) ? - String.format(ansGood, dEmotionalDamage) : String.format(ansBad, emotionalDamage) + String.format(ansGood, emotionalDamage) : 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); } } From 9e11e030a3361fd786aaae1abe43578942cd389c Mon Sep 17 00:00:00 2001 From: GinaD14 Date: Wed, 20 Sep 2023 13:16:47 -0700 Subject: [PATCH 2/2] Angelina Danna Lab 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37e2aaa..a90e55c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The lab template contains a program that prints the following if you choose "0": What does it mean to do something, "Like a Girl"? Show me what it looks like to run, "Like a Girl." Show me what it looks like to fight, "Like a Girl." -How do you think it affects them when somebody uses "Like a Girl" as an insult? Choice (good: 0, bad: 1) 0 +How do you think it affects them when somebody uses "Like a Girl" as an insult? Choice (good: 0, bad: 1) 0 You answered 0 Always wants to change that. Emotional Damage 100.000000.