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..0188623 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,39 @@ Review the flow of execution through the program [Zippo.java](src/Zippo.java), a **Questions to Answer In This README.md:** 1. Write the number 1 next to the first line of code in this program that will execute. 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? +3. What is the value of the parameter `blimp` when `baffle` gets invoked?; + + **"rattle"** 4. What is the output of this program? + **ik** + + **rattle** + + **ping zoop** + + **boo-wa-ha-ha** + + + public class Zippo { + + public static void baffle(String blimp) { + 5 System.out.println(blimp); + 6 zippo("ping", -5); + } + + public static void zippo(String quince, int flag) { + 7 if (flag < 0) { + 8 System.out.println(quince + " zoop"); + 2 } else { + 3 System.out.println("ik"); + 4 baffle(quince); + 9 System.out.println("boo-wa-ha-ha"); + } + } + + 1 public static void main(String[] args) { zippo("rattle", 13); } + } --- ## Part 3: Stack Diagram and Program Output @@ -40,10 +70,12 @@ Answer questions about stack diagrams and program output without running the pro 1. Draw a stack diagram that shows the state of the program the first time `ping` is invoked. * Hint: If you Google how to use IntelliJ's **BreakPoint** functionality, you can screenshot the **program state** instead of drawing it. * Regardless of your methodology, a picture of the programs state should be added to this Repo and committed. -2. What is the output by the following program? +2. What is the output by the following program? * Paste your output in the bash code-block below. ```bash - +No, I wug. +You wugga wug. +I wug. ``` --- @@ -55,8 +87,9 @@ 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? +**Nothing, once the method has run, the returned value will disappear and you might get a warning from the IDE that the returned value was never used.** 2. What happens if you use a void method as part of an expression? For example, try `System.out.println("boo!") + 7;`. - +**You get an error "java: not a statement", because the void method has no value and so cannot be part of an operation.** --- ## Part 5: Stack Diagram and Program Output @@ -71,7 +104,10 @@ 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 +! ``` ## Submission diff --git a/src/Part5_debug.png b/src/Part5_debug.png new file mode 100644 index 0000000..df2d477 Binary files /dev/null and b/src/Part5_debug.png differ diff --git a/src/RedesignDate.java b/src/RedesignDate.java new file mode 100644 index 0000000..91be646 --- /dev/null +++ b/src/RedesignDate.java @@ -0,0 +1,19 @@ +public class RedesignDate { + + public static void printAmerican(String day, String month, int date, int year) { + System.out.printf("%s, %s %dth, %d\n", day, month, date, year); + } + + public static void printEuropean(String day, int date, String month, int year) { + System.out.printf("%s, %dth of %s, %d\n", day, date, month, year); + } + + public static void main(String[] args) { + String day = "Wednesday"; + String month = "February"; + int date = 7; + int year = 2024; + printAmerican(day, month, date, year); + printEuropean(day, date, month, year); + } +} diff --git a/src/Sum.java b/src/Sum.java new file mode 100644 index 0000000..8a4744c --- /dev/null +++ b/src/Sum.java @@ -0,0 +1,11 @@ +public class Sum { + + public static int sum(int x, int y) { + return x+y; + } + + public static void main(String[] args) { + int s = sum(1,2); + System.out.println("s = " + s); + } +} diff --git a/src/Zippo.java b/src/Zippo.java index 04581a4..bd6a3ad 100644 --- a/src/Zippo.java +++ b/src/Zippo.java @@ -15,5 +15,5 @@ public static void zippo(String quince, int flag) { public static void main(String[] args) { zippo("rattle", 13); - } + } //1 } diff --git a/src/Zoop_debug.png b/src/Zoop_debug.png new file mode 100644 index 0000000..f08c4bb Binary files /dev/null and b/src/Zoop_debug.png differ