From c2902431cd324b27431c7a1fee41b744e1612fac Mon Sep 17 00:00:00 2001 From: cdsbl Date: Tue, 17 Apr 2018 13:50:58 -0500 Subject: [PATCH 01/22] add Christy --- ch02/Variables.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ch02/Variables.java b/ch02/Variables.java index a295abf..e18ff87 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) + { +//Christy 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 459b74b684b147e9aabcfab91d9cad668f6dfdf3 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Tue, 17 Apr 2018 14:55:19 -0500 Subject: [PATCH 02/22] Finished exercises --- ch02/.idea/vcs.xml | 6 ++++++ ch02/Arithmetic.java | 21 +++++++++++++++++++++ ch02/Assignment.java | 23 +++++++++++++++++++++++ ch02/Constants.java | 21 +++++++++++++++++++++ ch02/DataTypes.java | 16 ++++++++++++++++ ch02/FirstVariable.java | 12 ++++++++++++ ch02/Variables.java | 2 ++ 7 files changed, 101 insertions(+) create mode 100644 ch02/.idea/vcs.xml create mode 100644 ch02/Arithmetic.java create mode 100644 ch02/Assignment.java create mode 100644 ch02/Constants.java create mode 100644 ch02/DataTypes.java create mode 100644 ch02/FirstVariable.java diff --git a/ch02/.idea/vcs.xml b/ch02/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch02/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch02/Arithmetic.java b/ch02/Arithmetic.java new file mode 100644 index 0000000..6c58e37 --- /dev/null +++ b/ch02/Arithmetic.java @@ -0,0 +1,21 @@ +public class Arithmetic +{ + 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("Subtraction sum: " + sum); + + sum=num*factor; //100x20 + System.out.println("Multiplication sum: " + sum); + sum=num/factor; //100/20 + System.out.println("Division sum: " + sum); + + + + } +} diff --git a/ch02/Assignment.java b/ch02/Assignment.java new file mode 100644 index 0000000..8deb6d1 --- /dev/null +++ b/ch02/Assignment.java @@ -0,0 +1,23 @@ +public class Assignment +{ + 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 (30x5=150) + System.out.println("Multiplication sum: "+ sum); + + sum/= factor; //Assign result (150/5=30) + System.out.println("Division sum: "+ sum); + + } +} diff --git a/ch02/Constants.java b/ch02/Constants.java new file mode 100644 index 0000000..2b8ef74 --- /dev/null +++ b/ch02/Constants.java @@ -0,0 +1,21 @@ +public class Constants +{ + public static void main(String[]args) + { + final int TOUCHDOWN = 6; + final int CONVERSION = 1; + final int FIELDGOAL = 3; + + 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..a986e55 --- /dev/null +++ b/ch02/DataTypes.java @@ -0,0 +1,16 @@ +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/FirstVariable.java b/ch02/FirstVariable.java new file mode 100644 index 0000000..104aec6 --- /dev/null +++ b/ch02/FirstVariable.java @@ -0,0 +1,12 @@ +public class FirstVariable +{ + public static void main(String[] args) + { + String message = "Initial value"; + System.out.println(message); + + message = "Modified value"; + System.out.println(message); + + } +} diff --git a/ch02/Variables.java b/ch02/Variables.java index e18ff87..b9451ca 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -7,6 +7,8 @@ public class Variables public static void main(String[] args) { //Christy + + String message; int x; From 87d04e5f5835c35855e601a8f71d7e0774ad3364 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Tue, 17 Apr 2018 15:58:39 -0500 Subject: [PATCH 03/22] Finished exercises --- ch02/Time.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ch02/Time.java diff --git a/ch02/Time.java b/ch02/Time.java new file mode 100644 index 0000000..8776604 --- /dev/null +++ b/ch02/Time.java @@ -0,0 +1,19 @@ +public class Time +{ + public static void main(String[] args) + { + int hour = 15; + int minute = 39; + int second = 43; + System.out.println(hour); + System.out.println(minute); + System.out.println(second); + + +System.out.println(midnight); + + + } +} + + From a271e81dfa85ee76077c4e41e87cd5a9e880c5e8 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Wed, 18 Apr 2018 20:12:29 -0500 Subject: [PATCH 04/22] Exercises 4-A, 4-B, 4-C --- ch04/SimpleMethods.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ch04/SimpleMethods.java diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java new file mode 100644 index 0000000..579ee3c --- /dev/null +++ b/ch04/SimpleMethods.java @@ -0,0 +1,38 @@ +import java.sql.SQLOutput; + +public class SimpleMethods +{//This is the main method to assign values for 4-A and 4-B + public static void main(String[] args) + {//These are the variables for 4-A + printCount(5); + int count = 9; + printCount(count); + int someNumber = 3; + printCount(someNumber); + //These are the variables for 4-B + int num1 = 2; + int num2 = 4; + printSum(num1 + num2); + //These is the variable for 4-C + boolean isStudent=true; + printBoolean(isStudent); + } + +//This is the method for 4-A + public static void printCount(int count) + { + System.out.println("The count is: " + count); + } + + //This is the method for 4-B + public static void printSum(int sum) + { +System.out.println("The sum is: " + sum); + } + + //This is the method for 4-C + public static void printBoolean (boolean isStudent) + { + System.out.println("I am a student:"); + } +} \ No newline at end of file From 5e8ade2e607f5af08e82b69e44db7ab54781fbef Mon Sep 17 00:00:00 2001 From: cdsbl Date: Thu, 19 Apr 2018 15:15:39 -0500 Subject: [PATCH 05/22] Chapter 5 --- ch05/Comparison.java | 23 +++++++++++++++ ch05/Condition.java | 14 +++++++++ ch05/Else.java | 18 ++++++++++++ ch05/If.java | 16 +++++++++++ ch05/Logic.java | 18 ++++++++++++ ch05/LogicMethods.java | 65 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 ch05/Comparison.java create mode 100644 ch05/Condition.java create mode 100644 ch05/Else.java create mode 100644 ch05/If.java create mode 100644 ch05/Logic.java create mode 100644 ch05/LogicMethods.java diff --git a/ch05/Comparison.java b/ch05/Comparison.java new file mode 100644 index 0000000..ad7a6c3 --- /dev/null +++ b/ch05/Comparison.java @@ -0,0 +1,23 @@ +public class Comparison + +{ + public static void main(String[]args) + { + String txt = "Fantastic " ; + String lang = "Java" ; + boolean state = (txt==lang); //Assign text result + System.out.println("String Equality Test: " + state); + + state = (txt!=lang); // Assign result + System.out.println("String Inequaltiy Test: "+ state); + + int dozen = 12; + int score = 20; + state = (dozen > score); //Assign result + System.out.println("Greater Than Test: " + state); + + state = (dozen < score); // Assign result + System.out.println("Less Than Test:" + state); + + } +} diff --git a/ch05/Condition.java b/ch05/Condition.java new file mode 100644 index 0000000..dce7cb8 --- /dev/null +++ b/ch05/Condition.java @@ -0,0 +1,14 @@ +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(num1 + "is" + result); + + result = (num2 % 2 !=0) ? "Odd" : "Even"; + System.out.println(num2 + "is" + result); +} +} diff --git a/ch05/Else.java b/ch05/Else.java new file mode 100644 index 0000000..80a43ab --- /dev/null +++ b/ch05/Else.java @@ -0,0 +1,18 @@ +public class Else +{ + public static void main(String[] args) + { + int hrs = 21; + + if (hrs < 13) + { + System.out.println("Good morning: " + hrs); + } else if (hrs < 18) + { + System.out.println("Good afternoon: " + hrs); + + } + else + System.out.println("Good evening: " + hrs); + } +} diff --git a/ch05/If.java b/ch05/If.java new file mode 100644 index 0000000..52f12a3 --- /dev/null +++ b/ch05/If.java @@ -0,0 +1,16 @@ +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("Two is less than four."); + System.out.println("Test succeeded"); + } +} + + diff --git a/ch05/Logic.java b/ch05/Logic.java new file mode 100644 index 0000000..60f23a6 --- /dev/null +++ b/ch05/Logic.java @@ -0,0 +1,18 @@ +public class Logic + +{public static void main(String[]args) + // Assign boolean +{boolean yes = true; +boolean no = false; +// Test boolean both + System.out.println("Both YesYes True: " + (yes&&yes)); + System.out.println("Both YesNo True: " + (yes&&no)); + // Test boolean either + System.out.println( "Either YesYes True: " + (yes||yes)); + System.out.println( "Either YesNo True: " + (yes||no)); + System.out.println("Either NoNo True: " + (yes||yes)); + //Show original and inverse value + System.out.println("Original Yes Value: " + yes); + System.out.println("Inverse Yes Value: " + !yes); +} +} diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java new file mode 100644 index 0000000..206fcf7 --- /dev/null +++ b/ch05/LogicMethods.java @@ -0,0 +1,65 @@ +public class LogicMethods +{ + public static void main(String[] args) + { + int number = 3; + int number1 = 3; + int number2 = 3; + printIsLarge(number); + printIsLargeOrSmall(number); + printLargest(number1, number2); + printLargestOdd(number1, number2); + } + + private static void printIsLarge(int number) + { + if (number > 99) + { + System.out.println("The number is large"); + } + } + + private static void printIsLargeOrSmall(int number) + { + if (number > 99) + { + System.out.println("The number is large"); + } + if (number < 10) + { + System.out.println("The number is small"); + } + } + + private static void printLargest(int number1, int number2) + { + if (number1 > number2) + { + System.out.println("The largest number is: " + number1); + } + if (number2 > number1) + { + System.out.println("The largest number is: " + number2); + } + if (number1 == number2) + { + System.out.println("The numbers are equal"); + } + } + + private static void printLargestOdd(int number1, int number2) + {//determines if number is odd and then compares + if (number1 % 3 == 0 && number1 > number2) + { + System.out.println("The largest odd number is: " + number1); + } + if (number1 % 2 == 0) + { + System.out.println("Neither number is odd "); + } + if (number1 % 3 == 0 && number2 %3 == 0 && number1==number2) + { + System.out.println("Two odds make an even "); + } + } +} \ No newline at end of file From 7bd17c16613c03e3a60408b324476508598e1810 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Mon, 23 Apr 2018 13:11:05 -0500 Subject: [PATCH 06/22] For --- ch07/For.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ch07/For.java diff --git a/ch07/For.java b/ch07/For.java new file mode 100644 index 0000000..46596d6 --- /dev/null +++ b/ch07/For.java @@ -0,0 +1,17 @@ +public class For +{ + public static void main(String[] args) + { + int num = 0; + for (int i = 1; i < 4; i++) + { + System.out.println("Outer Loop i=" + i); + } + + for (int j = 1; j < 4; j++) + { + System.out.print("\tInner Loop j =" + j); + System.out.println("\t\tTotal num=" + (++num)); + } + } +} From 1f0c88b65b96646ea30800e1e8a21d5f2f34d56a Mon Sep 17 00:00:00 2001 From: cdsbl Date: Mon, 23 Apr 2018 14:02:43 -0500 Subject: [PATCH 07/22] For --- ch07/Count.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ch07/Count.java diff --git a/ch07/Count.java b/ch07/Count.java new file mode 100644 index 0000000..6173a83 --- /dev/null +++ b/ch07/Count.java @@ -0,0 +1,27 @@ +public class Count +{ + public static void main(String[] args) + { + int num = 0; + for (int i = 0+1; i <= 10; i++) + { + System.out.println("Counting up to 10 by 1 with for = " + i); + } + + while(num<=10) + { + System.out.println("Counting up to 10 by 1 with while = " + num); + num++; + } + + num = 1; + do + { + System.out.println("Counting up to 10 by 1 with do while = " + num); + num++; + } + while(num<=10); + } + + +} From e9b52c33734789be3d7443646b71804bba9db207 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Mon, 23 Apr 2018 14:46:59 -0500 Subject: [PATCH 08/22] For --- ch02/Date.java | 30 +++ ch02/Time.java | 7 +- ch03/Input.java | 6 +- ch03/Temperature.java | 29 +++ ch04/.idea/misc.xml | 6 + ch04/.idea/modules.xml | 8 + ch04/.idea/vcs.xml | 6 + ch04/.idea/workspace.xml | 309 +++++++++++++++++++++++++++ ch04/SimpleMethods.java | 2 +- ch04/Switch.java | 4 + ch04/ch04.iml | 11 + ch05/.idea/misc.xml | 6 + ch05/.idea/modules.xml | 8 + ch05/.idea/vcs.xml | 6 + ch05/.idea/workspace.xml | 447 +++++++++++++++++++++++++++++++++++++++ ch05/Precedence.java | 16 ++ ch05/Switch.java | 21 ++ ch05/ch05.iml | 11 + ch06/.idea/misc.xml | 6 + ch06/.idea/modules.xml | 8 + ch06/.idea/workspace.xml | 272 ++++++++++++++++++++++++ ch06/Demo.java | 38 ++++ ch06/Divisible.java | 4 + ch06/ch06.iml | 11 + ch07/.idea/misc.xml | 6 + ch07/.idea/modules.xml | 8 + ch07/.idea/vcs.xml | 6 + ch07/.idea/workspace.xml | 413 ++++++++++++++++++++++++++++++++++++ ch07/CountByTens.java | 25 +++ ch07/DoWhile.java | 13 ++ ch07/While.java | 13 ++ ch07/ch07.iml | 11 + 32 files changed, 1762 insertions(+), 5 deletions(-) create mode 100644 ch02/Date.java create mode 100644 ch03/Temperature.java create mode 100644 ch04/.idea/misc.xml create mode 100644 ch04/.idea/modules.xml create mode 100644 ch04/.idea/vcs.xml create mode 100644 ch04/.idea/workspace.xml create mode 100644 ch04/Switch.java create mode 100644 ch04/ch04.iml create mode 100644 ch05/.idea/misc.xml create mode 100644 ch05/.idea/modules.xml create mode 100644 ch05/.idea/vcs.xml create mode 100644 ch05/.idea/workspace.xml create mode 100644 ch05/Precedence.java create mode 100644 ch05/Switch.java create mode 100644 ch05/ch05.iml create mode 100644 ch06/.idea/misc.xml create mode 100644 ch06/.idea/modules.xml create mode 100644 ch06/.idea/workspace.xml create mode 100644 ch06/Demo.java create mode 100644 ch06/Divisible.java create mode 100644 ch06/ch06.iml create mode 100644 ch07/.idea/misc.xml create mode 100644 ch07/.idea/modules.xml create mode 100644 ch07/.idea/vcs.xml create mode 100644 ch07/.idea/workspace.xml create mode 100644 ch07/CountByTens.java create mode 100644 ch07/DoWhile.java create mode 100644 ch07/While.java create mode 100644 ch07/ch07.iml diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..50137ad --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,30 @@ +public class Date + +{ + public static void main (String[]args) + { + System.out.println("Date"); + System.out.println("American format:"); + String day = "Tuesday, "; + String date = "17th,"; + String month = "April "; + String year = " 2018"; + System.out.print(day); + System.out.print(month); + System.out.print(date); + System.out.println(year); + + + + System.out.println("European format:"); + String eday = "Tuesday "; + String edate = "17 "; + String emonth = "April "; + String eyear = "2018"; + System.out.print(eday); + System.out.print(emonth); + System.out.print(edate); + System.out.print(eyear); + } + } + diff --git a/ch02/Time.java b/ch02/Time.java index 8776604..3d7ef2b 100644 --- a/ch02/Time.java +++ b/ch02/Time.java @@ -1,8 +1,10 @@ public class Time { public static void main(String[] args) - { + {// + //undone int hour = 15; + int minute = 39; int second = 43; System.out.println(hour); @@ -10,10 +12,11 @@ public static void main(String[] args) System.out.println(second); -System.out.println(midnight); + // } } + diff --git a/ch03/Input.java b/ch03/Input.java index de97dc0..78f2b6d 100644 --- a/ch03/Input.java +++ b/ch03/Input.java @@ -6,11 +6,13 @@ public class Input { public static void main(String[] args) { System.out.println(System.out); - System.out.print(4.0 / 3.0); + System.out.println(4.0 / 3.0); System.out.printf("Four thirds = %.3f", 4.0 / 3.0); double pi = 3.14159; double x = (int) pi * 20.0; + + } -} + } \ No newline at end of file diff --git a/ch03/Temperature.java b/ch03/Temperature.java new file mode 100644 index 0000000..5432a40 --- /dev/null +++ b/ch03/Temperature.java @@ -0,0 +1,29 @@ +import java.util.Scanner; +public class Temperature +{public static void main(String[] args) +{String line; + +//create some variables to hold the two temperature values + double celsius; + double fahrenheit; +//create a scanner to read the keyboard input + Scanner in = new Scanner(System.in); + + // prompt the user and get Celsius value + System.out.print("What is the temperature outside in degrees Celsius?"); + //wait for the value from the keyboard and then + //assign it to the celsius variable + celsius = in.nextDouble(); + + //Show user the value they entered + System.out.println("You entered " + celsius + " for Celsius"); +//Do some math and convert from celsius and fahrenheit + fahrenheit = (celsius * 9.0/5.0)+32; + System.out.println("The temperature in Fahrenheit is: " + fahrenheit); + + + + +} + +} diff --git a/ch04/.idea/misc.xml b/ch04/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch04/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch04/.idea/modules.xml b/ch04/.idea/modules.xml new file mode 100644 index 0000000..740d4e8 --- /dev/null +++ b/ch04/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch04/.idea/vcs.xml b/ch04/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch04/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch04/.idea/workspace.xml b/ch04/.idea/workspace.xml new file mode 100644 index 0000000..9fe6f2e --- /dev/null +++ b/ch04/.idea/workspace.xml @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524237464668 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch06/Demo.java b/ch06/Demo.java new file mode 100644 index 0000000..8562e6c --- /dev/null +++ b/ch06/Demo.java @@ -0,0 +1,38 @@ +public class Demo +{ + public static void main(String[] args) + { + int firstValue = 5; + int secondValue = 50; + int thirdValue = 200; + + int firstValueBig = howBig(firstValue); + int secondValueBig = howBig(secondValue); + int thirdValueBig = howBig(thirdValue); + + System.out.println("firstValue is " + firstValue + "howBig returns: " + firstValueBig); + System.out.println("secondValue is " + secondValue + "howBig returns: " + secondValueBig); + System.out.println("thirdValue is " + thirdValue + "howBig returns: " + thirdValueBig); + } + + + //returns 0 if value less than 10 + //returns 1 if value 10 to 100 + // returns 2 if value more than 100 + private static int howBig(int value) + { + int answer; + + if (value >= 10 && value <= 100) + { + answer = 1; + } else if (value > 100) + { + answer = 2; + } else + { + answer = 0; + } + return answer; + } +} \ No newline at end of file diff --git a/ch06/Divisible.java b/ch06/Divisible.java new file mode 100644 index 0000000..5f94059 --- /dev/null +++ b/ch06/Divisible.java @@ -0,0 +1,4 @@ +public class Divisible +{ public static void main(String[] args) +{} +} diff --git a/ch06/ch06.iml b/ch06/ch06.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch06/ch06.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ch07/.idea/misc.xml b/ch07/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch07/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch07/.idea/modules.xml b/ch07/.idea/modules.xml new file mode 100644 index 0000000..644f3a5 --- /dev/null +++ b/ch07/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch07/.idea/vcs.xml b/ch07/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch07/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml new file mode 100644 index 0000000..fa1deee --- /dev/null +++ b/ch07/.idea/workspace.xml @@ -0,0 +1,413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -182,19 +182,18 @@ - + - - + @@ -211,6 +210,7 @@ + @@ -247,11 +247,46 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml index 23b3afb..8e0f817 100644 --- a/ch07/.idea/workspace.xml +++ b/ch07/.idea/workspace.xml @@ -2,7 +2,13 @@ - + + + + + + + @@ -28,7 +34,7 @@ - + @@ -37,7 +43,7 @@ - + @@ -55,7 +61,7 @@ - + @@ -85,7 +91,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524514613632 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch08/ch08.iml b/ch08/ch08.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch08/ch08.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 4f0d0c1edbfaa0613f88a0c12481417abe423098 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Tue, 24 Apr 2018 15:34:55 -0500 Subject: [PATCH 12/22] Chapter 8 --- ch08/ArrayDemo.java | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ch08/ArrayDemo.java diff --git a/ch08/ArrayDemo.java b/ch08/ArrayDemo.java new file mode 100644 index 0000000..5241f7b --- /dev/null +++ b/ch08/ArrayDemo.java @@ -0,0 +1,91 @@ +public class ArrayDemo +{ + public static void main(String[] args) + { + int[] values = {1, 5, 9}; // These are the values for 8-A in main + printArray(values); + System.out.println(); + + int[] sumNumbers = {5, 7, 13}; //These are the values for 8-B in main + int sum = arrayTotal(sumNumbers); + printArray(sumNumbers); + System.out.println("The numbers added up to " + sum); + + int[] maxNumbers = {5, 8, 21, 19, 2}; //These are the values for 8-C in main + int max = arrayMax(maxNumbers); + printArray(maxNumbers); + System.out.println("The highest number is " + max); + + int[] indexNumbers = {78, 23, 9, 34}; //These are the values for 8-D in main + int index = arrayMaxIndex(indexNumbers); + printArray(indexNumbers); + System.out.println("The highest index is " + index); + + double[] avgValue = {34.2, 18.0, 12.5, 13.1}; //These are the values for 8-E in main + double average = arrayAverage(avgValue); + System.out.println("The average is " + average); + + } + + private static void printArray(int[] values)//This is the method for 8-A + { + for (int value : values) + System.out.println(value); + } + + private static int arrayTotal(int[] values) //This is the method for 8-B + { + int sum = 0; + for (int value : values) + { + sum = sum + value; + } + return sum; + } + + private static int arrayMax(int[] values) //This is the method for 8-C + { + int max = 0; + for (int value : values) + { + if (value > max) + { + max = value; + } + } + return max; + } + + private static int arrayMaxIndex(int[] values) //This is the method for 8-D + { + int max = 0; + int indexMax = 0; + int index = 0; + + for (int value : values) + { + if (value > max) + { + max = value; + indexMax = index; + } + index = index + 1; + } + return indexMax; + } + + private static double arrayAverage(double[] values) //This is the method for 8-E + { + double sum = 0.0; + for (double value : values) + { + sum = (sum + value); + } + double average = sum/4; + return average; + + } +} + + + From 22abe2de5c05664d111ecc4ddc7eec82ef10b17f Mon Sep 17 00:00:00 2001 From: cdsbl Date: Tue, 24 Apr 2018 16:12:37 -0500 Subject: [PATCH 13/22] Chapter 8 --- ch07/.idea/workspace.xml | 10 +-- ch08/.idea/vcs.xml | 6 ++ ch08/.idea/workspace.xml | 144 +++++++++++++++++++++++++++++++++------ ch08/ArrayDemo.java | 26 +++++-- 4 files changed, 155 insertions(+), 31 deletions(-) create mode 100644 ch08/.idea/vcs.xml diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml index 8e0f817..8350711 100644 --- a/ch07/.idea/workspace.xml +++ b/ch07/.idea/workspace.xml @@ -2,14 +2,10 @@ - - - - - - - + + + + + - + + @@ -73,7 +97,7 @@ - + - + + + @@ -134,8 +163,13 @@ + + + + + @@ -151,25 +185,41 @@ - + + - - + + - + @@ -183,22 +233,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/Array.java + 10 + + + + + - + + + + - - + + - + - + + + + + + + + diff --git a/ch08/ArrayDemo.java b/ch08/ArrayDemo.java index 5241f7b..cf83862 100644 --- a/ch08/ArrayDemo.java +++ b/ch08/ArrayDemo.java @@ -2,10 +2,11 @@ public class ArrayDemo { public static void main(String[] args) { - int[] values = {1, 5, 9}; // These are the values for 8-A in main + int[] values = {1,5,9}; // These are the values for 8-A in main printArray(values); System.out.println(); + int[] sumNumbers = {5, 7, 13}; //These are the values for 8-B in main int sum = arrayTotal(sumNumbers); printArray(sumNumbers); @@ -21,10 +22,21 @@ public static void main(String[] args) printArray(indexNumbers); System.out.println("The highest index is " + index); - double[] avgValue = {34.2, 18.0, 12.5, 13.1}; //These are the values for 8-E in main + double[] avgValue = {10.0, 15.0, 20.0}; //These are the values for 8-E in main double average = arrayAverage(avgValue); System.out.println("The average is " + average); + int [] values2 = new int[10]; // 8-F adding int using new keyword + values2[0]=4; + values2[3]=2; + values2[9]=4; + printArray(values2); + + String [] values3 = new String[10]; //8-G adding string using new keyword + values3[0]="Hi"; + values3[3]="Hello"; + values3[9]="Bye"; + printArray(values3); } private static void printArray(int[] values)//This is the method for 8-A @@ -32,6 +44,11 @@ private static void printArray(int[] values)//This is the method for 8-A for (int value : values) System.out.println(value); } + private static void printArray(String[] values)//This is the method for 8-A + { + for (String value : values) + System.out.println(value); + } private static int arrayTotal(int[] values) //This is the method for 8-B { @@ -81,10 +98,11 @@ private static double arrayAverage(double[] values) //This is the method for 8-E { sum = (sum + value); } - double average = sum/4; + double average = sum/values.length; return average; - } + + } From ce38a2aedc0f3aef7e9e248cf8dc1c6a5145e8c4 Mon Sep 17 00:00:00 2001 From: cdsbl Date: Wed, 25 Apr 2018 14:13:17 -0500 Subject: [PATCH 14/22] StringUtil 9 --- ch07/.idea/workspace.xml | 7 +- ch08/.idea/workspace.xml | 52 +++++--- ch09/.idea/misc.xml | 6 + ch09/.idea/modules.xml | 8 ++ ch09/.idea/workspace.xml | 250 +++++++++++++++++++++++++++++++++++++++ ch09/ch09.iml | 11 ++ 6 files changed, 317 insertions(+), 17 deletions(-) create mode 100644 ch09/.idea/misc.xml create mode 100644 ch09/.idea/modules.xml create mode 100644 ch09/.idea/workspace.xml create mode 100644 ch09/ch09.iml diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml index 8350711..1795876 100644 --- a/ch07/.idea/workspace.xml +++ b/ch07/.idea/workspace.xml @@ -2,10 +2,11 @@ - - + + + + - - + - - + + + + + + + + + + + @@ -70,8 +80,8 @@ - @@ -97,7 +107,7 @@ - + - + @@ -214,7 +231,7 @@ - + @@ -301,8 +318,15 @@ - - + + + + + + + + + diff --git a/ch09/.idea/misc.xml b/ch09/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch09/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch09/.idea/modules.xml b/ch09/.idea/modules.xml new file mode 100644 index 0000000..dbdfbb9 --- /dev/null +++ b/ch09/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch09/.idea/workspace.xml b/ch09/.idea/workspace.xml new file mode 100644 index 0000000..f589559 --- /dev/null +++ b/ch09/.idea/workspace.xml @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -206,17 +206,52 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml index 21c13b6..9861962 100644 --- a/ch07/.idea/workspace.xml +++ b/ch07/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + @@ -277,11 +280,11 @@ + - @@ -292,6 +295,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch09/.idea/workspace.xml b/ch09/.idea/workspace.xml index f88d456..d95cee2 100644 --- a/ch09/.idea/workspace.xml +++ b/ch09/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + - + - + @@ -26,16 +29,8 @@ - - - - - - - - - - + + @@ -81,9 +76,9 @@ - @@ -254,7 +271,7 @@ - + @@ -264,18 +281,18 @@ - + - + - + @@ -335,6 +352,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch09/.idea/workspace.xml b/ch09/.idea/workspace.xml index 41ae98d..66be2de 100644 --- a/ch09/.idea/workspace.xml +++ b/ch09/.idea/workspace.xml @@ -2,9 +2,25 @@ + + + + + + + + + + + + + + + + - @@ -103,7 +125,7 @@ - + - + + + - + @@ -241,12 +276,12 @@ - + - + @@ -265,10 +300,10 @@ - + - + @@ -284,7 +319,7 @@ - + @@ -339,10 +374,18 @@ + + + + + + + + - - + + diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java index 021100e..e1035fc 100644 --- a/ch09/StringUtil.java +++ b/ch09/StringUtil.java @@ -34,6 +34,9 @@ public static void main(String[] args) //HOW DO I GET/PRINT THE INDEX??? 9-B-6 String printCharacters = getprintCharacters("Hello"); + printPhoneNumber("501-555-0100"); + + } @@ -77,16 +80,20 @@ private static String getprintCharacters(String value) return value; } - private static void printPhoneNumber(String area, String exchange, String line) + private static void printPhoneNumber(String phoneNumber) { - String phoneNumber = area.substring(0,3) + exchange.substring(3,6) + line.substring (6,9); - System.out.print("Phone Number is" + area); + String areaCode = phoneNumber.substring(0,3); + String exchange = phoneNumber.substring(4,7); + String lineNumber = phoneNumber.substring(8,12); + System.out.println("Area Code: " + areaCode + " Exchange: " + exchange + " Line Number: " + lineNumber); } +} + - //private static String findFirstE ("Hello") + //private static void String (findFirstE) //{ - // return int index = value.indexOf('e'); + //return int index = value.indexOf('e'); //} //private static String isFinn (String value) @@ -94,5 +101,4 @@ private static void printPhoneNumber(String area, String exchange, String line) //if name1=="Finn" //{ //return = true; - //}} -} \ No newline at end of file + //}} \ No newline at end of file diff --git a/ch10/.idea/misc.xml b/ch10/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch10/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch10/.idea/modules.xml b/ch10/.idea/modules.xml new file mode 100644 index 0000000..5794ef7 --- /dev/null +++ b/ch10/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch10/.idea/vcs.xml b/ch10/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch10/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch10/.idea/workspace.xml b/ch10/.idea/workspace.xml new file mode 100644 index 0000000..5fc7509 --- /dev/null +++ b/ch10/.idea/workspace.xml @@ -0,0 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524855333271 + + + 1524863354043 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch11/Date.java b/ch11/Date.java new file mode 100644 index 0000000..8bdaa4b --- /dev/null +++ b/ch11/Date.java @@ -0,0 +1,37 @@ +public class Date +{ + private int day; + private int month; + private int year; + + public Date (int day, int month, int year) + { + this.day=day; + this.month=month; + this.year=year; + } + + public int getDay() + { + return day; + } + + public int getMonth() + { + return month; + } + + public int getYear() + { + return year; + } + + public String getFormattedDate() + { + String formattedDate = year + "-" + month + "-" + day; + return formattedDate; + } +} + + + diff --git a/ch11/DateTester.java b/ch11/DateTester.java index a516610..bbef763 100644 --- a/ch11/DateTester.java +++ b/ch11/DateTester.java @@ -2,15 +2,11 @@ public class DateTester { public static void main(String[] args) { - Date currentDate = new Date (27, 4, 2018); - printcurrentDate(Date); - } - public static void currentDate (Date[] Date) - { - for (Date date : Date) - { - System.out.println(date.getDate()); - } + Date currentDate = new Date(27, 4, 2018); + + System.out.println(currentDate.getFormattedDate()); + } + } diff --git a/ch11/Planet.java b/ch11/Planet.java new file mode 100644 index 0000000..d181f3a --- /dev/null +++ b/ch11/Planet.java @@ -0,0 +1,14 @@ +public class Planet +{ + private String name; + + public Planet(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/ch11/PlanetTester.java b/ch11/PlanetTester.java new file mode 100644 index 0000000..792f31b --- /dev/null +++ b/ch11/PlanetTester.java @@ -0,0 +1,37 @@ +public class PlanetTester +{ + public static void main(String[] args) + { + Planet mercury = new Planet("Mercury"); + Planet venus = new Planet("Venus"); + Planet earth = new Planet("Earth"); + Planet mars = new Planet("Mars"); + Planet jupiter = new Planet("Jupiter"); + Planet saturn = new Planet("Saturn"); + Planet uranus = new Planet("Uranus"); + Planet neptune = new Planet("Neptune"); + Planet pluto = new Planet("Pluto"); + + Planet[] solarSystemPlanets = new Planet[9]; + solarSystemPlanets[0] = mercury; + solarSystemPlanets[1] = venus; + solarSystemPlanets[2] = earth; + solarSystemPlanets[3] = mars; + solarSystemPlanets[4] = jupiter; + solarSystemPlanets[5] = saturn; + solarSystemPlanets[6] = uranus; + solarSystemPlanets[7] = neptune; + solarSystemPlanets[8] = pluto; + + printPlanet(solarSystemPlanets); + + } + + private static void printPlanet(Planet[] Planet) + { + for (Planet planet : Planet) + { + System.out.println(planet.getName()); + } + } +} diff --git a/ch11/ch11.iml b/ch11/ch11.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch11/ch11.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file