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
78 changes: 59 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,52 @@
Be able to explain what variables are. Understand variable types, allowed names, and valid values.
Know how to create and use string, integer, floating-point, and boolean variables.

### Part 1 - PricelessScript.java - [MasterCard YouTube Ad](https://www.youtube.com/watch?v=Q_6stXKGuHo)
### Part 1 - LikeAGirl.java - [Like a Girl](https://www.youtube.com/watch?v=5yLXrWLvwAo)

The lab template contains a program that prints the following:
The lab template contains a program that prints the following if you choose "0":
```
2 tickets: $28.00
2 hotdogs, 2 popcorn, 2 sodas: $18.00
1 autographed baseball $45.00
real conversation with 11 year old son: priceless
true
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
You answered 0
Always wants to change that.
Emotional Damage 100.000000.
Did you answer like a nice person? FALSE
```
... OR the following if you choose "1":
```
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) 1
You answered 1
Good for you.
Emotional Damage 0.000000.
Did you answer like a nice person? TRUE
```

Ignore the code that you don't fully recognize and concentrate on changing the variables to alter the MasterCard *Priceless* script to say:
Ignore the code that you don't fully recognize and concentrate on changing the variables to alter the script to say the following if 1 is chosen:
```
What does it mean to do something, "Like a Boy"?
Show me what it looks like to run, "Like a Boy."
Show me what it looks like to fight, "Like a Boy."
How do you think it affects them when somebody uses "Like a Boy" as an insult? Choice (good: 1, bad: 2) 1
You answered 1
Good for you.
Emotional Damage 50.000000.
Did you answer like a nice person? TRUE
```
3 tickets: $42.00
3 hotdogs, 3 popcorn, 3 sodas: $27.00
2 autographed baseball $90.00
watching the Giants win: priceless
false
OR to say the following if 2 is chosen:
```
What does it mean to do something, "Like a Boy"?
Show me what it looks like to run, "Like a Boy."
Show me what it looks like to fight, "Like a Boy."
How do you think it affects them when somebody uses "Like a Boy" as an insult? Choice (good: 1, bad: 2) 2
You answered 2
Always wants to change that.
Emotional Damage 100.000000.
Did you answer like a nice person? FALSE
```

### Part 2 - Interpretation
Expand All @@ -31,18 +59,30 @@ 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.

Next give TWO example variable names and TWO example variable assignments that are *WRONG* and explain why.
* Hint: your IDE can help you discover these!
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!

### 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.
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)

### Part 4 - Submission
* Just as you did last week (Reference the Lab video in your Week 1 module), create a Spring2023 feature branch of your code
* 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
* Push it to your Remote/origin branch (i.e. GitHub: Spring2023 -> origin/Spring2023)
* Push it to your Remote/origin branch (i.e. GitHub: Feature1 -> origin/Feature1)
* Then issue a Pull request to my instructor branch
* Make sure to save the Pull request URL and submit it for the lab.
* Make sure to **COPY** the Pull request URL and submit it for the lab/assignment.


### Answers to part 2
* Some Variables I noticed were float, double, and boolean.
* The data type for double is a 64-bit floating point.
* The data type for float is a 32-bit floating point.
* I'm not sure what boolean was but after looking into it, it's a data type that returns two values.
* Double can be assigned to pretty much any integer in a 64 bit processor
* Float can be assigned to any integer in a 32-bit processor
* Boolean can return either "true" or "false"
* An example of a wrong variable would be- double = "50.0". This is wrong because the integer has apostrophes around it.
* Another example would be- boolean = trueorfalse. This is incorrect because of the improper use of lowercase letters.
55 changes: 55 additions & 0 deletions src/LikeAGirl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.util.Scanner;

public class LikeAGirl {
/**
* "Like a Girl," Super Bowl XLIX (2015) - <a href="https://www.youtube.com/watch?v=5yLXrWLvwAo">Like a Girl</a>
* @param args Command line arguments [The source file path, The target file path, ...]
**/
public static void main(String[] args) {
// String variables, some with format specifiers
String scriptTemplateLine1 = "What does it mean to do something, \"%s\"?";
String scriptTemplateLine2 = "Show me what it looks like to run, \"%s.\"%n";
String scriptTemplateLine3 = "Show me what it looks like to fight, \"%s.\"";
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 likeABoy = "Like a boy";

// integer variable
int good = 2;
int bad = 1;
// 32 bit floating point variable
float emotionalDamage = 50.0f; // 32 Bit, but it does exist!
// double precision floating point variable
double dEmotionalDamage = 100.0; // Double precision
// boolean variable
boolean trueOrFalse;
// Scanner variable for reading input.
Scanner s = new Scanner(System.in);

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

// Example of using printf and platform specific line separator "%n" to
// format instead of String.format
System.out.printf(scriptTemplateLine2, likeABoy);

System.out.println(String.format(scriptTemplateLine3, likeABoy));

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)
)
);

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);
}
}
45 changes: 0 additions & 45 deletions src/PricelessScript.java

This file was deleted.