From 32390f76e173d54b037714ba72109debcba18f3a Mon Sep 17 00:00:00 2001 From: Jaime Ortiz Date: Fri, 9 Feb 2024 02:43:53 -0800 Subject: [PATCH 1/2] lab 004 finished --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ README.md | 37 ++++++++++++++++++++++++++++++++----- src/Redesigndate.java | 13 +++++++++++++ src/Zippo.java | 26 +++++++++++++------------- 5 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/Redesigndate.java 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..9e0e471 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ 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? - +* The value of the parameter 'blimp' when 'baffle' is invoked would be "rattle". +* The output of this program is (ik, rattle, ping zoop, boo-wa-ha-ha) --- ## Part 3: Stack Diagram and Program Output @@ -40,13 +41,25 @@ 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. + +* The diagram of the program the first time ping is invoked would go like +* main() + | + --> zoop() + | + --> baffle() + | + --> ping() + 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. ``` ---- +--- ## Part 4: Exploring Method Invocations @@ -55,7 +68,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? +* If you invoke the value method and don't do anything with the result then the code still occurs and runs but whatever result comes of it will be discarded. 2. What happens if you use a void method as part of an expression? For example, try `System.out.println("boo!") + 7;`. +* If you try to use a void method as part of an expression then you will get a compile-time error. This is because the void method doesn't produce a value that can be used in an expression. The command System.out.println("boo!") is a void command so adding a 7 won't do anything until the 7 is inside the parenthesis with the "boo!". --- @@ -68,10 +83,22 @@ Draw a stack diagram that shows the state of the program the second time `zoop` 1. Draw a stack diagram that shows the state of the program the second time `zoop` 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. + +* The output would be main() + | + --> zoop("just for", 5) // first invocation + | + --> clink(4) + | + --> zoop("breakfast ", 4) // second invocation + 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/Redesigndate.java b/src/Redesigndate.java new file mode 100644 index 0000000..99167b4 --- /dev/null +++ b/src/Redesigndate.java @@ -0,0 +1,13 @@ +public class Redesigndate { + public static void main(String[] args) { + printAmerican("February", "Friday", 9, 2024); + + printEuropean("Friday", 9, "February", 2024); + } + public static void printAmerican(String month, String day, int date, int year) { + System.out.println(day + ", " + month + " " + date + ", " + year); + } + public static void printEuropean(String day, int date, String month, int year) { + System.out.println(month + " " + date + ", " + day + ", " + year); + } +} diff --git a/src/Zippo.java b/src/Zippo.java index 04581a4..db8c00a 100644 --- a/src/Zippo.java +++ b/src/Zippo.java @@ -1,19 +1,19 @@ -public class Zippo { - public static void baffle(String blimp) { - System.out.println(blimp); - zippo("ping", -5); +public class Zippo { //1 + public static void baffle(String blimp) { //7 + System.out.println(blimp); //8 + zippo("ping", -5); //9 } - 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) { //3 + if (flag < 0) { //4 + System.out.println(quince + " zoop"); //10 + } else { //5 + System.out.println("ik"); //6 + baffle(quince); //7 + System.out.println("boo-wa-ha-ha"); //11 } } - public static void main(String[] args) { - zippo("rattle", 13); + public static void main(String[] args) { //2 + zippo("rattle", 13); //3 } } From a08269c440a02303954435d31c1926e0637f5f15 Mon Sep 17 00:00:00 2001 From: Jaime Ortiz Date: Fri, 9 Feb 2024 17:25:36 -0800 Subject: [PATCH 2/2] lab 004 finished --- README.md | 3 ++- src/Zippo.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e0e471..5ab6380 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,8 @@ Draw a stack diagram that shows the state of the program the second time `zoop` * 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. -* The output would be main() +* The output would be + main() | --> zoop("just for", 5) // first invocation | diff --git a/src/Zippo.java b/src/Zippo.java index db8c00a..1193460 100644 --- a/src/Zippo.java +++ b/src/Zippo.java @@ -14,6 +14,6 @@ public static void zippo(String quince, int flag) { //3 } public static void main(String[] args) { //2 - zippo("rattle", 13); //3 + zippo("rattle", 13); //2 } }