From 4e289e3fa5a5c7222b110610e606eb3e7e64a850 Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Thu, 1 Jul 2021 13:34:48 -0700 Subject: [PATCH 1/3] Suppress warnings for unused variables --- .../codefortomorrow/beginner/chapter2/examples/Variables.java | 2 +- .../codefortomorrow/beginner/chapter3/practice/FirstHalf.java | 2 +- .../codefortomorrow/beginner/chapter3/practice/WithoutEnd.java | 1 + .../codefortomorrow/beginner/chapter3/solutions/Initialize.java | 1 + .../beginner/chapter9/examples/InitializeArray.java | 1 + .../intermediate/chapter12/examples/WrapperClasses.java | 2 +- .../intermediate/chapter12/practice/Account.java | 1 + 7 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java b/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java index 3adc394..456646f 100644 --- a/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java +++ b/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java @@ -1,7 +1,7 @@ package com.codefortomorrow.beginner.chapter2.examples; public class Variables { - + @SuppressWarnings("unused") public static void main(String[] args) { String name; // declaration name = "Kaz"; // initialization diff --git a/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java b/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java index d14bb3a..c491757 100644 --- a/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java +++ b/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java @@ -13,7 +13,7 @@ */ public class FirstHalf { - + @SuppressWarnings("unused") public static void main(String[] args) { String str1 = "WooHoo"; // should print "Woo" String str2 = "HelloThere"; // should print "Hello" diff --git a/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java b/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java index 936949c..32d1b10 100644 --- a/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java +++ b/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java @@ -14,6 +14,7 @@ */ public class WithoutEnd { + @SuppressWarnings("unused") public static void main(String[] args) { String str1 = "Hello"; // should print "ell" diff --git a/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java b/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java index 6f29242..bd4713d 100644 --- a/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java +++ b/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java @@ -13,6 +13,7 @@ */ public class Initialize { + @SuppressWarnings("unused") public static void main(String[] args) { boolean isRaining = false; diff --git a/src/com/codefortomorrow/beginner/chapter9/examples/InitializeArray.java b/src/com/codefortomorrow/beginner/chapter9/examples/InitializeArray.java index 4ee2d8f..1276147 100644 --- a/src/com/codefortomorrow/beginner/chapter9/examples/InitializeArray.java +++ b/src/com/codefortomorrow/beginner/chapter9/examples/InitializeArray.java @@ -2,6 +2,7 @@ public class InitializeArray { + @SuppressWarnings("unused") public static void main(String[] args) { // declare an array - can be initialized later // with either of the initialization methods below diff --git a/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java b/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java index bf81b9f..488773d 100644 --- a/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java +++ b/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java @@ -1,7 +1,7 @@ package com.codefortomorrow.intermediate.chapter12.examples; public class WrapperClasses { - + @SuppressWarnings("unused") public static void main(String[] args) { // auto-boxing (int to Integer) Integer intObject = 2; diff --git a/src/com/codefortomorrow/intermediate/chapter12/practice/Account.java b/src/com/codefortomorrow/intermediate/chapter12/practice/Account.java index d87f957..4bdfe2b 100644 --- a/src/com/codefortomorrow/intermediate/chapter12/practice/Account.java +++ b/src/com/codefortomorrow/intermediate/chapter12/practice/Account.java @@ -4,6 +4,7 @@ Create a UML diagram for the Account class. */ +@SuppressWarnings("unused") public class Account { private String name; From b8fc77f0d1b97c103f0ecdd922dccc334a76cd18 Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Thu, 1 Jul 2021 13:35:14 -0700 Subject: [PATCH 2/3] Print results of operators usage --- .../beginner/chapter4/examples/Arithmetic.java | 18 ++++++++++++------ .../chapter4/examples/AugmentedAssignment.java | 13 ++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter4/examples/Arithmetic.java b/src/com/codefortomorrow/beginner/chapter4/examples/Arithmetic.java index 4022f62..4ead928 100644 --- a/src/com/codefortomorrow/beginner/chapter4/examples/Arithmetic.java +++ b/src/com/codefortomorrow/beginner/chapter4/examples/Arithmetic.java @@ -4,21 +4,27 @@ public class Arithmetic { public static void main(String[] args) { // addition - int a = 5 + 1; // a has the value 6 + int a = 5 + 1; + System.out.println("a is " + a); // subtraction - double b = 25.6 - 90; // b has the value 64.4 + double b = 25.6 - 90; + System.out.println("b is " + b); // multiplication - int c = 12 * 4; // c has the value 48 + int c = 12 * 4; + System.out.println("c is " + c); // integer division - int d = 10 / 3; // d has the value 3 + int d = 10 / 3; + System.out.println("d is " + d); // double division - double e = 10.0 / 3; // e has the value 3.3333333... + double e = 10.0 / 3; + System.out.println("e is " + e); // modulus - int f = 10 % 3; // f has the value 1 + int f = 10 % 3; + System.out.println("f is " + f); } } diff --git a/src/com/codefortomorrow/beginner/chapter4/examples/AugmentedAssignment.java b/src/com/codefortomorrow/beginner/chapter4/examples/AugmentedAssignment.java index 16e2240..4127067 100644 --- a/src/com/codefortomorrow/beginner/chapter4/examples/AugmentedAssignment.java +++ b/src/com/codefortomorrow/beginner/chapter4/examples/AugmentedAssignment.java @@ -3,12 +3,23 @@ public class AugmentedAssignment { public static void main(String[] args) { - int a = 1; + int a = 10; + System.out.println("1. a is " + a); a += 1; // equivalent to a = a + 1; + System.out.println("2. a is " + a); + a -= 2; // equivalent to a = a - 2; + System.out.println("3. a is " + a); + a *= 3; // equivalent to a = a * 3; + System.out.println("4. a is " + a); + + // NOTE: In this case, we are doing integer division a /= 4; // equivalent to a = a / 4; + System.out.println("5. a is " + a); + a %= 5; // equivalent to a = a % 5; + System.out.println("6. a is " + a); } } From 75fd8d73d760778737975862b5e235d52492fbca Mon Sep 17 00:00:00 2001 From: phrdang Date: Thu, 1 Jul 2021 21:18:22 +0000 Subject: [PATCH 3/3] Bot: Prettified Java code! --- .../codefortomorrow/beginner/chapter2/examples/Variables.java | 1 + .../codefortomorrow/beginner/chapter3/practice/FirstHalf.java | 1 + .../codefortomorrow/beginner/chapter3/practice/WithoutEnd.java | 2 +- .../codefortomorrow/beginner/chapter3/solutions/Initialize.java | 2 +- .../intermediate/chapter12/examples/WrapperClasses.java | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java b/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java index 456646f..dd80723 100644 --- a/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java +++ b/src/com/codefortomorrow/beginner/chapter2/examples/Variables.java @@ -1,6 +1,7 @@ package com.codefortomorrow.beginner.chapter2.examples; public class Variables { + @SuppressWarnings("unused") public static void main(String[] args) { String name; // declaration diff --git a/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java b/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java index c491757..605fcc2 100644 --- a/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java +++ b/src/com/codefortomorrow/beginner/chapter3/practice/FirstHalf.java @@ -13,6 +13,7 @@ */ public class FirstHalf { + @SuppressWarnings("unused") public static void main(String[] args) { String str1 = "WooHoo"; // should print "Woo" diff --git a/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java b/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java index 32d1b10..5854a5c 100644 --- a/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java +++ b/src/com/codefortomorrow/beginner/chapter3/practice/WithoutEnd.java @@ -14,8 +14,8 @@ */ public class WithoutEnd { - @SuppressWarnings("unused") + @SuppressWarnings("unused") public static void main(String[] args) { String str1 = "Hello"; // should print "ell" String str2 = "java"; // should print "av" diff --git a/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java b/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java index bd4713d..9a55660 100644 --- a/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java +++ b/src/com/codefortomorrow/beginner/chapter3/solutions/Initialize.java @@ -13,8 +13,8 @@ */ public class Initialize { - @SuppressWarnings("unused") + @SuppressWarnings("unused") public static void main(String[] args) { boolean isRaining = false; double price = 5.68; diff --git a/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java b/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java index 488773d..d8576c9 100644 --- a/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java +++ b/src/com/codefortomorrow/intermediate/chapter12/examples/WrapperClasses.java @@ -1,6 +1,7 @@ package com.codefortomorrow.intermediate.chapter12.examples; public class WrapperClasses { + @SuppressWarnings("unused") public static void main(String[] args) { // auto-boxing (int to Integer)