Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ Did you answer like a nice person? FALSE

### Part 2 - Interpretation
Take note of the various variables and their data types. Write a brief summary in this section of the README.md file listing the:
* Variable name
* Its data type
* and example values you can assign them.
* Variable name: ***String***
* Its data type: ***Non-Primitive***
* and example values you can assign them.: ***stores strings of characters such as this text here surrounded by quotations like "Hello World"***

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!
1. int ***good = 1.789*** is wrong because this is a double floating point due to the decimal int uses whole numbers
2. boolean ***oneOrTwoOrThree*** is wrong because boolean is either on or off using two states only such as trueOrFalse or onOrOff

### Part 3 - Bonus: Play around with Java String Format Specifiers.

Expand Down
33 changes: 21 additions & 12 deletions src/LikeAGirl.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
*
* @author Trevor Hartman
* @author Cassandra Portlock
*
* @since Version 1.0
*
*/

import java.util.Scanner;

public class LikeAGirl {
Expand All @@ -13,15 +22,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 ansGood = "Good for you.%nEmotional Damage %f";
String ansBad = "Always wants to change that.%nEmotional Damage %f";
String likeABoy = "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
Expand All @@ -30,26 +39,26 @@ public static void main(String[] args) {
Scanner s = new Scanner(System.in);

System.out.println(
String.format(scriptTemplateLine1, likeAGirl));
String.format(scriptTemplateLine1, likeABoy));

// 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) : 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);
}
}