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..8e5be6b 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ Review the flow of execution through the program [Zippo.java](src/Zippo.java), a 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 gets invoked is "rattle" + +// The output of this program is; ik, rattle, ping zoop, boo-wa-ha-ha + --- ## Part 3: Stack Diagram and Program Output @@ -42,7 +46,19 @@ Answer questions about stack diagrams and program output without running the pro * 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? * Paste your output in the bash code-block below. + + Stack diagram; + +Stack Diagram for the First Invocation of ping: +* Main method activation record: Local variables: args (String[]) +* zoop method activation record: No local variables +* baffle method activation record: No local variables +* ping method activation record: No local variables + ```bash +No, I wug. +You wugga wug. +I wug. ``` @@ -57,6 +73,14 @@ Explore method invocations and their consequences. 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;`. +When you invoke a value method and dont do anything with the result, the method will still execute but the return value is thrown out. + +if you used a void method as part of an expression you would get a compilation error like ; + +Error: bad operand types for binary operator '+' +first type: void +second type: int + --- ## Part 5: Stack Diagram and Program Output @@ -70,7 +94,13 @@ Draw a stack diagram that shows the state of the program the second time `zoop` * Regardless of your methodology, a picture of the programs state should be added to this Repo and committed. 2. What is the complete output? * Paste your output in the bash code-block below. + +The stack diagram is the same as mentioned before I believe, no changes to the diagram are needed + ```bash +No, I wug. +You wugga wug. +I wug. ``` diff --git a/src/RedesignDate.java b/src/RedesignDate.java new file mode 100644 index 0000000..c579d96 --- /dev/null +++ b/src/RedesignDate.java @@ -0,0 +1,12 @@ +public class RedesignDate { + public static void main(String[] args) { + printAmerican("Monday", 22, "July", 2019); + printEuropean("Monday", 22, "July", 2019); + } + public static void printAmerican(String day, int date, String month, int year) { + System.out.printf("%s, %s %d, %d\n", day, month, date, year); + } + public static void printEuropean(String day, int date, String month, int year) { + System.out.printf("%s %d %s, %d\n", day, date, month, year); + } +} diff --git a/src/Zippo.java b/src/Zippo.java index 04581a4..0b4d78e 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) { // 3 + 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"); + + public static void zippo(String quince, int flag) { // 4 + if (flag < 0) { // 5 + System.out.println(quince + " zoop"); // 6 } else { - System.out.println("ik"); - baffle(quince); - System.out.println("boo-wa-ha-ha"); + System.out.println("ik"); // 10 + baffle(quince); // 11 + System.out.println("boo-wa-ha-ha"); // 12 } } - public static void main(String[] args) { - zippo("rattle", 13); + public static void main(String[] args) { // 1 + zippo("rattle", 13); // 2 } }