diff --git a/.idea/misc.xml b/.idea/misc.xml index cf9abe6..cbbff6a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 40c2bd8..766a53c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Review the flow of execution through the program [Zippo.java](src/Zippo.java), a 2. Write the number 2 next to the second line of code, and so on until the end of the program. 3. What is the value of the parameter `blimp` when `baffle` gets invoked? 4. What is the output of this program? - + Answer - ik, rattle, ping zoop, boo-wa-ha-ha --- ## Part 3: Stack Diagram and Program Output @@ -43,7 +43,7 @@ Answer questions about stack diagrams and program output without running the pro 2. What is the output by the following program? * Paste your output in the bash code-block below. ```bash - +// refer to the attached pic 'Readme pt 3' ``` --- @@ -55,7 +55,10 @@ Explore method invocations and their consequences. **Questions to answer in the README.md via Markdown:** 1. What happens if you invoke a value method and don’t do anything with the result; that is, if you don’t assign it to a variable or use it as part of a larger expression? -2. What happens if you use a void method as part of an expression? For example, try `System.out.println("boo!") + 7;`. +// P. 60 makes mention of value methods, but not of consequences for not using the result. Google Bard/Gemini says the General Behavior has 3 possible outcomes; 1- Discarding the Value - the method executes but the value isn't stored and becomes lost. 2- No impact on the program's core logic. 3- Potential Performance implications, that could be negligible for simple programs or could be relevant for heavy processing work. +2. What happens if you use a void method as part of an expression? For example, try `System.out.println("boo!") + 7;`. +// When I tried to compile this on a scratch paper class, I received the result "Operator '+' cannot be applied to 'void', 'int'" + --- @@ -71,6 +74,12 @@ Draw a stack diagram that shows the state of the program the second time `zoop` 2. What is the complete output? * Paste your output in the bash code-block below. ```bash +just for +any not more +It's breakfast +! + +Process finished with exit code 0 ``` diff --git a/src/Readme pt 3.png b/src/Readme pt 3.png new file mode 100644 index 0000000..af795c5 Binary files /dev/null and b/src/Readme pt 3.png differ diff --git a/src/Readme pt 5.png b/src/Readme pt 5.png new file mode 100644 index 0000000..91bd61d Binary files /dev/null and b/src/Readme pt 5.png differ diff --git a/src/RedesignDate.java b/src/RedesignDate.java new file mode 100644 index 0000000..d4eeef0 --- /dev/null +++ b/src/RedesignDate.java @@ -0,0 +1,28 @@ +import java.util.Scanner; +public class RedesignDate { + static void printAmerican() { + String day = "Thursday, "; + String month = "February "; + String date = "8 "; + String year = "2024 "; + System.out.println(day + month + date + year); + } + static void printEuropean() { + String day = "Thursday "; + String month = "February "; + String date = "8 "; + String year = "2024 "; + System.out.println(day + date + month + year); + } + + public static void main(String[] args) { + + System.out.println("Enter 1 for American date format or 2 for European format"); + Scanner in = new Scanner(System.in); + int choice = in.nextInt(); + if (choice == 1) { + printAmerican(); + } else { + printEuropean(); + } + }} \ No newline at end of file diff --git a/src/Zippo.java b/src/Zippo.java index 04581a4..26bedeb 100644 --- a/src/Zippo.java +++ b/src/Zippo.java @@ -1,19 +1,20 @@ public class Zippo { - public static void baffle(String blimp) { - System.out.println(blimp); - zippo("ping", -5); + public static void baffle(String blimp) { // 6 + System.out.println(blimp); // 7 + zippo("ping", -5); // 8 } - public static void zippo(String quince, int flag) { - if (flag < 0) { - System.out.println(quince + " zoop"); - } else { - System.out.println("ik"); - baffle(quince); - System.out.println("boo-wa-ha-ha"); + public static void zippo(String quince, int flag) { // 2 + if (flag < 0) { // 9 + System.out.println(quince + " zoop"); // 10 + } else { // 3 + System.out.println("ik"); // 4 + baffle(quince); // 5 + System.out.println("boo-wa-ha-ha"); // 11 } } public static void main(String[] args) { zippo("rattle", 13); - } + } // 1, starts with main. } +// ik, rattle, ping zoop, boo-wa-ha-ha \ No newline at end of file