From 2a168b3bfd5e2230b2bb67ca54889cb528639f37 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Wed, 18 Apr 2018 01:56:33 -0800 Subject: [PATCH 01/10] added comment --- ch02/Variables.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ch02/Variables.java b/ch02/Variables.java index a295abf..d238665 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -1,10 +1,12 @@ /** * Examples from Chapter 2. */ -public class Variables { - - public static void main(String[] args) { +public class Variables +{ + public static void main(String[] args) + { + //Stephanie String message; int x; @@ -59,7 +61,7 @@ public static void main(String[] args) { System.out.println(0.1 * 10); System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 - + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); + + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); double balance = 123.45; // potential rounding error int balance2 = 12345; // total number of cents From 96693e41f4779beed179e7da3fc7f064d1625746 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Wed, 18 Apr 2018 04:37:12 -0800 Subject: [PATCH 02/10] added comment --- ch02/Assigningvalues.java | 19 +++++++++++++++++++ ch02/Constants.java | 19 +++++++++++++++++++ ch02/DataTypes.java | 20 ++++++++++++++++++++ ch02/Date.java | 9 +++++++++ ch02/Doingarithmetic.java | 19 +++++++++++++++++++ ch02/FirstVariable.java | 14 ++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 ch02/Assigningvalues.java create mode 100644 ch02/Constants.java create mode 100644 ch02/DataTypes.java create mode 100644 ch02/Date.java create mode 100644 ch02/Doingarithmetic.java create mode 100644 ch02/FirstVariable.java diff --git a/ch02/Assigningvalues.java b/ch02/Assigningvalues.java new file mode 100644 index 0000000..fd76413 --- /dev/null +++ b/ch02/Assigningvalues.java @@ -0,0 +1,19 @@ +package PACKAGE_NAME; + +public class Assigningvalues +{ + public static void main(String[] args) + { + String txt = "Fantastic"; + String lang = "Java"; + txt += lang; // Assign concatenated String + System.out.println("Add & Assign Strings;" + txt); + int sum = 10; + int num = 20; + sum += num ; // Assign result ( 10 + 20 = 30 ) + System.out.println( "Add & Assign Integers: " + sum ) ; + int factor = 5 ; + sum *= factor ; // Assign result ( 30 x 5 = 150 ) + System.out.println( "Multiplication sum: " + sum ) ; + } +} diff --git a/ch02/Constants.java b/ch02/Constants.java new file mode 100644 index 0000000..7153d65 --- /dev/null +++ b/ch02/Constants.java @@ -0,0 +1,19 @@ +public class Constants + +{ + public static void main ( String[] args ) + { + final int TOUCHDOWN = 6; + final int CONVERSION = 1; + final int FIELDGOAL = 1; + + + int td, pat, fg, total; + td = 4 * TOUCHDOWN; + pat = 3 * CONVERSION; + fg = 2 * FIELDGOAL; + total = (td + pat + fg); + System.out.println("Score: " + total ); + + } +} diff --git a/ch02/DataTypes.java b/ch02/DataTypes.java new file mode 100644 index 0000000..b1470eb --- /dev/null +++ b/ch02/DataTypes.java @@ -0,0 +1,20 @@ +public class DataTypes +{ + public static void main(String[] args) + { + + char letter = 'M'; + String title = "Java in easy steps "; + int number = 365; + float decimal = 98.6f; + boolean result = true; + System.out.println("Initial is " + letter ); + System.out.println("Book is " +title ); + System.out.println("Days are " + number ); + System.out.println("Temperature is " + decimal ); + System.out.println("Answer is " + result ); + + + + } +} diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..f99c54a --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,9 @@ +public class Date +{ + public static void main(String[] args) + { // gnerate some simple output + System.out.println("hello "); + int num = 13 + + } +} \ No newline at end of file diff --git a/ch02/Doingarithmetic.java b/ch02/Doingarithmetic.java new file mode 100644 index 0000000..236d49f --- /dev/null +++ b/ch02/Doingarithmetic.java @@ -0,0 +1,19 @@ +public class Doingarithmetic +{ + public static void main(String[] args) + { + int num = 100; + int factor = 20; + int sum = 0; + sum = num + factor; // 100 + 20 + System.out.println("Addition sum: " + sum); + sum = num - factor; // 100 - 20 + System.out.println("Subtrsction sum: " + sum); + sum = num * factor ; // 100 x 20 + System.out.println( "Multiplication sum: " + sum ) ; + sum = num / factor ; // 100 / 20 + System.out.println( "Division sum:" + sum ) ; + + + } +} diff --git a/ch02/FirstVariable.java b/ch02/FirstVariable.java new file mode 100644 index 0000000..1bc2f05 --- /dev/null +++ b/ch02/FirstVariable.java @@ -0,0 +1,14 @@ +public class FirstVariable +{ + public static void main(String []args ) + { + String message = "Initial value"; + System.out.println (message); + + message = "Modified value"; + System.out.println (message); + + } + + +} From ff33c241bc5b18f16764bf33edabdf23b2a20a15 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Thu, 19 Apr 2018 23:30:58 -0800 Subject: [PATCH 03/10] Completed Comparing Values --- ch05/Comparison.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch05/Comparison.java diff --git a/ch05/Comparison.java b/ch05/Comparison.java new file mode 100644 index 0000000..b086c90 --- /dev/null +++ b/ch05/Comparison.java @@ -0,0 +1,22 @@ +import java.sql.SQLOutput; + +public class Comparison +{ + + public static void main(String[] args) + { + String txt = "Fantastic "; + String lang = "Java " ; + boolean state = ( txt == lang ) ; // Assign test result + System.out.println( "String Equality Test: " + state ) ; + state = ( txt != lang ) ; //Assign test result + System.out.println( "String Inequality Test:" + state ) ; + int dozen = 12 ; + int score = 20 ; + state = ( dozen > score ) ; //Assign result + System.out.println( "Less Than Test" + state ) ; + + + } +} + From 3c0d4a320cd3c8e41356f56fa67dcd945c403e99 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 00:46:45 -0800 Subject: [PATCH 04/10] Completed Comparing Values --- ch05/Logic.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ch05/Logic.java diff --git a/ch05/Logic.java b/ch05/Logic.java new file mode 100644 index 0000000..64bf1a7 --- /dev/null +++ b/ch05/Logic.java @@ -0,0 +1,16 @@ +public class Logic +{ + public static void main( String[] args ) + { + boolean yes = true ; + boolean no = false ; + System.out.println( "Both YesYes True: " + ( yes && yes ) ) ; + System.out.println( "Both YesNo True: " + ( yes && no ) ) ; + System.out.println( "Either YesYes True: " + ( yes && yes )) ; + System.out.println( "Either YesNo True: " + ( yes || no ) ) ; + System.out.println( "Either NoNo True: " + ( no || no ) ) ; + System.out.println( "Original Yes Value: " + yes ) ; + System.out.println( "Inverse Yes Value: " + !yes ) ; + + } +} From 1ee2613eaad0bdabbb7ba9898ab8eaae42e3b1d4 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 01:10:59 -0800 Subject: [PATCH 05/10] Completed Comparing Values --- ch05/Condition.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ch05/Condition.java diff --git a/ch05/Condition.java b/ch05/Condition.java new file mode 100644 index 0000000..732e220 --- /dev/null +++ b/ch05/Condition.java @@ -0,0 +1,17 @@ +public class Condition +{ + + public static void main(String[] args) + + { + int num1 = 1357; + int num2 = 2468; + String result ; + result = ( num1 % 2 != 0 ) ? "Odd": "Even"; + System.out.println(num2 + " is " + result); + result = ( num2 % 2 != 0 ) ? "Odd" : "Even" ; + System.out.println( num2 + " is " + result ) ; + } + + +} From b419854a91fe1a1fd608d8769f080a05c06f8221 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 01:22:59 -0800 Subject: [PATCH 06/10] Completed Comparing Values --- ch05/Precedence.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ch05/Precedence.java diff --git a/ch05/Precedence.java b/ch05/Precedence.java new file mode 100644 index 0000000..0780449 --- /dev/null +++ b/ch05/Precedence.java @@ -0,0 +1,18 @@ +public class Precedence + +{ + public static void main(String[] args ) + { + int sum = 32 - 8 + 16 * 2 ; // 16 x 2 = 32, + 24 + 56 + System.out.println( "Default order: " + sum ) ; + sum = ( 32 - 8 + 16 ) * 2 ; // 24 + 16 = 40, x 2 + 80 + System.out.println( "Specified order: " + sum ) ; + sum = ( 32 - (8 + 16) ) * 2 ; // 32 - 24 + 8, * 2 = 80 + System.out.println( "Nested specific order: " + sum ) ; + + + + } + + +} From 6ffcf90c4b4ccb91c559e7abc6d0797bb76a3262 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 01:54:02 -0800 Subject: [PATCH 07/10] Completed Comparing Values --- ch05/If.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ch05/If.java diff --git a/ch05/If.java b/ch05/If.java new file mode 100644 index 0000000..904cc22 --- /dev/null +++ b/ch05/If.java @@ -0,0 +1,23 @@ +public class If +{ + + public static void main(String[] args) + + { + if (5 > 1) System.out.println("Five is greater than one."); + if (2 < 4) + + { + System.out.println("Test succeeded."); + System.out.println("Number is 6-9 inclusive, or 12" ); + + } + + int num = 8 ; + + { + if (((num > 5) && (num < 10)) || (num == 12)) + System.out.println("Number is 6-9 inclusive, or 12"); + } + } +} \ No newline at end of file From 446f859c5df3edc58cfa3bc9a896609ed72cd514 Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 02:09:16 -0800 Subject: [PATCH 08/10] Completed Comparing Values --- ch05/Else.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ch05/Else.java diff --git a/ch05/Else.java b/ch05/Else.java new file mode 100644 index 0000000..ee2f8a6 --- /dev/null +++ b/ch05/Else.java @@ -0,0 +1,15 @@ +public class Else +{ + public static void main(String[] args) + { + int hrs = 21; + if (hrs < 21) ; + + else if (hrs < 18) ; + + { + System.out.println(" Good morning; " + hrs); + } + + } +} From 8c8f9f9c3000cfa130dfcd55ed6e96af3da7fd5d Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 02:30:39 -0800 Subject: [PATCH 09/10] Completed Comparing Values --- ch05/LogicMethods.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ch05/LogicMethods.java diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java new file mode 100644 index 0000000..a16d6fb --- /dev/null +++ b/ch05/LogicMethods.java @@ -0,0 +1,21 @@ +public class LogicMethods +{ + public staic void main ( String[] args ) + + int + + { + System.out.println("The number is large "); + printIsLarge( number 450 ) + } + + public static void main ( String[] args ) + + + { + if (number > 85) ; + { + System.out.println + } + } +} From 9de6876c7a3b9f4cc389391b4a091ad10b479c1d Mon Sep 17 00:00:00 2001 From: StephLew1 Date: Fri, 20 Apr 2018 03:43:25 -0800 Subject: [PATCH 10/10] Logic Methods - large and small --- ch05/LogicMethods.java | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java index a16d6fb..a5f028b 100644 --- a/ch05/LogicMethods.java +++ b/ch05/LogicMethods.java @@ -1,21 +1,26 @@ public class LogicMethods { - public staic void main ( String[] args ) - - int - + public static void main(String[] args ) { - System.out.println("The number is large "); - printIsLarge( number 450 ) + System.out.println("Logic Methods"); + printIsLargeOrSmall(100) ; + printIsLargeOrSmall(75); } - public static void main ( String[] args ) + private static void printIsLargeOrSmall (int number) + { + if( number > 99 ) + if( number < 10 ) - { - if (number > 85) ; { - System.out.println + System.out.println("The number is large " ) ; + System.out.println("The number is small ") ; } + } -} + + + + +} \ No newline at end of file