Skip to content
Open

Sub #29

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
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/LikeAGirl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ 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);
Expand All @@ -44,12 +45,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.
}
}