From f8457d72e2b8b991c0c779cc2bde4362343cc42b Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Thu, 1 Jul 2021 11:49:43 -0700 Subject: [PATCH 1/2] Fix VariableTypes solution errors - Rename duplicate `decimal` variable - Remove unnecessary `d` in the `number` double - Fix type of `dogsOut` and `name` variables - Suppress unused variable warnings --- .../beginner/chapter2/solutions/VariableTypes.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index 0a3a64e..b578b4d 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -8,6 +8,7 @@ */ public class VariableTypes { + @SuppressWarnings("unused") public static void main(String[] args) { // write your code here @@ -18,16 +19,16 @@ public static void main(String[] args) { float decimal = 23.32544f; // define a double variable on line 21 - double decimal = 23.2352536d; + double number = 23.2352536; // define a boolean variable on line 24 (Hint: true/false) - double dogsOut = true; // the dogs are out :) + boolean dogsOut = true; // the dogs are out :) // define a character variable on line 27 char letter = 'A'; // define a string variable on line 30 - char name = "Jeff"; + String name = "Jeff"; } } From 38cfe255a6d6c03739a62664477cb725cef223bc Mon Sep 17 00:00:00 2001 From: phrdang Date: Thu, 1 Jul 2021 18:53:12 +0000 Subject: [PATCH 2/2] Bot: Prettified Java code! --- .../beginner/chapter1/practice/Comments.java | 23 ++++++++----------- .../chapter1/practice/HelloWorld.java | 11 +++++---- .../beginner/chapter1/solutions/Comments.java | 19 +++++++-------- .../chapter1/solutions/HelloWorld.java | 11 +++++---- .../chapter2/practice/ApplesOranges.java | 14 ++++------- .../chapter2/practice/VariableTypes.java | 18 +++++---------- .../chapter2/solutions/ApplesOranges.java | 15 ++++++------ .../chapter2/solutions/VariableTypes.java | 21 ++++++++--------- .../chapter4/practice/CarDealership.java | 18 +++++---------- .../chapter4/solutions/CarDealership.java | 14 +++++------ 10 files changed, 71 insertions(+), 93 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java b/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java index cebb705..cb032a4 100644 --- a/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java +++ b/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java @@ -3,16 +3,17 @@ /** * @author ArmeetJatyani * March 2021 - * - * You'll be writing your first ever comment today! - * What we'll go over: + * + * You'll be writing your first ever comment today! + * What we'll go over: * - single line comments * - multi line comments */ - // a class is an "object" where we will place all our code inside - public class Comments { - // the main method (below) is the first thing that runs when your program is run +// a class is an "object" where we will place all our code inside +public class Comments { + + // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // this is a single line comment, I can write anything here // single line comments aren't run by Java! @@ -22,17 +23,11 @@ public static void main(String[] args) { * this is a multi * line * comment - * + * * It can span across multiple lines! */ // YOUR ASSIGNMENT: write 1 single-line comment and 1 multi-line comment on the lines below... - - - - - - } - } \ No newline at end of file +} diff --git a/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java index 832742a..4fd1294 100644 --- a/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java +++ b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java @@ -3,17 +3,18 @@ /** * @author ArmeetJatyani * March 2021 - * - * Welcome to Java! + * + * Welcome to Java! * This may be your first ever java program! * We'll begin your journey with the infamous Hello World program! */ - // a class is an "object" where we will place all our code inside - public class HelloWorld { +// a class is an "object" where we will place all our code inside +public class HelloWorld { + // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // write code here (replace the "" with "Hello World!") System.out.println(""); } - } +} diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java index 446b385..faaa644 100644 --- a/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java @@ -3,16 +3,17 @@ /** * @author ArmeetJatyani * March 2021 - * - * You'll be writing your first ever comment today! - * What we'll go over: + * + * You'll be writing your first ever comment today! + * What we'll go over: * - single line comments * - multi line comments */ - // a class is an "object" where we will place all our code inside - public class Comments { - // the main method (below) is the first thing that runs when your program is run +// a class is an "object" where we will place all our code inside +public class Comments { + + // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // this is a single line comment, I can write anything here // single line comments aren't run by Java! @@ -22,7 +23,7 @@ public static void main(String[] args) { * this is a multi * line * comment - * + * * It can span across multiple lines! */ @@ -31,8 +32,8 @@ public static void main(String[] args) { // Hi my name is Armeet! /** - * I like teaching Java, and + * I like teaching Java, and * good luck on your journey! */ } - } \ No newline at end of file +} diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java index a1152d2..e645eff 100644 --- a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java @@ -3,17 +3,18 @@ /** * @author ArmeetJatyani * March 2021 - * - * Welcome to Java! + * + * Welcome to Java! * This may be your first ever java program! * We'll begin your journey with the infamous Hello World program! */ - // a class is an "object" where we will place all our code inside - public class HelloWorld { +// a class is an "object" where we will place all our code inside +public class HelloWorld { + // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // write code here (replace the "" with "Hello World!") System.out.println("Hello World!"); } - } +} diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java index bb28674..5c91b50 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java @@ -3,26 +3,22 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Print out the number of apples and oranges! */ - public class ApplesOranges { +public class ApplesOranges { + public static void main(String[] args) { // write your code here - + // define an integer variable called numOranges with value 10 (line 15) - // define an integer variable called numApples with value 24 (line 18) - // print out number of oranges using variables, output: "I have 10 oranges." (line 21) - // print out number of apples using variables, output: "I have 24 apples." (line 24) - } - } - +} diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java index e5b9678..b0848ac 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java @@ -3,32 +3,26 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Define different types of variables */ - public class VariableTypes { +public class VariableTypes { + public static void main(String[] args) { // write your code here - + // define an integer variable on line 15 - // define a float variable on line 18 - // define a double variable on line 21 - // define a boolean variable on line 24 (Hint: true/false) - // define a character variable on line 27 - - // define a string variable on line 30 - + // define a string variable on line 30 } - } - +} diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java index b35c1e9..e45b29a 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java @@ -3,26 +3,25 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Print out the number of apples and oranges! */ - public class ApplesOranges { +public class ApplesOranges { + public static void main(String[] args) { // write your code here - + // define an integer variable called numOranges with value 10 (line 15) int numOranges = 10; - + // define an integer variable called numApples with value 24 (line 18) int numApples = 24; - + // print out number of oranges using variables, output: "I have 10 oranges." (line 21) System.out.println("I have " + numOranges + " oranges."); // print out number of apples using variables, output: "I have 24 apples." (line 24) System.out.println("I have " + numApples + " apples."); - } - } - +} diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index b578b4d..f9946b0 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -3,33 +3,32 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Define different types of variables */ - public class VariableTypes { - @SuppressWarnings("unused") +public class VariableTypes { + + @SuppressWarnings("unused") public static void main(String[] args) { // write your code here - + // define an integer variable on line 15 int age = 23; - + // define a float variable on line 18 float decimal = 23.32544f; - + // define a double variable on line 21 double number = 23.2352536; // define a boolean variable on line 24 (Hint: true/false) - boolean dogsOut = true; // the dogs are out :) + boolean dogsOut = true; // the dogs are out :) // define a character variable on line 27 char letter = 'A'; - // define a string variable on line 30 + // define a string variable on line 30 String name = "Jeff"; - } - } - +} diff --git a/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java b/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java index df2013f..27c3110 100644 --- a/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java +++ b/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java @@ -3,26 +3,20 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Manage a car dealership and take inventory of all cars sold! */ - public class CarDealership { +public class CarDealership { + public static void main(String[] args) { // write your code here - - // define 3 integer constants, representing the prices of 3 cars sold in USD (line 15-17) - - + // define 3 integer constants, representing the prices of 3 cars sold in USD (line 15-17) // define an integer variable, which represents the sum of the prices of these 3 cars (line 20) - - - // print out the formatted revenue after selling these 3 cars, output: "I sold 3 cars for $XXXXXX." (line 23) - + // print out the formatted revenue after selling these 3 cars, output: "I sold 3 cars for $XXXXXX." (line 23) } - } - \ No newline at end of file +} diff --git a/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java index 10fdd82..98f48fb 100644 --- a/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java +++ b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java @@ -3,14 +3,15 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Manage a car dealership and take inventory of all cars sold! */ - public class CarDealership { +public class CarDealership { + public static void main(String[] args) { // write your code here - + // define 3 integer constants, representing the prices of 3 cars sold in USD (line 15-17) final int car1 = 30000; final int car2 = 24650; @@ -18,11 +19,8 @@ public static void main(String[] args) { // define an integer variable, which represents the sum of the prices of these 3 cars (line 20) int revenue = car1 + car2 + car3; - + // print out the formatted revenue after selling these 3 cars, output: "I sold 3 cars for $XXXXXX." (line 23) System.out.println("I sold 3 cars for $" + revenue + "."); - - } - } - \ No newline at end of file +}