From f0633534256e6eb2664ec1d098a65dd5d024b8cc Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 13:51:36 -0500 Subject: [PATCH 001/103] 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..0d46a93 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) + { + //Tim 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 ddd162ceff9093b8904f9519047af802392edae2 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 14:58:06 -0500 Subject: [PATCH 002/103] added comment --- ch02/.idea/vcs.xml | 6 ++++++ ch02/Arithmetic.java | 18 ++++++++++++++++++ ch02/Assignment.java | 20 ++++++++++++++++++++ ch02/Constants.java | 24 ++++++++++++++++++++++++ ch02/DataTypes.java | 16 ++++++++++++++++ ch02/FirstVariable.java | 10 ++++++++++ 6 files changed, 94 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..94bb4b2 --- /dev/null +++ b/ch02/Arithmetic.java @@ -0,0 +1,18 @@ +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; //100x 20 + System.out.println("Multiplication: "+ 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..73ad4ee --- /dev/null +++ b/ch02/Assignment.java @@ -0,0 +1,20 @@ +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 (30 x 5= 150) + System.out.println("Multiplication sum: "+ sum); + sum/= factor; //Assgn 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..962b813 --- /dev/null +++ b/ch02/Constants.java @@ -0,0 +1,24 @@ + +/* A program to demonstrate constant variables +/* + */ +public class Constants +{ + public static void main (String[]args) + { + //Constant score values. + final int TOUCHDOWN = 6; + final int CONVERSION = 1; + final int FIELDGOAL = 3; + + //Calculate points scored + int td,pat,fg,total; + td=4* TOUCHDOWN; //4x6=24 + pat=3*CONVERSION; //3x1=3 + fg =2*FIELDGOAL; //2x3=6 + total = (td+pat+fg); //24+3+6=33 + + //Output calculated total. + System.out.println("Score: "+ total); + } +} diff --git a/ch02/DataTypes.java b/ch02/DataTypes.java new file mode 100644 index 0000000..6207c7d --- /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..16b78a9 --- /dev/null +++ b/ch02/FirstVariable.java @@ -0,0 +1,10 @@ +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 f74271814c3db2e5699a407e0eca2268608978f6 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 16:00:08 -0500 Subject: [PATCH 003/103] added comment --- ch02/Date.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch02/Date.java diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..ae91d64 --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,22 @@ +public class Date +{ + public static void main(String[] args) + { + String day = "Tuesday "; + String month = "April "; + int date = 16; + int year = 2018; + System.out.println("American Format:"); + System.out.print(day); + System.out.print(month); + System.out.print(date); + System.out.print(", "); + System.out.println(year); + System.out.println("European Format:"); + System.out.print(day); + System.out.print(date); + System.out.print(" "); + System.out.print(month); + System.out.println(year); + } +} From 478d859a6110838eb81a728b2432fad44deba917 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 19:31:08 -0500 Subject: [PATCH 004/103] added comment --- ch02/Time.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ch02/Time.java diff --git a/ch02/Time.java b/ch02/Time.java new file mode 100644 index 0000000..382815b --- /dev/null +++ b/ch02/Time.java @@ -0,0 +1,42 @@ +public class Time +{ + public static void main(String[] args) + { + int hour = 15; + int minute = 46; + int second = 33; + + /*Calculate current time to seconds since midnight, 15 hours x 60 minutes x 60 seconds + + minutes x 60 seconds + seconds = 56793 + */ + int secondsSinceMidnight = (hour * 60) * 60 + (minute * 60) + second; + System.out.print("Number of seconds since midnight: "); + System.out.println(secondsSinceMidnight); + //Calculate one day into seconds + double oneDay = 24 * 60 * 60; + double secondsUntilMidnight = oneDay - secondsSinceMidnight; + System.out.println("Number of seconds until midnight: " + secondsUntilMidnight); + //Percentage of the day that has passed + System.out.print("Percent of day that has passed: " + secondsSinceMidnight * 100 / oneDay); + System.out.println("%"); + //Change hour minute and second to reflect current time + + //Place holders for computation + int x = hour; + int y= minute; + int z = second; + //Change values to "current" time + hour = 18; + minute = 58; + second = 45; + //Compute how much time has passed in hours minutes and seconds + int elapsedHour = hour - x; + int elapsedMinute = minute - y; + int elapsedSecond = second -z; + System.out.print("Elapsed Time: "+ elapsedHour); + System.out.print(" Hours "+ elapsedMinute); + System.out.print(" Minutes "+ elapsedSecond); + System.out.println(" Seconds has passed since starting exercise."); + + } +} From a124b0cfc2b838cd20476ef986e28c141ad303ee Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 19:52:21 -0500 Subject: [PATCH 005/103] added comment --- ch02/IntExtremes.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ch02/IntExtremes.java diff --git a/ch02/IntExtremes.java b/ch02/IntExtremes.java new file mode 100644 index 0000000..41bf6d4 --- /dev/null +++ b/ch02/IntExtremes.java @@ -0,0 +1,18 @@ +public class IntExtremes +{ + public static void main(String[] args) + { + //Increas max positive int + int positiveInt = 2147483647; + System.out.println(positiveInt); + positiveInt++; + System.out.println(positiveInt); + int negativeInt = -2147483648; + + //Decrease max negative int + System.out.println(negativeInt); + negativeInt--; + System.out.println(negativeInt); + + } +} From 0e4e6918cbe029a8c4cfac7206b7dc8024072643 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 19:55:18 -0500 Subject: [PATCH 006/103] Fixed Typo in comment --- ch02/IntExtremes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch02/IntExtremes.java b/ch02/IntExtremes.java index 41bf6d4..db4ac61 100644 --- a/ch02/IntExtremes.java +++ b/ch02/IntExtremes.java @@ -2,7 +2,7 @@ public class IntExtremes { public static void main(String[] args) { - //Increas max positive int + //Increase max positive int int positiveInt = 2147483647; System.out.println(positiveInt); positiveInt++; From 30dc09eed3fd3612d7e5d7593a18ddae79eb1c76 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 20:01:28 -0500 Subject: [PATCH 007/103] Fixed Typo in comment --- ch02/IntByZero.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch02/IntByZero.java diff --git a/ch02/IntByZero.java b/ch02/IntByZero.java new file mode 100644 index 0000000..16311cc --- /dev/null +++ b/ch02/IntByZero.java @@ -0,0 +1,12 @@ +public class IntByZero +{ + public static void main (String[] args) + { + + //Divide by zero error demo + int first = 42; + int second = 0; + int result = first / second; + System.out.println(result); + } +} From 0c02de473cf12975e8f9893ed178faba3711eb27 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 20:07:55 -0500 Subject: [PATCH 008/103] added comment --- ch02/DoubleByZero.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch02/DoubleByZero.java diff --git a/ch02/DoubleByZero.java b/ch02/DoubleByZero.java new file mode 100644 index 0000000..bc5f7fa --- /dev/null +++ b/ch02/DoubleByZero.java @@ -0,0 +1,12 @@ +public class DoubleByZero +{ + public static void main (String[] args) + { + + //Divide by zero error demo + double first = 42; + double second = 0; + double result = first / second; + System.out.println(result); + } +} \ No newline at end of file From 83ff3db471d875bf1658437c775309a0e029c18f Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 20:14:03 -0500 Subject: [PATCH 009/103] added comment --- ch02/LoveJava.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ch02/LoveJava.java diff --git a/ch02/LoveJava.java b/ch02/LoveJava.java new file mode 100644 index 0000000..10d2d95 --- /dev/null +++ b/ch02/LoveJava.java @@ -0,0 +1,11 @@ +public class LoveJava +{ + public static void main (String[] args) + { + System.out.println("I love Java!"); + String firstWord = "I "; + String secondWord = "love "; + String thirdWord = "Java!"; + System.out.println(firstWord + secondWord + thirdWord); + } +} From 2fcb1aba36deeef070208b9e66027fdb5c865d5a Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 21:49:37 -0500 Subject: [PATCH 010/103] 2-E Silver --- ch02/Withdrawal.java | 106 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 ch02/Withdrawal.java diff --git a/ch02/Withdrawal.java b/ch02/Withdrawal.java new file mode 100644 index 0000000..171ad2e --- /dev/null +++ b/ch02/Withdrawal.java @@ -0,0 +1,106 @@ +public class Withdrawal +{ + public static void main (String[] args) + { + //Compute $137 withdrawal into appropriate bills + int withdrawal = 137; + int twenty = 20; + int ten = 10; + int five = 5; + int one = 1; + int distributeTwenties = withdrawal / twenty; + int twentyRemainder = withdrawal % twenty; + int distributeTen = twentyRemainder / ten; + int tenRemainder = twentyRemainder % ten; + int distributeFive = tenRemainder / five; + int fiveRemainder = tenRemainder % five; + int distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = 137"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + System.out.println("\n"); + + //Compute $100 withdrawal into appropriate bills + withdrawal = 100; + distributeTwenties = withdrawal / twenty; + twentyRemainder = withdrawal % twenty; + distributeTen = twentyRemainder / ten; + tenRemainder = twentyRemainder % ten; + distributeFive = tenRemainder / five; + fiveRemainder = tenRemainder % five; + distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = $100"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + System.out.println("\n"); + + //Compute $20 withdrawal into appropriate bills + withdrawal = 20; + distributeTwenties = withdrawal / twenty; + twentyRemainder = withdrawal % twenty; + distributeTen = twentyRemainder / ten; + tenRemainder = twentyRemainder % ten; + distributeFive = tenRemainder / five; + fiveRemainder = tenRemainder % five; + distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = $20"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + System.out.println("\n"); + + //Compute $17 withdrawal into appropriate bills + withdrawal = 17; + distributeTwenties = withdrawal / twenty; + twentyRemainder = withdrawal % twenty; + distributeTen = twentyRemainder / ten; + tenRemainder = twentyRemainder % ten; + distributeFive = tenRemainder / five; + fiveRemainder = tenRemainder % five; + distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = $17"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + System.out.println("\n"); + + //Compute $15 withdrawal into appropriate bills + withdrawal = 15; + distributeTwenties = withdrawal / twenty; + twentyRemainder = withdrawal % twenty; + distributeTen = twentyRemainder / ten; + tenRemainder = twentyRemainder % ten; + distributeFive = tenRemainder / five; + fiveRemainder = tenRemainder % five; + distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = $15"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + System.out.println("\n"); + + //Compute $2 withdrawal into appropriate bills + withdrawal = 2; + distributeTwenties = withdrawal / twenty; + twentyRemainder = withdrawal % twenty; + distributeTen = twentyRemainder / ten; + tenRemainder = twentyRemainder % ten; + distributeFive = tenRemainder / five; + fiveRemainder = tenRemainder % five; + distributeOne = fiveRemainder / one; + System.out.println("When withdrawal = $2"); + System.out.print("Distribute $20 bills = " + distributeTwenties); + System.out.print(", $10 bills = " + distributeTen); + System.out.print(", $5 bills = " + distributeFive); + System.out.println(", $1 bills = " + distributeOne); + + //This was tough for the 2nd day, may be crude but it meets requirements! + } +} From 86566d91072846b3b06135e4bf9f3cf60e8b911a Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 17 Apr 2018 22:14:41 -0500 Subject: [PATCH 011/103] 2-E Silver --- ch02/Withdrawal.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ch02/Withdrawal.java b/ch02/Withdrawal.java index 171ad2e..64e6506 100644 --- a/ch02/Withdrawal.java +++ b/ch02/Withdrawal.java @@ -19,7 +19,7 @@ public static void main (String[] args) System.out.print("Distribute $20 bills = " + distributeTwenties); System.out.print(", $10 bills = " + distributeTen); System.out.print(", $5 bills = " + distributeFive); - System.out.println(", $1 bills = " + distributeOne); + System.out.print(", $1 bills = " + distributeOne); System.out.println("\n"); //Compute $100 withdrawal into appropriate bills @@ -35,7 +35,7 @@ public static void main (String[] args) System.out.print("Distribute $20 bills = " + distributeTwenties); System.out.print(", $10 bills = " + distributeTen); System.out.print(", $5 bills = " + distributeFive); - System.out.println(", $1 bills = " + distributeOne); + System.out.print(", $1 bills = " + distributeOne); System.out.println("\n"); //Compute $20 withdrawal into appropriate bills @@ -51,7 +51,7 @@ public static void main (String[] args) System.out.print("Distribute $20 bills = " + distributeTwenties); System.out.print(", $10 bills = " + distributeTen); System.out.print(", $5 bills = " + distributeFive); - System.out.println(", $1 bills = " + distributeOne); + System.out.print(", $1 bills = " + distributeOne); System.out.println("\n"); //Compute $17 withdrawal into appropriate bills @@ -67,7 +67,7 @@ public static void main (String[] args) System.out.print("Distribute $20 bills = " + distributeTwenties); System.out.print(", $10 bills = " + distributeTen); System.out.print(", $5 bills = " + distributeFive); - System.out.println(", $1 bills = " + distributeOne); + System.out.print(", $1 bills = " + distributeOne); System.out.println("\n"); //Compute $15 withdrawal into appropriate bills @@ -83,7 +83,7 @@ public static void main (String[] args) System.out.print("Distribute $20 bills = " + distributeTwenties); System.out.print(", $10 bills = " + distributeTen); System.out.print(", $5 bills = " + distributeFive); - System.out.println(", $1 bills = " + distributeOne); + System.out.print(", $1 bills = " + distributeOne); System.out.println("\n"); //Compute $2 withdrawal into appropriate bills From 05a6e4c444413d88970ddd4e69c59e2560256fff Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 13:44:04 -0500 Subject: [PATCH 012/103] 3.2 --- ch03/TempConvert.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ch03/TempConvert.java diff --git a/ch03/TempConvert.java b/ch03/TempConvert.java new file mode 100644 index 0000000..802c1cf --- /dev/null +++ b/ch03/TempConvert.java @@ -0,0 +1,27 @@ + +import java.util.Scanner; + /** + * Converts centimeters to feet and inches. + */ + public class TempConvert + { + + public static void main(String[] args) { + double celsius; + double fahrenheit; + + Scanner in = new Scanner(System.in); + + // prompt the user and get the value + System.out.print("Exactly how many cm? "); + celsius = in.nextDouble(); + + fahrenheit = (celsius * 9.0/5.0) + 32; + System.out.println("Temp in Farenheight is: " + fahrenheit); + + + + } + + } + From 4aa375ab73cedda04d68a3c7f72cc0a35ab699b4 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 15:41:24 -0500 Subject: [PATCH 013/103] 4-a --- ch04/SimpleMethods.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ch04/SimpleMethods.java diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java new file mode 100644 index 0000000..9a2f828 --- /dev/null +++ b/ch04/SimpleMethods.java @@ -0,0 +1,11 @@ +public class SimpleMethods +{ + public void main (String[] args) + { + printCount(5); + } + public static void printCount(int count) + { + System.out.println("The count is: " + count); + } +} From bffa7de5f11d98c0106ac97aaf3f1aef58595937 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 15:57:49 -0500 Subject: [PATCH 014/103] 4-a --- ch04/SimpleMethods.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java index 9a2f828..829dbb1 100644 --- a/ch04/SimpleMethods.java +++ b/ch04/SimpleMethods.java @@ -3,9 +3,16 @@ public class SimpleMethods public void main (String[] args) { printCount(5); + printSum(4,6); + printSum(7,2); } public static void printCount(int count) { System.out.println("The count is: " + count); } + + public static void printSum(int x, int y) + { + System.out.println(x+y); + } } From ea83ef2a1eade1fc8af833278246cf9084942a38 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 16:06:53 -0500 Subject: [PATCH 015/103] 4a to 4c --- ch04/SimpleMethods.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java index 829dbb1..76622c8 100644 --- a/ch04/SimpleMethods.java +++ b/ch04/SimpleMethods.java @@ -1,10 +1,12 @@ public class SimpleMethods { - public void main (String[] args) + public static void main (String[] args) { printCount(5); printSum(4,6); printSum(7,2); + printBoolean(true); + printBoolean(false); } public static void printCount(int count) { @@ -15,4 +17,8 @@ public static void printSum(int x, int y) { System.out.println(x+y); } + public static void printBoolean(Boolean isStudent) + { + System.out.println("I am a student: "+ isStudent); + } } From dd370fb5e529ea69339130203386ffa02fa4314f Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 16:23:50 -0500 Subject: [PATCH 016/103] 4e --- ch04/DemoMath.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ch04/DemoMath.java diff --git a/ch04/DemoMath.java b/ch04/DemoMath.java new file mode 100644 index 0000000..a8ecc13 --- /dev/null +++ b/ch04/DemoMath.java @@ -0,0 +1,13 @@ +public class DemoMath +{ + public static void main(String[] args) + { + int abs = Math.abs(-4); + System.out.println(abs); + int max = Math.max(7,10); + System.out.println(max); + double pow = Math.pow(5.0, 6.6); + System.out.println(pow); + System.out.println(Math.PI); + } +} From dd1137766d8f2f25b21be072e6a8677830a7baae Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 19:41:47 -0500 Subject: [PATCH 017/103] 4-f --- ch04/MathUtil.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ch04/MathUtil.java diff --git a/ch04/MathUtil.java b/ch04/MathUtil.java new file mode 100644 index 0000000..d0b1ccb --- /dev/null +++ b/ch04/MathUtil.java @@ -0,0 +1,23 @@ +public class MathUtil +{ + public static void main(String[] args) + { + + printDifference(6,7); + printAbs(-1); + + } + + public static void printDifference(int a, int b) + { + int subtract = a-b; + System.out.print("The value is " +subtract); + } + + public static void printAbs(int a) + { + a = Math.abs(a); + System.out.println(" and abs value is " + a); + + } +} From 10d43cf11e0bb7e4ee3e3f84471cbb990ab170b9 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 20:00:34 -0500 Subject: [PATCH 018/103] 4-g --- ch04/BigMethodSignature.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ch04/BigMethodSignature.java diff --git a/ch04/BigMethodSignature.java b/ch04/BigMethodSignature.java new file mode 100644 index 0000000..f1142f9 --- /dev/null +++ b/ch04/BigMethodSignature.java @@ -0,0 +1,13 @@ +public class BigMethodSignature +{ + public static void main (String[] args) + { + printSum(1,2,3,4,5,6,7,8,9,11); + printSum(11,22,33,44,55,66,77,88,99,111); + } + public static void printSum(int a, int b, int c, int d, int e, int f, int g, int h, int i,int j) + { + int k = a+b+c+d+e+f+g+h+i+j; + System.out.println(k); + } +} From 28e13d67693939f25f9b1b6f4eb8ea7a5effaeb8 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 20:03:56 -0500 Subject: [PATCH 019/103] 4-g --- ch04/BigMethodSignature.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch04/BigMethodSignature.java b/ch04/BigMethodSignature.java index f1142f9..5f07e7d 100644 --- a/ch04/BigMethodSignature.java +++ b/ch04/BigMethodSignature.java @@ -7,7 +7,7 @@ public static void main (String[] args) } public static void printSum(int a, int b, int c, int d, int e, int f, int g, int h, int i,int j) { - int k = a+b+c+d+e+f+g+h+i+j; - System.out.println(k); + int k = a + b + c + d + e + f + g + h + i + j; + System.out.println("The sum is: " + k); } } From f76df0c0cb565ea15b4b79c469e8e3caf596d8ba Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 21:05:42 -0500 Subject: [PATCH 020/103] 3-3 --- ch03/TimeConverter.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ch03/TimeConverter.java diff --git a/ch03/TimeConverter.java b/ch03/TimeConverter.java new file mode 100644 index 0000000..ebbab5b --- /dev/null +++ b/ch03/TimeConverter.java @@ -0,0 +1,36 @@ +import java.util.Scanner; +/** + * Converts centimeters to feet and inches. + */ +public class TimeConverter +{ + + public static void main(String[] args) { + + + Scanner in = new Scanner(System.in); + + // prompt the user and get the value + + int seconds; + int minutes ; + int hours; + System.out.print("Enter the number of seconds : "); + seconds = in.nextInt(); + hours = seconds / 3600; + minutes = (seconds % 3600) / 60; + int secondsRemainder = (seconds % 3600) % 60; + + System.out.println(seconds + " Seconds = " + hours + " Hours " + minutes + " Minutes and " + secondsRemainder + " Seconds"); + + + /* int distributeTwenties = withdrawal / twenty; + int twentyRemainder = withdrawal % twenty; + int distributeTen = twentyRemainder / ten; + int tenRemainder = twentyRemainder % ten; + int distributeFive = tenRemainder / five; + int fiveRemainder = tenRemainder % five; + int distributeOne = fiveRemainder / one;*/ + } + +} From 77333b15356f9010fd408b8fece343097eec1563 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 21:08:51 -0500 Subject: [PATCH 021/103] 3-3 --- ch03/TimeConverter.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ch03/TimeConverter.java b/ch03/TimeConverter.java index ebbab5b..79012e9 100644 --- a/ch03/TimeConverter.java +++ b/ch03/TimeConverter.java @@ -23,14 +23,6 @@ public static void main(String[] args) { System.out.println(seconds + " Seconds = " + hours + " Hours " + minutes + " Minutes and " + secondsRemainder + " Seconds"); - - /* int distributeTwenties = withdrawal / twenty; - int twentyRemainder = withdrawal % twenty; - int distributeTen = twentyRemainder / ten; - int tenRemainder = twentyRemainder % ten; - int distributeFive = tenRemainder / five; - int fiveRemainder = tenRemainder % five; - int distributeOne = fiveRemainder / one;*/ } } From d90d7f7b1feb3290ce1cf82f7db7ea4fd70ea470 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 21:27:07 -0500 Subject: [PATCH 022/103] 3-4 --- ch03/GuessStarter.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java index 64984df..8d52862 100644 --- a/ch03/GuessStarter.java +++ b/ch03/GuessStarter.java @@ -1,5 +1,5 @@ import java.util.Random; - +import java.util.Scanner; /** * Starter code for the "Guess My Number" exercise. */ @@ -8,8 +8,16 @@ public class GuessStarter { public static void main(String[] args) { // pick a random number Random random = new Random(); + Scanner in = new Scanner(System.in); int number = random.nextInt(100) + 1; - System.out.println(number); + System.out.println("I'm thinking of a number between 1 and 100: "); + System.out.println("Can you guess what it is? "); + int guess = in.nextInt(); + System.out.println("Your Guess is " + guess); + System.out.println(); + System.out.println("The number I was thinking of was "+number); + int difference = guess - number; + System.out.println("You were off by "+ Math.abs(difference)); } } From 444ad4eb609be062e366085365587ec8fd3e4f96 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 18 Apr 2018 21:56:26 -0500 Subject: [PATCH 023/103] 3-ES-1 --- ch03/Escape.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ch03/Escape.java diff --git a/ch03/Escape.java b/ch03/Escape.java new file mode 100644 index 0000000..ef9fd93 --- /dev/null +++ b/ch03/Escape.java @@ -0,0 +1,15 @@ +public class Escape +{ + public static void main(String[] args) + { + String header = "\n\tNEWYORK 3-DAY FORCAST:\n"; + header += "\n\tDay\t\tHigh\tLow\tConditions\n" ; + header += "\t---\t\t----\t---\t----------\n" ; + + String forecast = "\tSunday\t\t68F\t48F\tSunny\n" ; + forecast += "\tMonday\t\t69F\t57F\tSunny\n" ; + forecast += "\tTuesday\t\t71F\t50F\tCloudy\n" ; + + System.out.println(header + forecast); + } +} From 270e9a56e9d7658524e1046b78c1f6a3af7c3e13 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 10:02:17 -0500 Subject: [PATCH 024/103] 4-g --- ch04/SimpleMethods.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java index 76622c8..bdee7fb 100644 --- a/ch04/SimpleMethods.java +++ b/ch04/SimpleMethods.java @@ -8,16 +8,18 @@ public static void main (String[] args) printBoolean(true); printBoolean(false); } - public static void printCount(int count) + private static void printCount(int count) { System.out.println("The count is: " + count); } - public static void printSum(int x, int y) + private static void printSum(int x, int y) { - System.out.println(x+y); + int sum= x+y; + System.out.println(x + "+" + y); + System.out.println(x+"+"+y+"="+sum); } - public static void printBoolean(Boolean isStudent) + private static void printBoolean(Boolean isStudent) { System.out.println("I am a student: "+ isStudent); } From 944b529e2b8b26c20158fc5d0836719f739952bc Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 11:36:45 -0500 Subject: [PATCH 025/103] 5-es-1 --- ch05/Comparision.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ch05/Comparision.java diff --git a/ch05/Comparision.java b/ch05/Comparision.java new file mode 100644 index 0000000..98c99e5 --- /dev/null +++ b/ch05/Comparision.java @@ -0,0 +1,18 @@ +public class Comparision +{ + 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 result + System.out.println("String Inequality 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); + } +} From 75e969d318ec5169c072d510537490deb3d9aacb Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 11:37:08 -0500 Subject: [PATCH 026/103] 5-es-1 --- ch05/Condition.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ch05/Condition.java diff --git a/ch05/Condition.java b/ch05/Condition.java new file mode 100644 index 0000000..de112d4 --- /dev/null +++ b/ch05/Condition.java @@ -0,0 +1,13 @@ +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)); + } +} From c46674b4aa559883f33e46320cfec3c9a1073f05 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 11:37:33 -0500 Subject: [PATCH 027/103] 5-es-1 --- ch05/Logic.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ch05/Logic.java diff --git a/ch05/Logic.java b/ch05/Logic.java new file mode 100644 index 0000000..dead234 --- /dev/null +++ b/ch05/Logic.java @@ -0,0 +1,15 @@ +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("Origiona Yes Value: "+ yes); + System.out.println("Inverse Yes Value: "+ !yes); + } +} From 09bd96b5722f337392a22ef162b11619c60cc403 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 11:37:49 -0500 Subject: [PATCH 028/103] 5-es-1 --- ch05/Precedence.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch05/Precedence.java diff --git a/ch05/Precedence.java b/ch05/Precedence.java new file mode 100644 index 0000000..e9df31b --- /dev/null +++ b/ch05/Precedence.java @@ -0,0 +1,12 @@ +public class Precedence +{ + public static void main( String[] args) + { + int sum = 32 - 8 + 16 *2; //16x32 +, +24 = 56 + System.out.println("Default order: "+ sum); + sum = (32-8+16)*2; //24+16=40,x2=80 + System.out.println("Specified order: "+ sum); + sum =(32 - (8+16)) *2; //32-24=8, * 2 =16 + System.out.println("Nested Specific order: "+ sum); + } +} From b6f4cdb53178a2b1b57c80eda787a5c8622b95a8 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 12:44:29 -0500 Subject: [PATCH 029/103] 5-es-1 --- ch05/If.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ch05/If.java diff --git a/ch05/If.java b/ch05/If.java new file mode 100644 index 0000000..ebff57a --- /dev/null +++ b/ch05/If.java @@ -0,0 +1,13 @@ +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."); + } + + } +} From 81568948351ca9105d5cca0bb3dd004d8ff31a12 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 12:49:31 -0500 Subject: [PATCH 030/103] 5-es-1 --- ch05/If.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ch05/If.java b/ch05/If.java index ebff57a..2ee719c 100644 --- a/ch05/If.java +++ b/ch05/If.java @@ -7,6 +7,9 @@ public static void main (String[] args) { System.out.println("Two is less than four."); System.out.println("Test succeeded."); + int num =10; + if(((num > 5)&&(num < 10))||(num == 12)) + System.out.println("Number is 6-9 inclusive, or 12"); } } From 3f6a525e39aea8c3698690ea0005fca400e312f2 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 14:49:51 -0500 Subject: [PATCH 031/103] 5 a - d --- ch05/LogicMethods.java | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ch05/LogicMethods.java diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java new file mode 100644 index 0000000..103fab0 --- /dev/null +++ b/ch05/LogicMethods.java @@ -0,0 +1,76 @@ +public class LogicMethods +{ + public static void main(String[] args) + { + printIsLarge(101); + printIsLargeOrSmall(6); + printLargest(10 ,10); + printLargestOdd(5,5); + } + public static void printIsLarge(int number) + { + if (number > 99) + { + System.out.println("The number is large"); + } + } + public static void printIsLargeOrSmall(int number) + { + if (number > 99 ) + { + System.out.println("The number is large"); + } + else if (number < 10) + { + System.out.println("The number is small"); + } + } + public static void printLargest(int number1, int number2) + { + int value; + if(number1 > number2) + { + value= number1; + System.out.println("The largest number is: " + value); + } + else if (number1 < number2) + { + value = number2; + System.out.println("the largest number is: "+value); + + } + else System.out.println("The two numbers are equal"); + } + public static void printLargestOdd(int number1, int number2) + { + int value; + if ((number1 % 2 != 0) && number1 > number2) + { + + value = number1; + System.out.println("The larges odd number is: "+ value ); + } + else if ((number2 % 2 != 0) && number2 > number1) + { + value = number2; + System.out.println("The largest odd number is: "+ value ); + } + else if ((number1 % 2 == 0) && (number2 % 2 ==0)) + { + System.out.println("Neither number is odd"); + } + + + if ((number1 % 2 != 0) && (number2 % 2 != 0 )) + { + System.out.println("Two odds make an even"); + + if ((number1 % 2 != 0) && (number2 % 2 != 0 && (number1 == number2))) + { + int sum = number1 + number2; + System.out.println("The Sum of the two odds are: " + sum); + } + } + } + +} From 11084e6cb29bf7eccebd14047a7162154dc6f644 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 15:59:46 -0500 Subject: [PATCH 032/103] 5-e --- ch05/SwitchExample.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ch05/SwitchExample.java diff --git a/ch05/SwitchExample.java b/ch05/SwitchExample.java new file mode 100644 index 0000000..a307a4a --- /dev/null +++ b/ch05/SwitchExample.java @@ -0,0 +1,27 @@ + class SwitchExample +{ + public static void main(String[] args) + { + lastNameWinner("Lazenby"); + } + + public static void lastNameWinner(String lastName) + { + switch (lastName ) + { + case "smith": + System.out.println("Congratulations, grand winner");break; + case "jones": + System.out.println("Congratulations, grand winner");break; + + case "Lazenby": + System.out.println("Hey, he owes me dinner");break; + default: + System.out.println("Sorry, not a winner"); + + + } + } +} + + From 5c1a00a7903816d30fe090209774175423317726 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 18:46:03 -0500 Subject: [PATCH 033/103] 5-es-1 --- ch05/Else.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ch05/Else.java diff --git a/ch05/Else.java b/ch05/Else.java new file mode 100644 index 0000000..80175f7 --- /dev/null +++ b/ch05/Else.java @@ -0,0 +1,16 @@ +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); + } +} From 41142dca3121e785548202fc415bf8ddd6bab167 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 18:55:35 -0500 Subject: [PATCH 034/103] 5-es-1 --- ch05/Switch.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ch05/Switch.java diff --git a/ch05/Switch.java b/ch05/Switch.java new file mode 100644 index 0000000..0c1bc3e --- /dev/null +++ b/ch05/Switch.java @@ -0,0 +1,17 @@ +public class Switch +{ + public static void main (String[] args) + { + int month = 2; + int year = 2018; + int num = 31; + + switch (month) + { + case 4: case 6: case 11: num = 30 ;break; + case 2: num = (year % 4== 0)? 29: 28; break; + + } + System.out.println(month + "/" + year + ":" + num + " days"); + } +} From bc6b06602f4fd7de287a172c384b0117d4d39a0c Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 19:26:40 -0500 Subject: [PATCH 035/103] 5 - E & D --- ch05/SwitchExample.java | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/ch05/SwitchExample.java b/ch05/SwitchExample.java index a307a4a..88269bf 100644 --- a/ch05/SwitchExample.java +++ b/ch05/SwitchExample.java @@ -1,26 +1,51 @@ - class SwitchExample +class SwitchExample { public static void main(String[] args) { lastNameWinner("Lazenby"); + dayOfWeek(100); } public static void lastNameWinner(String lastName) { - switch (lastName ) + switch (lastName) { case "smith": - System.out.println("Congratulations, grand winner");break; + System.out.println("Congratulations, grand winner"); + break; case "jones": - System.out.println("Congratulations, grand winner");break; + System.out.println("Congratulations, grand winner"); + break; case "Lazenby": - System.out.println("Hey, he owes me dinner");break; + System.out.println("Hey, he owes me dinner"); + break; default: - System.out.println("Sorry, not a winner"); + System.out.println("Sorry, not a winner"); + } + } + public static void dayOfWeek(int day) + { + switch (day) + { + case 1: + System.out.println("Sunday");break; + case 2: + System.out.println("Monday");break; + case 3: + System.out.println("Tuesday");break; + case 4: + System.out.println("Wednesday");break; + case 5: + System.out.println("Thursday");break; + case 6: + System.out.println("Friday");break; + case 7: + System.out.println("Saturday");break; } + System.out.println("Invalid value: X"); } } From 9c350196f44c7456e525a74fdf58b61cd503b30e Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 21:04:39 -0500 Subject: [PATCH 036/103] 5-g silver --- ch05/CrazyEdsWholesaleStringCheese.java | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ch05/CrazyEdsWholesaleStringCheese.java diff --git a/ch05/CrazyEdsWholesaleStringCheese.java b/ch05/CrazyEdsWholesaleStringCheese.java new file mode 100644 index 0000000..3296324 --- /dev/null +++ b/ch05/CrazyEdsWholesaleStringCheese.java @@ -0,0 +1,77 @@ +import java.util.Scanner; + +public class CrazyEdsWholesaleStringCheese +{ + + public static void main(String[] args) + { + int size; + int amount; + Scanner in = new Scanner(System.in); + + System.out.println("Crazy Ed's Wholesale String Cheese offers"); + System.out.println("1 in, 2 in or 3 in, diameter string cheese"); + System.out.println("Limit: one size per order"); + System.out.println("What size cheese would you like to order? "); + + size = in.nextInt(); + if (size > 3) + { + System.out.println("Your order is too crazy, Please try a different size!"); + } else + { + System.out.println("How many yards would you like to order?"); + amount = in.nextInt(); + System.out.println("You ordered: " + amount + " yards of " + size + " inch thick string cheese."); + + + switch (size) + { + case 1: + int price1 = 2; + int shipping1 = 2; + int withoutShipping = amount * price1; + int withShipping = (amount * price1) + shipping1; + if (amount > 50) + { + System.out.println("Your total cost will be $ " + withoutShipping); + } else + { + System.out.println("Your total cost will be $ " + withShipping); + } + + case 2: + int price2 = 4; + int shipping2 = 2; + withoutShipping = amount * price2; + withShipping = (amount * price2) + shipping2; + if (amount > 50) + { + System.out.println("Your total cost will be $ " + withoutShipping); + } else + { + System.out.println("Your total cost will be $ " + withShipping); + } + + case 3: + int price3 = 6; + int shipping3 = 4; + withoutShipping = amount * price3; + withShipping = (amount * price3) + shipping3; + if (amount > 50) + { + System.out.println("Your total cost will be $ " + withoutShipping); + } else + { + System.out.println("Your total cost will be $ " + withShipping); + } + + } + + + } + } +} + + + From 22de8c6a138a8be781c069c47dc50c370ff0e0b6 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 21:26:24 -0500 Subject: [PATCH 037/103] 5-g silver --- ch05/CrazyEdsWholesaleStringCheese.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ch05/CrazyEdsWholesaleStringCheese.java b/ch05/CrazyEdsWholesaleStringCheese.java index 3296324..b5002fc 100644 --- a/ch05/CrazyEdsWholesaleStringCheese.java +++ b/ch05/CrazyEdsWholesaleStringCheese.java @@ -18,7 +18,8 @@ public static void main(String[] args) if (size > 3) { System.out.println("Your order is too crazy, Please try a different size!"); - } else + } + else { System.out.println("How many yards would you like to order?"); amount = in.nextInt(); @@ -65,10 +66,7 @@ public static void main(String[] args) { System.out.println("Your total cost will be $ " + withShipping); } - } - - } } } From 662e10859fa7d4eb95a5572c58fdd7d0d61a587f Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 19 Apr 2018 23:38:10 -0500 Subject: [PATCH 038/103] 5-g silver over achiever --- ch05/CrazyEdsWholesaleStringCheese.java | 59 ++++++++++++++++++++----- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/ch05/CrazyEdsWholesaleStringCheese.java b/ch05/CrazyEdsWholesaleStringCheese.java index b5002fc..c88b2e7 100644 --- a/ch05/CrazyEdsWholesaleStringCheese.java +++ b/ch05/CrazyEdsWholesaleStringCheese.java @@ -33,12 +33,23 @@ public static void main(String[] args) int shipping1 = 2; int withoutShipping = amount * price1; int withShipping = (amount * price1) + shipping1; - if (amount > 50) + if ((amount >= 50) && (size == 1)) { - System.out.println("Your total cost will be $ " + withoutShipping); - } else + String header ="\n\tITEMIZED INVOICE:\n" ; + header += "\n\tSize\tCost\tAmount\tTotal\n"; + header += "\n\t----\t----\t------\t-----\n"; + String invoice = "\n\t|"+size+"in |\t| $"+price1+" | \t| "+amount+" |\t| $"+withoutShipping+" |\n"; + System.out.println(header + invoice); + //System.out.println("Your total cost will be $ " + withoutShipping); + } + else if ((amount < 50)&& (size == 1)) { - System.out.println("Your total cost will be $ " + withShipping); + String header ="\n\tITEMIZED INVOICE:\n" ; + header += "\n\tSize\tCost\tAmount\tshipping\tTotal\n"; + header += "\n\t----\t----\t------\t--------\t-----\n"; + String invoice = "\n\t|"+size+"in |\t| $"+price1+" | \t| "+amount+" |\t| $ "+shipping1+" |\t\t| $"+withShipping+" |\n"; + System.out.println(header + invoice); + //System.out.println("Your total cost will be $ " + withShipping); } case 2: @@ -46,12 +57,24 @@ public static void main(String[] args) int shipping2 = 2; withoutShipping = amount * price2; withShipping = (amount * price2) + shipping2; - if (amount > 50) + + if ((amount >= 75)&&(size ==2)) { - System.out.println("Your total cost will be $ " + withoutShipping); - } else + String header2 ="\n\tITEMIZED INVOICE:\n" ; + header2 += "\n\t Size\t Cost\t Amount\t Total\n"; + header2 += "\n\t ----\t ----\t ------\t -----\n"; + String invoice2 = "\n\t| "+size+"in|\t| $"+price2+" | \t| "+amount+" |\t| $"+withoutShipping+" |\n"; + System.out.println(header2 + invoice2); + //System.out.println("Your total cost will be $ " + withoutShipping); + } + else if ((amount < 75)&&(size == 2)) { - System.out.println("Your total cost will be $ " + withShipping); + String header2 ="\n\tITEMIZED INVOICE:\n" ; + header2 += "\n\t ize\tCost\tAmount\tshipping\tTotal\n"; + header2 += "\n\t----\t ----\t------\t--------\t-----\n"; + String invoice2 = "\n\t|"+size+"in |\t| $"+price2+" | \t| "+amount+"|\t| $ "+shipping2+"|\t\t| $"+withShipping+" |\n"; + System.out.println(header2 + invoice2); + //System.out.println("Your total cost will be $ " + withShipping); } case 3: @@ -59,12 +82,24 @@ public static void main(String[] args) int shipping3 = 4; withoutShipping = amount * price3; withShipping = (amount * price3) + shipping3; - if (amount > 50) + + if ((amount >= 25)&&(size ==3)) { - System.out.println("Your total cost will be $ " + withoutShipping); - } else + String header3 ="\n\tITEMIZED INVOICE:\n" ; + header3 += "\n\tSize\t Cost\tAmount\tTotal\n"; + header3 += "\n\t----\t ----\t------\t-----\n"; + String invoice3 = "\n\t| "+size+"in |\t| $"+price3+" | \t| "+amount+" |\t| $"+withoutShipping+" |\n"; + System.out.println(header3 + invoice3); + //System.out.println("Your total cost will be $ " + withoutShipping); + } + else if ((amount < 25)&&(size ==3)) { - System.out.println("Your total cost will be $ " + withShipping); + String header3 ="\n\tITEMIZED INVOICE:\n" ; + header3 += "\n\tSize\tCost\tAmount\tshipping\tTotal\n"; + header3 += "\n\t----\t----\t------\t--------\t-----\n"; + String invoice3 = "\n\t| "+size+"in |\t| $"+price3+" | \t| "+amount+"\t| $ "+shipping3+" |\t\t| $ "+withShipping+" |\n"; + System.out.println(header3 + invoice3); + //System.out.println("Your total cost will be $ " + withShipping); } } } From bc8c65ec4a1ad1e57831a2f46c1d2ff64ea4e2b5 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 02:37:27 -0500 Subject: [PATCH 039/103] 6-2 --- ch06/Divisible.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch06/Divisible.java diff --git a/ch06/Divisible.java b/ch06/Divisible.java new file mode 100644 index 0000000..3d402ef --- /dev/null +++ b/ch06/Divisible.java @@ -0,0 +1,22 @@ +public class Divisible +{ + +public static void main(String[] args) +{ + + + System.out.println(isDivisible(10,2)); + +} +public static boolean isDivisible(int n, int m) +{ + if(n%m==0) + { + return true; + } + else + { + return false; + } +} + } From 43de30fa8a1dcc0eb84e89e6f765bec236c67067 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 03:10:38 -0500 Subject: [PATCH 040/103] 6-3 --- ch06/isTriangle.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ch06/isTriangle.java diff --git a/ch06/isTriangle.java b/ch06/isTriangle.java new file mode 100644 index 0000000..7c5a210 --- /dev/null +++ b/ch06/isTriangle.java @@ -0,0 +1,24 @@ +public class isTriangle +{ + public static void main(String[]args) + { + System.out.println(isTriangle(5,10,5)); + } + + //Can Create Triangle? + public static boolean isTriangle(int left, int right, int bottom) + { + boolean noTriangle = false; + boolean yesTriangle = true; + // If any of the sides is > than the sum of the other two = no triangle + if( (bottom > left + right) || ( right > bottom + left ) || (left > bottom + right) ) + { + return noTriangle; + } + else + { + return yesTriangle; + } + + } +} From 170f404e601d2bd131814e1017073f018d7d36cd Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 03:12:56 -0500 Subject: [PATCH 041/103] 6-2 --- ch06/isDivisible.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch06/isDivisible.java diff --git a/ch06/isDivisible.java b/ch06/isDivisible.java new file mode 100644 index 0000000..3b89fa3 --- /dev/null +++ b/ch06/isDivisible.java @@ -0,0 +1,22 @@ +public class isDivisible +{ + + public static void main(String[] args) + { + + + System.out.println(isDivisible(4, 2)); + + } + + public static boolean isDivisible(int n, int m) + { + if (n % m == 0) + { + return true; + } else + { + return false; + } + } +} From b6963ac2368af59a26694ea5b56f84bfb4a20bf0 Mon Sep 17 00:00:00 2001 From: tjheckler <38469447+tjheckler@users.noreply.github.com> Date: Sat, 21 Apr 2018 03:14:01 -0500 Subject: [PATCH 042/103] Delete Divisible.java --- ch06/Divisible.java | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 ch06/Divisible.java diff --git a/ch06/Divisible.java b/ch06/Divisible.java deleted file mode 100644 index 3d402ef..0000000 --- a/ch06/Divisible.java +++ /dev/null @@ -1,22 +0,0 @@ -public class Divisible -{ - -public static void main(String[] args) -{ - - - System.out.println(isDivisible(10,2)); - -} -public static boolean isDivisible(int n, int m) -{ - if(n%m==0) - { - return true; - } - else - { - return false; - } -} - } From 460fb4c73403d5f0b93a48b16328297d935fadae Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 03:31:26 -0500 Subject: [PATCH 043/103] 6-4, steps 1-3 --- ch06/Multadd.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ch06/Multadd.java diff --git a/ch06/Multadd.java b/ch06/Multadd.java new file mode 100644 index 0000000..50b5433 --- /dev/null +++ b/ch06/Multadd.java @@ -0,0 +1,16 @@ +public class Multadd +{ + public static void main (String[] args) + { + System.out.println(Multadd(1,2,3)); + } + + public static double Multadd(double a, double b, double c) + { + double math = a*b +c; + return math; + } + + //I started to look at step 4 and said to myself... not that smart + // ... couldn't attempt if it was required +} From a9dda5cf3862a569494c561fbc376b36fd97aab0 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 03:43:13 -0500 Subject: [PATCH 044/103] 6-b --- ch06/MathUtil.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch06/MathUtil.java diff --git a/ch06/MathUtil.java b/ch06/MathUtil.java new file mode 100644 index 0000000..cd7ee24 --- /dev/null +++ b/ch06/MathUtil.java @@ -0,0 +1,25 @@ +public class MathUtil +{ + public static void main(String[] args) + { + System.out.println(absoluteSum(12,12)); + System.out.println(absoluteSum(12,12,-12)); + } + + public static int absoluteSum(int a, int b) + { + int absa = Math.abs(a); + int absb = Math.abs(b); + int absSum = absa + absb; + return absSum; + } + public static int absoluteSum(int a, int b, int c) + { + int absa = Math.abs(a); + int absb = Math.abs(b); + int absc = Math.abs(c); + int absSum = absa + absb + absc; + return absSum; + } + +} From 746a58a2ae7bdc453b2f9f338ebe4f7d8f34d4cc Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 04:42:09 -0500 Subject: [PATCH 045/103] 5-g silver --- ch05/CrazyEdsWholesaleStringCheese.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ch05/CrazyEdsWholesaleStringCheese.java b/ch05/CrazyEdsWholesaleStringCheese.java index c88b2e7..bbfd570 100644 --- a/ch05/CrazyEdsWholesaleStringCheese.java +++ b/ch05/CrazyEdsWholesaleStringCheese.java @@ -70,9 +70,9 @@ else if ((amount < 50)&& (size == 1)) else if ((amount < 75)&&(size == 2)) { String header2 ="\n\tITEMIZED INVOICE:\n" ; - header2 += "\n\t ize\tCost\tAmount\tshipping\tTotal\n"; + header2 += "\n\t Size\tCost\tAmount\tShipping\tTotal\n"; header2 += "\n\t----\t ----\t------\t--------\t-----\n"; - String invoice2 = "\n\t|"+size+"in |\t| $"+price2+" | \t| "+amount+"|\t| $ "+shipping2+"|\t\t| $"+withShipping+" |\n"; + String invoice2 = "\n\t|"+size+"in |\t| $"+price2+" | \t| "+amount+" |\t| $ "+shipping2+"|\t\t| $"+withShipping+" |\n"; System.out.println(header2 + invoice2); //System.out.println("Your total cost will be $ " + withShipping); } @@ -95,9 +95,9 @@ else if ((amount < 75)&&(size == 2)) else if ((amount < 25)&&(size ==3)) { String header3 ="\n\tITEMIZED INVOICE:\n" ; - header3 += "\n\tSize\tCost\tAmount\tshipping\tTotal\n"; + header3 += "\n\tSize\tCost\tAmount\tShipping\tTotal\n"; header3 += "\n\t----\t----\t------\t--------\t-----\n"; - String invoice3 = "\n\t| "+size+"in |\t| $"+price3+" | \t| "+amount+"\t| $ "+shipping3+" |\t\t| $ "+withShipping+" |\n"; + String invoice3 = "\n\t| "+size+"in |\t| $"+price3+" | \t| "+amount+" |\t | $ "+shipping3+" |\t\t| $ "+withShipping+" |\n"; System.out.println(header3 + invoice3); //System.out.println("Your total cost will be $ " + withShipping); } From 3bf46f9fbd324c757b4ab393c639a0b44f675c79 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 21 Apr 2018 23:40:35 -0500 Subject: [PATCH 046/103] 5-h(gold) --- ch05/TicketNumber.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ch05/TicketNumber.java diff --git a/ch05/TicketNumber.java b/ch05/TicketNumber.java new file mode 100644 index 0000000..6b349de --- /dev/null +++ b/ch05/TicketNumber.java @@ -0,0 +1,28 @@ +import java.util.Scanner; +public class TicketNumber +{ + + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + System.out.println("Enter 6 digit ticket number: "); + int ticketNumber = in.nextInt(); + int lastDigit = ticketNumber%10; + int prefix = ticketNumber / 10; + int remainder = prefix % 7; + boolean result = lastDigit == remainder; + + + if(result == true) + { + System.out.println(ticketNumber + " Is a good number"); + } + else + { + System.out.println("Bad Number, Try again"); + } + + + } + +} From 968fc54e6e099eb5ffe181c3b3378ebf1d2262fa Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 10:52:26 -0500 Subject: [PATCH 047/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 ch05/GreenCoffeeGrowers.java diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java new file mode 100644 index 0000000..1a0758a --- /dev/null +++ b/ch05/GreenCoffeeGrowers.java @@ -0,0 +1,93 @@ +import java.util.Scanner; + +public class GreenCoffeeGrowers +{ + public static void main(String[] args) + { + int commute; + int miles; + + + Scanner in = new Scanner(System.in); + + System.out.println("Do you commute by bus bike or car? Enter: true or false"); + System.out.println("Please type (1) for bus, (2) for bike, (3) for car, or (4) to proceed to checkout "); + commute = in.nextInt(); + System.out.println("How many miles? "); + miles = in.nextInt(); + + + if (commute > 4) + { + System.out.println("Invalid Selection, Please Try again!"); + } else + { + switch (commute) + { + + case 1: + if (commute == 1) + { + if (miles < 21) + { + System.out.println("You receive a free coffee"); + } + else if (miles < 35 && miles >= 21) + { + System.out.println("You receive a free coffee and a 20% discount"); + } + else if (miles <= 50 && miles >= 35) + { + System.out.println("You receive a free coffee and a 30% discount"); + } + + else if (miles > 50) + { + System.out.println("You receive a free coffee and 50% discount"); + } + + } + + case 2: + if (commute == 2) + { + if (miles < 21) + { + System.out.println("You receive a free coffee"); + } + else if (miles > 21 && miles < 30) + { + System.out.println("You receive a free coffee"); + } + else if (miles > 30 && miles < 50) + { + System.out.println("You receive a free coffee and a 10% discount"); + } + else if (miles < 50 && miles >= 31) + { + System.out.println("You receive a free coffee and a 20% discount"); + } + + else if (miles >= 50) + { + System.out.println("You receive a free coffee and 30% discount"); + } + + } + case 3: + if (commute == 3) + { + if (miles < 21) + { + System.out.println("You receive a free coffee"); + } + } + case 4: + System.out.println("Your Total is... "); + } + } //Rest of Program + + + } + +} From bebfce48182621804324c536512c030b9f43bd5d Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 11:02:53 -0500 Subject: [PATCH 048/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 1a0758a..6b0d9bd 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -11,7 +11,7 @@ public static void main(String[] args) Scanner in = new Scanner(System.in); System.out.println("Do you commute by bus bike or car? Enter: true or false"); - System.out.println("Please type (1) for bus, (2) for bike, (3) for car, or (4) to proceed to checkout "); + System.out.println("Please type (1) for bus, (2) for bike, (3) for car, or (4) Don't commute, proceed to checkout "); commute = in.nextInt(); System.out.println("How many miles? "); miles = in.nextInt(); @@ -24,7 +24,7 @@ public static void main(String[] args) { switch (commute) { - + //Bus commute case 1: if (commute == 1) { @@ -32,11 +32,11 @@ public static void main(String[] args) { System.out.println("You receive a free coffee"); } - else if (miles < 35 && miles >= 21) + else if (miles >= 21 && miles < 35 ) { System.out.println("You receive a free coffee and a 20% discount"); } - else if (miles <= 50 && miles >= 35) + else if (miles >= 35 && miles <= 50 ) { System.out.println("You receive a free coffee and a 30% discount"); } @@ -48,6 +48,7 @@ else if (miles > 50) } + //Bike commute case 2: if (commute == 2) { @@ -55,15 +56,12 @@ else if (miles > 50) { System.out.println("You receive a free coffee"); } - else if (miles > 21 && miles < 30) - { - System.out.println("You receive a free coffee"); - } - else if (miles > 30 && miles < 50) + else if (miles > 21 && miles <= 30) { System.out.println("You receive a free coffee and a 10% discount"); } - else if (miles < 50 && miles >= 31) + + else if (miles >= 31 && miles < 50) { System.out.println("You receive a free coffee and a 20% discount"); } @@ -74,6 +72,8 @@ else if (miles >= 50) } } + + //Trick question? you said EVERYONE included car case 3: if (commute == 3) { @@ -82,6 +82,7 @@ else if (miles >= 50) System.out.println("You receive a free coffee"); } } + //Chose not to take discount or doesn't commute case 4: System.out.println("Your Total is... "); } From 585db373a3a6dbf64479160b02cfe932f4e7d58d Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 14:19:26 -0500 Subject: [PATCH 049/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 6b0d9bd..72f4fe0 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -10,7 +10,7 @@ public static void main(String[] args) Scanner in = new Scanner(System.in); - System.out.println("Do you commute by bus bike or car? Enter: true or false"); + System.out.println("How do you commute?"); System.out.println("Please type (1) for bus, (2) for bike, (3) for car, or (4) Don't commute, proceed to checkout "); commute = in.nextInt(); System.out.println("How many miles? "); From 4364c4a6bd5f112ef21cea964a3c307950fd9b63 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 14:21:55 -0500 Subject: [PATCH 050/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 72f4fe0..16c666d 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -17,7 +17,7 @@ public static void main(String[] args) miles = in.nextInt(); - if (commute > 4) + if (commute > 4 || commute < 1) { System.out.println("Invalid Selection, Please Try again!"); } else From c0ba3e3ff7b2d70474dfa1ae68bcc7d5ffb40f86 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 14:26:51 -0500 Subject: [PATCH 051/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 16c666d..911959c 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -81,6 +81,10 @@ else if (miles >= 50) { System.out.println("You receive a free coffee"); } + else + { + System.out.println("Your Total is... "); + } } //Chose not to take discount or doesn't commute case 4: From 923096ea6130b67cfe4bce2572c9b7196289092b Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 14:38:30 -0500 Subject: [PATCH 052/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 911959c..3028b16 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -20,7 +20,7 @@ public static void main(String[] args) if (commute > 4 || commute < 1) { System.out.println("Invalid Selection, Please Try again!"); - } else + } else if (commute > 4) { switch (commute) { @@ -81,17 +81,22 @@ else if (miles >= 50) { System.out.println("You receive a free coffee"); } - else + else if (miles >= 21) { System.out.println("Your Total is... "); } } //Chose not to take discount or doesn't commute - case 4: + case 4: if (miles >0) + { System.out.println("Your Total is... "); + } } } //Rest of Program - +else + { + System.out.println("Your Total is... "); + } } From e6513d050965406c5fec960ed052ab629516a8b7 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 22 Apr 2018 14:56:02 -0500 Subject: [PATCH 053/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 3028b16..1002b67 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -5,7 +5,7 @@ public class GreenCoffeeGrowers public static void main(String[] args) { int commute; - int miles; + int miles; Scanner in = new Scanner(System.in); @@ -20,7 +20,7 @@ public static void main(String[] args) if (commute > 4 || commute < 1) { System.out.println("Invalid Selection, Please Try again!"); - } else if (commute > 4) + } else if (commute < 4) { switch (commute) { @@ -28,7 +28,7 @@ public static void main(String[] args) case 1: if (commute == 1) { - if (miles < 21) + if (miles < 21&& miles > 0) { System.out.println("You receive a free coffee"); } @@ -52,7 +52,7 @@ else if (miles > 50) case 2: if (commute == 2) { - if (miles < 21) + if (miles < 21 && miles < 0) { System.out.println("You receive a free coffee"); } @@ -77,7 +77,7 @@ else if (miles >= 50) case 3: if (commute == 3) { - if (miles < 21) + if (miles < 21 && miles > 0) { System.out.println("You receive a free coffee"); } @@ -87,10 +87,15 @@ else if (miles >= 21) } } //Chose not to take discount or doesn't commute - case 4: if (miles >0) + case 4: + if ( miles >= 0) { System.out.println("Your Total is... "); } + else + { + System.out.println("Invalid selection! Pssst! you cant travel negative miles no matter the direction, Try again."); + } } } //Rest of Program else From 04f672f04ddfb2a2905b90cdc2244c9435f8c5f1 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 10:08:55 -0500 Subject: [PATCH 054/103] 5-I gold --- ch05/GreenCoffeeGrowers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch05/GreenCoffeeGrowers.java b/ch05/GreenCoffeeGrowers.java index 1002b67..90d6967 100644 --- a/ch05/GreenCoffeeGrowers.java +++ b/ch05/GreenCoffeeGrowers.java @@ -20,7 +20,7 @@ public static void main(String[] args) if (commute > 4 || commute < 1) { System.out.println("Invalid Selection, Please Try again!"); - } else if (commute < 4) + } else if (commute <= 4) { switch (commute) { From d7d9b2cbc1d3062055f84f3b5c8b49d52b41c885 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 12:24:56 -0500 Subject: [PATCH 055/103] 7-es-1 step 1 --- ch07/While.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch07/While.java diff --git a/ch07/While.java b/ch07/While.java new file mode 100644 index 0000000..05d3021 --- /dev/null +++ b/ch07/While.java @@ -0,0 +1,12 @@ +public class While +{ + public static void main(String[] args) + { + int num = 100; + while(num > 0) + { + System.out.println("While Countdown: " + num); + num -=10 ; + } + } +} From 106ffa8fbf07ec731a8efcb4e74c5bbf13839862 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 12:32:12 -0500 Subject: [PATCH 056/103] 7-es-1 step 2 --- ch07/DoWhile.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ch07/DoWhile.java diff --git a/ch07/DoWhile.java b/ch07/DoWhile.java new file mode 100644 index 0000000..ab701fb --- /dev/null +++ b/ch07/DoWhile.java @@ -0,0 +1,14 @@ +public class DoWhile +{ + public static void main(String[] args) + { + int num = 100; + do + { + System.out.println("DoWhile Countup: "+ num); + num+=10; + } + while(num < 10); + + } +} From 5a5ce01824245b13ac62cd191dfe94219d0d44d5 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 12:52:40 -0500 Subject: [PATCH 057/103] 7-es-1 step 3 --- 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..99860ed --- /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("\t Inner Loop j = " + j); + System.out.println( "\t\t Total num = " +(++num)); + } + } + } +} + From 51d78646ac8d73b1a3057de3808d9e82a979243a Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 13:30:23 -0500 Subject: [PATCH 058/103] 7-A --- ch07/ForWhileDoWhile.java | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ch07/ForWhileDoWhile.java diff --git a/ch07/ForWhileDoWhile.java b/ch07/ForWhileDoWhile.java new file mode 100644 index 0000000..e688ce9 --- /dev/null +++ b/ch07/ForWhileDoWhile.java @@ -0,0 +1,56 @@ +public class ForWhileDoWhile +{ + public static void main(String[] args) + { + + forLoop(0); + While(10); + DoWhile(0,10); + } + public static void forLoop (int i) + { + + + for (i = 1; i <= 10; i++) + { + System.out.println(" Count up i = " + i); + + } + for (i = 10; i >= 1; i--) + { + System.out.println(" Count down = " + i); + + } + } + public static void While(int num) + { + + while(num >=1) + { + System.out.println("While Countdown: " + num); + num -=1 ; + } + while(num < 10) + { + System.out.println("While Countup: " + num); + num +=1 ; + } + } + public static void DoWhile(int number,int number2) + { + + do + { + System.out.println("DoWhile Countup: "+ number); + number += 1; + } + while(number <= 10); + + do + { + System.out.println("DoWhile Countdown: "+ number2); + number2 -= 1; + } + while(number2 >= 1); + } +} From 1889a0ef21a95011574897513535ad5f38d4b496 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 13:35:58 -0500 Subject: [PATCH 059/103] 7-B --- ch07/ForDoWhile2.java | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ch07/ForDoWhile2.java diff --git a/ch07/ForDoWhile2.java b/ch07/ForDoWhile2.java new file mode 100644 index 0000000..9201693 --- /dev/null +++ b/ch07/ForDoWhile2.java @@ -0,0 +1,57 @@ +public class ForDoWhile2 +{ + public static void main(String[] args) + { + + forLoop(0); + While(10); + DoWhile(0,100); + } + public static void forLoop (int i) + { + + + for (i = 10; i <= 100; i++) + { + System.out.println(" Count up i = " + i); + + } + for (i = 100; i >= 10; i--) + { + System.out.println(" Count down = " + i); + + } + } + public static void While(int num) + { + + while(num >=100) + { + System.out.println("While Countdown: " + num); + num -=10 ; + } + while(num <= 100) + { + System.out.println("While Countup: " + num); + num +=10 ; + } + } + public static void DoWhile(int number,int number2) + { + + do + { + System.out.println("DoWhile Countup: "+ number); + number += 10; + } + while(number <= 100); + + do + { + System.out.println("DoWhile Countdown: "+ number2); + number2 -= 10; + } + while(number2 >= 10); + } +} + From 8602caa581bc5814b8200fb6151403d83cfef37b Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 13:37:34 -0500 Subject: [PATCH 060/103] 7-B --- ch07/ForDoWhile2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ch07/ForDoWhile2.java b/ch07/ForDoWhile2.java index 9201693..3f5f9df 100644 --- a/ch07/ForDoWhile2.java +++ b/ch07/ForDoWhile2.java @@ -11,14 +11,14 @@ public static void forLoop (int i) { - for (i = 10; i <= 100; i++) + for (i = 10; i <= 100; i+=10) { System.out.println(" Count up i = " + i); } - for (i = 100; i >= 10; i--) + for (i = 100; i >= 10; i-=10) { - System.out.println(" Count down = " + i); + System.out.println(" Count down i = " + i); } } From 26d167b098ba771321efe3e9866e4571ffb767f2 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 14:01:33 -0500 Subject: [PATCH 061/103] 7-C --- ch07/ForDoWhile3.java | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ch07/ForDoWhile3.java diff --git a/ch07/ForDoWhile3.java b/ch07/ForDoWhile3.java new file mode 100644 index 0000000..12a4b3f --- /dev/null +++ b/ch07/ForDoWhile3.java @@ -0,0 +1,56 @@ +public class ForDoWhile3 +{ + public static void main(String[] args) + { + + forLoop(0); + While(100,-100); + DoWhile(-100,100); + } + public static void forLoop (int i) + { + + + for (i = -100; i <= 100; i+=8) + { + System.out.println(" Count up i = " + i); + + } + for (i = 100; i >= -100; i-=8) + { + System.out.println(" Count down i = " + i); + + } + } + public static void While(int num, int num2) + { + + while(num >= -100) + { + System.out.println("While Countdown: " + num); + num -=8 ; + } + while(num2 <= 100) + { + System.out.println("While Countup: " + num2); + num2 +=8 ; + } + } + public static void DoWhile(int number,int number2) + { + + do + { + System.out.println("DoWhile Countup: "+ number); + number += 8; + } + while(number <= 100); + + do + { + System.out.println("DoWhile Countdown: "+ number2); + number2 -= 8; + } + while(number2 >= -100); + } +} From 0cb3db7572f1c00956b509d1e0d40d4c564be7bf Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 14:43:06 -0500 Subject: [PATCH 062/103] 7-D --- ch07/For2.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ch07/For2.java diff --git a/ch07/For2.java b/ch07/For2.java new file mode 100644 index 0000000..9746118 --- /dev/null +++ b/ch07/For2.java @@ -0,0 +1,16 @@ +public class For2 +{ + public static void main(String[] args) + { + loopFor(10); + } + public static void loopFor(int n) + { + + for (int i = 1 ; i <= n ; i++) + { + System.out.println(" Outer Loop i = " + i); + + } + } +} From af7f8e183d37066ae7670d34ba53b3fe1bb32458 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 15:45:12 -0500 Subject: [PATCH 063/103] 7-E --- ch07/ZeroLoop.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ch07/ZeroLoop.java diff --git a/ch07/ZeroLoop.java b/ch07/ZeroLoop.java new file mode 100644 index 0000000..950d44c --- /dev/null +++ b/ch07/ZeroLoop.java @@ -0,0 +1,24 @@ +import java.util.Scanner; + +public class ZeroLoop +{ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int answer; + + do + { + System.out.println("Please enter a number"); + + answer = in.nextInt(); + + } + while (answer != 0); + System.out.println("Great Guess!"); + + } + + +} + From fded40d0e69a520edd38ea6e512078ad2f49c75c Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 16:52:01 -0500 Subject: [PATCH 064/103] 7-F --- ch07/AskForInt.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch07/AskForInt.java diff --git a/ch07/AskForInt.java b/ch07/AskForInt.java new file mode 100644 index 0000000..0438a8c --- /dev/null +++ b/ch07/AskForInt.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +public class AskForInt +{ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int answer; + int total = 0; + + + do + { + + System.out.println("Please enter a number"); + answer = in.nextInt(); + total = answer + total; + System.out.println("Your total is " + total); + } + while (total <= 1000); + + System.out.println("Your total is " + total); + + } +} From 3b728168cea7434ae5c57f8a392554158cf69cb3 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 20:48:10 -0500 Subject: [PATCH 065/103] 7-G --- ch07/MultiplicationTable.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ch07/MultiplicationTable.java diff --git a/ch07/MultiplicationTable.java b/ch07/MultiplicationTable.java new file mode 100644 index 0000000..a785a03 --- /dev/null +++ b/ch07/MultiplicationTable.java @@ -0,0 +1,32 @@ +public class MultiplicationTable +{ + public static void main(String[] args) + { + + int tableSize = 5; + + printMultiplicationTable(tableSize); + + } + + + public static void printMultiplicationTable(int tableSize) + { + + for (int i = 1; i <= tableSize; i++) + { + + for (int j = 1; j <= tableSize; j++) + { + + System.out.format("%4d\t", i * j); + + } + + System.out.println(); + + } + + + } +} From b99c418aca410d3c3da9c3ad281d08570cf7487b Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 20:49:46 -0500 Subject: [PATCH 066/103] 7-G --- ch07/MultiplicationTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch07/MultiplicationTable.java b/ch07/MultiplicationTable.java index a785a03..b6ec672 100644 --- a/ch07/MultiplicationTable.java +++ b/ch07/MultiplicationTable.java @@ -19,7 +19,7 @@ public static void printMultiplicationTable(int tableSize) for (int j = 1; j <= tableSize; j++) { - System.out.format("%4d\t", i * j); + System.out.printf("%4d\t", i * j); } From ece26c219e44994dac8e2d0f7371271359b7581f Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 21:07:19 -0500 Subject: [PATCH 067/103] 7-G --- ch07/MultiplicationTable.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ch07/MultiplicationTable.java b/ch07/MultiplicationTable.java index b6ec672..568e00e 100644 --- a/ch07/MultiplicationTable.java +++ b/ch07/MultiplicationTable.java @@ -6,7 +6,8 @@ public static void main(String[] args) int tableSize = 5; printMultiplicationTable(tableSize); - + System.out.println(); + printMultiplicationTable2(tableSize); } @@ -28,5 +29,25 @@ public static void printMultiplicationTable(int tableSize) } + } + public static void printMultiplicationTable2(int tableSize) + { + int i = 1; + + while ( i <= tableSize ) + { + int j = 1; + while ( j <= tableSize ) + { + + System.out.printf("%4d\t", i * j); + j= j + 1; + } + i= i + 1; + System.out.println(); + + } + + } } From a32e27d81340012ca96536623e230fc8ab9033a1 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 23 Apr 2018 21:11:28 -0500 Subject: [PATCH 068/103] 7-G silver --- ch07/MultiplicationTable.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ch07/MultiplicationTable.java b/ch07/MultiplicationTable.java index 568e00e..6a2c18a 100644 --- a/ch07/MultiplicationTable.java +++ b/ch07/MultiplicationTable.java @@ -4,9 +4,11 @@ public static void main(String[] args) { int tableSize = 5; - + //for loop printMultiplicationTable(tableSize); + //space between System.out.println(); + //while loop printMultiplicationTable2(tableSize); } From d1428c1710ff5725a55cc4baf4c1ee57e080f653 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 24 Apr 2018 09:48:16 -0500 Subject: [PATCH 069/103] 8-es-1 --- ch08/Array.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ch08/Array.java diff --git a/ch08/Array.java b/ch08/Array.java new file mode 100644 index 0000000..a1e8452 --- /dev/null +++ b/ch08/Array.java @@ -0,0 +1,15 @@ +public class Array +{ + public static void main(String[] args) + { + String[] str = {"Much","More","Java"}; + int[]num = new int[3]; + num[0]=100; + num[1]=200; + str[1]="Better"; + System.out.println("String array length is "+str.length); + System.out.println("integer array lengthis "+ num.length); + System.out.println(num[0]+","+num[1]+","+num[2]); + System.out.println(str[0] + str[1] + str[2]); + } +} From 4140c463f91b408099a7e31c3178c4a7e75dbf8e Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 24 Apr 2018 14:50:20 -0500 Subject: [PATCH 070/103] 8-A-G(not silver) --- ch08/ArrayDemo.java | 105 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 ch08/ArrayDemo.java diff --git a/ch08/ArrayDemo.java b/ch08/ArrayDemo.java new file mode 100644 index 0000000..11d056f --- /dev/null +++ b/ch08/ArrayDemo.java @@ -0,0 +1,105 @@ +public class ArrayDemo +{ + public static void main(String[] args) + { + int[] value = {1, 5, 9}; + int[] moreValue = {5, 2, 9, 8, 0}; + int[] maxValues = {5, 8, 21, 19}; + double[] averageValues = {34.2, 18.0,12.5,13.1}; + int[] array = new int[10]; + array[0]=4; + array[3]=2; + array[9]=4; + String[] array2 = new String[10]; + array2[0]="Hi"; + array2[3]="Hello"; + array2[9]="Bye"; + + + printArray(value); + printArray(moreValue); + int mySum = arrayTotal(moreValue); + System.out.println("Sum of the array is " + mySum); + int myMaxIndex = arrayMaxIndex(maxValues); + System.out.println("Max index of the array is " + myMaxIndex); + int myMaxNum = arrayMax(maxValues); + System.out.println("Max number of the array is " + myMaxNum); + double myAverage = arrayAverage(averageValues); + System.out.println("Average value of the array is " + myAverage); + printArray(array); + printArray2(array2); + + } + + //print array values + public static void printArray(int[] values) + { + for (int value : values) + { + System.out.println(value); + } + } + + public static int arrayTotal(int[] values) + { + int sum = 0; + for (int value : values) + { + sum = sum + value; + + } + return sum; + } + + public static int arrayMax(int[] values) + { + int highest = 0; + for (int value : values) + { + if (value > highest) + { + highest = value; + } + + } + return highest; + } + + public static int arrayMaxIndex(int[] values) + { + int highest = 0; + for (int i = 0; i <= values.length; i++) + { + if (highest < i) + { + highest = i; + } + } + return highest; + } + + public static double arrayAverage(double[] values) + { + double length = values.length; + double average; + double sum = 0; + + for(double value : values) + { + + sum += value; + + } + average = (sum / length); + + return average; + } + + public static void printArray2(String[] values) + { + for (String value : values) + { + System.out.println(value); + } + } +} \ No newline at end of file From cc70a9d93562c89a27bbaf47552031dc02f9b44a Mon Sep 17 00:00:00 2001 From: tjheckler Date: Tue, 24 Apr 2018 16:11:42 -0500 Subject: [PATCH 071/103] 8-G(silver) --- ch08/HowManyPets.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ch08/HowManyPets.java diff --git a/ch08/HowManyPets.java b/ch08/HowManyPets.java new file mode 100644 index 0000000..f5db6ad --- /dev/null +++ b/ch08/HowManyPets.java @@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class HowManyPets +{ + + public static void main(String[] args) + { + howManyPets(); + + } + public static void howManyPets() + { + Scanner in = new Scanner(System.in); + int pets; + + String[] petNames; + String petName; + + System.out.println("How many pets do you have? "); + + pets = in.nextInt(); + in.nextLine(); + petNames = new String[pets]; + + for (int i =0; i< pets; i++) + { + System.out.println("What is the name(s)? "); + petName = in.nextLine(); + petNames[i] = petName; + + } + + printArray2(petNames); + + } + public static void printArray2(String[] values) + { + for (String value : values) + { + System.out.println("Your pets name is " + value); + } + } +} From 197de323d83133e47589e55913333feb86af22b5 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 25 Apr 2018 11:52:55 -0500 Subject: [PATCH 072/103] 8-H(silver) --- ch08/IntergalacticVendingMachines.java | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ch08/IntergalacticVendingMachines.java diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java new file mode 100644 index 0000000..64ff1b6 --- /dev/null +++ b/ch08/IntergalacticVendingMachines.java @@ -0,0 +1,41 @@ +import java.util.Scanner; + +public class IntergalacticVendingMachines +{ + public static void main(String[] args) + { + String[] food = new String[3]; + food[0] = "Freeze Dried Sushi"; + food[1] = "Spock's Brain Blast"; + food[2] = "Alien Asparagus"; + printMenu(food); + + //count foods + int[] counter = new int[3]; + counter[0] = 0; + counter[1] = 1; + counter[2] = 2; + + + //if select # 99 + boolean chose; + + + } + + + public static void printMenu(String[] food ) + { + Scanner in = new Scanner(System.in); + //foods + + System.out.println("Please Select From: "); + System.out.println("0) " + food[0]); + System.out.println("1) " + food[1]); + System.out.println("2) " + food[2]); + System.out.println(); + int choice = in.nextInt(); + System.out.println("Your Selection was " + food[choice]); + } + +} From 5e563471c5e94e8390047b6277a70c5c971afd89 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Wed, 25 Apr 2018 15:30:36 -0500 Subject: [PATCH 073/103] all bronze --- ch09/Stringutil.java | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 ch09/Stringutil.java diff --git a/ch09/Stringutil.java b/ch09/Stringutil.java new file mode 100644 index 0000000..ff65f1a --- /dev/null +++ b/ch09/Stringutil.java @@ -0,0 +1,89 @@ +public class Stringutil +{ + public static void main(String[]args) + { + System.out.println("Welcome to StringUtil"); + System.out.println(); + getFirstCharacter("Goodbye"); + getFirstCharacter("Hello"); + System.out.println(); + getLastCharacter("Hello"); + getLastCharacter("Goodbye"); + System.out.println(); + System.out.println(getFirstTwoCharacters("Hello")); + System.out.println(getFirstTwoCharacters("Goodbye")); + + System.out.println(); + System.out.println(getLastTwoCharacters("Goodbye")); + System.out.println(getLastTwoCharacters("Hello")); + System.out.println(); + System.out.println(getFirstThreeCharacters("Hello")); + System.out.println(getFirstThreeCharacters("Goodbye")); + System.out.println(); + System.out.println(printCharacters("Hello")); + System.out.println(printCharacters("Goodbye")); + System.out.println(); + printPhoneNumber("501-555-0100"); + System.out.println(); + findFirstE("Hello"); + findFirstE("Goodbye"); + + + + } + private static String getFirstCharacter(String value) + { + String word= "Hello"; + String newWord = "Goodbye"; + System.out.println(word.substring(0,1)); + System.out.println(newWord.substring(0,1)); + return value.substring(0,1); + } + private static String getLastCharacter(String value) + { + int startIndex= value.length()-1; + return value.substring(startIndex, startIndex+1); + } + private static String getFirstTwoCharacters(String value) + { + return value.substring(0,2) ; + + + } + private static String getLastTwoCharacters(String value) + { + int startIndex = value.length()-2; + return value.substring(startIndex, startIndex+2); + } + private static String getFirstThreeCharacters(String value) + { + return value.substring(0,3); + } + private static String printCharacters(String value) + { + for (int i=0; i Date: Wed, 25 Apr 2018 15:46:03 -0500 Subject: [PATCH 074/103] all bronze --- ch09/Stringutil.java | 69 ++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/ch09/Stringutil.java b/ch09/Stringutil.java index ff65f1a..b2a5ddc 100644 --- a/ch09/Stringutil.java +++ b/ch09/Stringutil.java @@ -1,6 +1,6 @@ public class Stringutil { - public static void main(String[]args) + public static void main(String[] args) { System.out.println("Welcome to StringUtil"); System.out.println(); @@ -27,63 +27,88 @@ public static void main(String[]args) System.out.println(); findFirstE("Hello"); findFirstE("Goodbye"); - + System.out.println(); + System.out.println(); + System.out.println(isFinn("Finn")); + System.out.println(isFinn("Jake")); } + private static String getFirstCharacter(String value) { - String word= "Hello"; + String word = "Hello"; String newWord = "Goodbye"; - System.out.println(word.substring(0,1)); - System.out.println(newWord.substring(0,1)); - return value.substring(0,1); + System.out.println(word.substring(0, 1)); + System.out.println(newWord.substring(0, 1)); + return value.substring(0, 1); } + private static String getLastCharacter(String value) { - int startIndex= value.length()-1; - return value.substring(startIndex, startIndex+1); + int startIndex = value.length() - 1; + return value.substring(startIndex, startIndex + 1); } + private static String getFirstTwoCharacters(String value) { - return value.substring(0,2) ; + return value.substring(0, 2); } + private static String getLastTwoCharacters(String value) { - int startIndex = value.length()-2; - return value.substring(startIndex, startIndex+2); + int startIndex = value.length() - 2; + return value.substring(startIndex, startIndex + 2); } + private static String getFirstThreeCharacters(String value) { - return value.substring(0,3); + return value.substring(0, 3); } + private static String printCharacters(String value) { - for (int i=0; i Date: Thu, 26 Apr 2018 08:51:54 -0500 Subject: [PATCH 075/103] all bronze --- ch09/{Stringutil.java => StringUtil.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ch09/{Stringutil.java => StringUtil.java} (99%) diff --git a/ch09/Stringutil.java b/ch09/StringUtil.java similarity index 99% rename from ch09/Stringutil.java rename to ch09/StringUtil.java index b2a5ddc..9686228 100644 --- a/ch09/Stringutil.java +++ b/ch09/StringUtil.java @@ -1,4 +1,4 @@ -public class Stringutil +public class StringUtil { public static void main(String[] args) { From 04ef22fa55bf1e2dfc167d090b1b76b1e00382a9 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 26 Apr 2018 16:41:28 -0500 Subject: [PATCH 076/103] qwert --- ch10/Student.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ch10/Student.java diff --git a/ch10/Student.java b/ch10/Student.java new file mode 100644 index 0000000..06bbb67 --- /dev/null +++ b/ch10/Student.java @@ -0,0 +1,29 @@ +public class Student +{ + private String name; + private int studentId; + private double gpa; + + + public Student(String name, int studentId) + { + this.name = name; + this.studentId = studentId; + + } + + public String getName() + { + return name; + } + + public int getStudentId() + { + return studentId; + } + + public double getGpa() + { + return gpa; + } +} From c4ed5448e2a406e30f88a6694724e04fcf4cb2c4 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Thu, 26 Apr 2018 16:41:42 -0500 Subject: [PATCH 077/103] qwert --- ch10/StudentTester.java | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ch10/StudentTester.java diff --git a/ch10/StudentTester.java b/ch10/StudentTester.java new file mode 100644 index 0000000..22fd6cd --- /dev/null +++ b/ch10/StudentTester.java @@ -0,0 +1,42 @@ +public class StudentTester +{ + public static void main (String[] args) + { + // System.out.println("vomit some code here" ); + Student maggie = new Student("Maggie", 1); + // System.out.println(maggie.getName()); + + Student tim = new Student("Tim",2); + //System.out.println(tim.getName()); + + Student joseph = new Student("Joseph",3); + // System.out.println(joseph.getName()); + Student josiah = new Student("Josiah",4); + Student christy = new Student("Christy",5); + Student luke = new Student("Luke",6); + + Student[] frontRowStudents= new Student[3]; + frontRowStudents[0]= maggie; + frontRowStudents[1]= tim; + frontRowStudents[2]= joseph; + + Student[] backRowStudents= new Student[3]; + backRowStudents[0]= josiah; + backRowStudents[1]= christy; + backRowStudents[2]= luke; + + + printStudents(frontRowStudents); + System.out.println(); + printStudents(backRowStudents); + + } + private static void printStudents(Student[] students) + { + for (Student student: students) + { + // System.out.println(student.getName()); + System.out.println(student.getName()); + } + } +} From 35c5eb7880076c0a2a828f65c450b2b55d3e86aa Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 13:55:58 -0500 Subject: [PATCH 078/103] 8-H(silver) --- ch08/IntergalacticVendingMachines.java | 45 +++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index 64ff1b6..da4fd49 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -4,38 +4,47 @@ public class IntergalacticVendingMachines { public static void main(String[] args) { - String[] food = new String[3]; - food[0] = "Freeze Dried Sushi"; - food[1] = "Spock's Brain Blast"; - food[2] = "Alien Asparagus"; - printMenu(food); + Food driedSushi = new Food(" Freeze Dried Sushi",0); + Food brainBlast = new Food(" Spock's Brain Blast",1); + Food alienAsparagus = new Food(" Alien Asparagus",2); + Food[] meal = new Food[3]; + meal[0] = driedSushi; + meal[1] = brainBlast; + meal[2] = alienAsparagus; + + printMenu(meal); //count foods - int[] counter = new int[3]; - counter[0] = 0; - counter[1] = 1; - counter[2] = 2; + // int[] counter = new int[3]; + // counter[0] = 0; + // counter[1] = 1; + // counter[2] = 2; //if select # 99 - boolean chose; } - public static void printMenu(String[] food ) + public static void printMenu(Food[] meals) { + int choice; Scanner in = new Scanner(System.in); //foods + System.out.println("Please Select an Item:" ); - System.out.println("Please Select From: "); - System.out.println("0) " + food[0]); - System.out.println("1) " + food[1]); - System.out.println("2) " + food[2]); + //Prints Menu for selection +for (Food meal: meals) +{ + System.out.println(meal.getId() +" "+meal.getName()); +} System.out.println(); - int choice = in.nextInt(); - System.out.println("Your Selection was " + food[choice]); - } + choice = in.nextInt(); + System.out.println(); + int selection = choice; + System.out.println("Your selection is: "+meals[selection].getName()); + + } } From 9e9b5b7e0c65aba76288d424b3f8606ca0526e95 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 15:12:34 -0500 Subject: [PATCH 079/103] 11-b-2 --- ch11/Date.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ch11/Date.java diff --git a/ch11/Date.java b/ch11/Date.java new file mode 100644 index 0000000..72fec4a --- /dev/null +++ b/ch11/Date.java @@ -0,0 +1,38 @@ +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() + { + if (month < 10) + { + return getYear() + "-0" + getMonth() + "-" + getDay(); + } else + return getYear() + "-" + getMonth() + "-" + getDay(); + + } +} From 2b1367721d0519b63247a3aa19addb23e319f556 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 15:13:21 -0500 Subject: [PATCH 080/103] 11-b-2 --- ch11/DateTester.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ch11/DateTester.java diff --git a/ch11/DateTester.java b/ch11/DateTester.java new file mode 100644 index 0000000..67f5811 --- /dev/null +++ b/ch11/DateTester.java @@ -0,0 +1,14 @@ +public class DateTester +{ + public static void main(String[] args) + { + Date currentDate; + + currentDate = new Date(27,04,2018); + + + System.out.println(currentDate.getformattedDate()); + } + + +} From 9091e43c3210b5e57c3de5408f28cbb1fdf5874a Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 15:13:39 -0500 Subject: [PATCH 081/103] 11-b-1 --- ch11/Planet.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ch11/Planet.java diff --git a/ch11/Planet.java b/ch11/Planet.java new file mode 100644 index 0000000..6d5f10c --- /dev/null +++ b/ch11/Planet.java @@ -0,0 +1,13 @@ +public class Planet +{ + private String name; + public Planet (String name) + { + this.name = name; + } + + public String getName() + { + return name; + } +} From dcf22694c8e56ff0b311770f29c9a547a2566cdb Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 15:13:53 -0500 Subject: [PATCH 082/103] 11-b-1 --- ch11/PlanetTester.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ch11/PlanetTester.java diff --git a/ch11/PlanetTester.java b/ch11/PlanetTester.java new file mode 100644 index 0000000..025dfdf --- /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 saturn = new Planet("Saturn"); + Planet jupiter = new Planet("Jupiter"); + Planet uranus = new Planet("Uranus"); + Planet neptune = new Planet("Neptune"); + Planet pluto = new Planet("Pluto"); + + + Planet[] planets = new Planet[9]; + planets[0] = mercury; + planets[1] = venus; + planets[2] = earth; + planets[3] = mars; + planets[4] = saturn; + planets[5] = jupiter; + planets[6] = uranus; + planets[7] = neptune; + planets[8] = pluto; + printPlanets(planets); + } + + public static void printPlanets(Planet[] planets) + { +for (Planet planet: planets) +{ + System.out.println(planet.getName()); +} + } +} From e6620a4839090f5baad98c485ced46652a40d98b Mon Sep 17 00:00:00 2001 From: tjheckler Date: Fri, 27 Apr 2018 15:21:16 -0500 Subject: [PATCH 083/103] 11-b-2 --- ch11/Date.java | 2 +- ch11/DateTester.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ch11/Date.java b/ch11/Date.java index 72fec4a..ef3d30a 100644 --- a/ch11/Date.java +++ b/ch11/Date.java @@ -26,7 +26,7 @@ public int getYear() return year; } - public String getformattedDate() + public String getFormattedDate() { if (month < 10) { diff --git a/ch11/DateTester.java b/ch11/DateTester.java index 67f5811..2adfebd 100644 --- a/ch11/DateTester.java +++ b/ch11/DateTester.java @@ -7,7 +7,7 @@ public static void main(String[] args) currentDate = new Date(27,04,2018); - System.out.println(currentDate.getformattedDate()); + System.out.println(currentDate.getFormattedDate()); } From 2559588edeb6219dd838a43d370bfc652cd436e4 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 28 Apr 2018 00:23:17 -0500 Subject: [PATCH 084/103] 8-H(silver) --- ch08/Food.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ch08/Food.java diff --git a/ch08/Food.java b/ch08/Food.java new file mode 100644 index 0000000..dbec312 --- /dev/null +++ b/ch08/Food.java @@ -0,0 +1,26 @@ +public class Food +{ + + private String name; + private int id; + + + public Food (String name, int id) + { + this.name = name; + this.id = id; + + } + + public String getName() + { + return name; + } + + public int getId() + { + return id; + } + + +} From 3bfb7695b4551c6e02376d9dec07266a6ca9005e Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 28 Apr 2018 00:23:30 -0500 Subject: [PATCH 085/103] 8-H(silver) --- ch08/IntergalacticVendingMachines.java | 48 ++++++++++++++++++-------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index da4fd49..a1ce7b5 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -4,9 +4,9 @@ public class IntergalacticVendingMachines { public static void main(String[] args) { - Food driedSushi = new Food(" Freeze Dried Sushi",0); - Food brainBlast = new Food(" Spock's Brain Blast",1); - Food alienAsparagus = new Food(" Alien Asparagus",2); + Food driedSushi = new Food(" Freeze Dried Sushi", 1); + Food brainBlast = new Food(" Spock's Brain Blast", 2); + Food alienAsparagus = new Food(" Alien Asparagus", 3); Food[] meal = new Food[3]; meal[0] = driedSushi; @@ -14,11 +14,11 @@ public static void main(String[] args) meal[2] = alienAsparagus; printMenu(meal); - //count foods - // int[] counter = new int[3]; - // counter[0] = 0; - // counter[1] = 1; - // counter[2] = 2; + + int[] counter = new int[3]; + counter[0] = 0; + counter[1] = 1; + counter[2] = 2; //if select # 99 @@ -32,19 +32,39 @@ public static void printMenu(Food[] meals) int choice; Scanner in = new Scanner(System.in); //foods - System.out.println("Please Select an Item:" ); + System.out.println("Please Select an Item:"); //Prints Menu for selection -for (Food meal: meals) -{ - System.out.println(meal.getId() +" "+meal.getName()); -} + for (Food meal : meals) + { + System.out.println(meal.getId() + ") " + meal.getName()); + } System.out.println(); choice = in.nextInt(); System.out.println(); + + /*------------------------------------------------------------------*/ + int selection = choice; - System.out.println("Your selection is: "+meals[selection].getName()); + if (choice < 4) + { + System.out.println("Thank you for choosing: " + meals[selection].getName()); + } + + if (choice >= 4 && choice < 99 || choice >99) + { + System.out.println("Invalid Selection please try again"); + + } + if (choice == 99) + { + System.out.println("Counter goes here"); + + } + + /*------------------------------------------------------------------*/ } + } From 73912349af0bd4f19c21b5c8643428fe85500941 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 28 Apr 2018 06:09:25 -0500 Subject: [PATCH 086/103] 11-s-1 --- ch11/Time2.java | 76 +++++++++++++++++++++++++++++++++++++++++++ ch11/Time2Tester.java | 23 +++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 ch11/Time2.java create mode 100644 ch11/Time2Tester.java diff --git a/ch11/Time2.java b/ch11/Time2.java new file mode 100644 index 0000000..e92efed --- /dev/null +++ b/ch11/Time2.java @@ -0,0 +1,76 @@ +public class Time2 +{ + private int hour; + private int minute; + private boolean PM; + + public Time2(int hour, int minute) + { + this.hour = hour; + this.minute = minute; + } + public Time2(int hour, int minute, boolean PM) + { + this.hour = hour; + this.minute = minute; + this.PM = PM; + + } + + + public String getMilitaryTime() + { + if (hour < 10 && minute < 10) + { + return "0"+getHour() + ":0" + getMinute(); + } + else if (hour < 10) + { + return "0"+getHour() + ":" + getMinute(); + } + else if (minute < 10) + { + return getHour() + ":0" + getMinute(); + } + else + { + return getHour() + ":" + getMinute(); + } + } + public String getTime() + { + if (hour > 12 && PM) + { + return "Civilian Time: "+ (getHour() - 12) + ":" + getMinute() + " PM"; + } + else if (hour <= 12) + { + return "Civilian Time: "+"0" + getHour() + ":" + getMinute() + " AM"; + } + else if (minute < 10) + { + return "Civilian Time: "+getHour() + ":0" + getMinute() + " AM"; + } + else + return "Civilian Time: "+getHour() + ":" + getMinute() + " AM"; + } + + + + public int getHour() + { + return hour; + } + + public int getMinute() + { + return minute; + } + + public boolean PM() + { + return PM; + } + + +} diff --git a/ch11/Time2Tester.java b/ch11/Time2Tester.java new file mode 100644 index 0000000..c16e904 --- /dev/null +++ b/ch11/Time2Tester.java @@ -0,0 +1,23 @@ +public class Time2Tester +{ + public static void main(String[]args) + { + + Time2 currentTime; + currentTime = new Time2 (9,45,true); + System.out.println(currentTime.getTime()); + System.out.println(); + + System.out.println("Military Time: "+currentTime.getMilitaryTime()); + System.out.println(); + + + currentTime = new Time2 (14,30,true); + + System.out.println("Military Time: "+currentTime.getMilitaryTime()); + System.out.println(); + System.out.println(currentTime.getTime()); + + } + +} From 26502461c9533c431526302ff5f55f549556f3b1 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 28 Apr 2018 06:37:26 -0500 Subject: [PATCH 087/103] 11-s-2 --- ch11/Player.java | 31 +++++++++++++++++++++++++++++++ ch11/PlayerTest.java | 11 +++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ch11/Player.java create mode 100644 ch11/PlayerTest.java diff --git a/ch11/Player.java b/ch11/Player.java new file mode 100644 index 0000000..3010483 --- /dev/null +++ b/ch11/Player.java @@ -0,0 +1,31 @@ +public class Player +{ + private String name; + private int score; + + public Player(String name, int score) + { + score = 0; + this.name = name; + this.score = score; + } + + public int increaseScore() + { + return score = score+1; + } + public int resetScore() + { + return score = 0; + } + + public int getScore() + { + return score; + } + + public String getName() + { + return name; + } +} diff --git a/ch11/PlayerTest.java b/ch11/PlayerTest.java new file mode 100644 index 0000000..a2bd34b --- /dev/null +++ b/ch11/PlayerTest.java @@ -0,0 +1,11 @@ +public class PlayerTest +{ + public static void main(String[]args) + { + Player player; + player = new Player("Josh",4); + System.out.println(player.getName()+" entered the game with score at "+player.getScore()); + System.out.println(player.getName()+" scored a point! increased score to "+player.increaseScore()); + System.out.println(player.getName()+" cheated, score is now reset to "+player.resetScore()); + } +} From 28ea380d586af149ef19535899ff4ec085f3bb1d Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 28 Apr 2018 22:04:56 -0500 Subject: [PATCH 088/103] up to 9-S-3 --- ch09/StringUtil.java | 57 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java index 9686228..bc40779 100644 --- a/ch09/StringUtil.java +++ b/ch09/StringUtil.java @@ -24,6 +24,7 @@ public static void main(String[] args) System.out.println(printCharacters("Goodbye")); System.out.println(); printPhoneNumber("501-555-0100"); + printPhoneNumber2("5015550100"); System.out.println(); findFirstE("Hello"); findFirstE("Goodbye"); @@ -31,7 +32,11 @@ public static void main(String[] args) System.out.println(); System.out.println(isFinn("Finn")); System.out.println(isFinn("Jake")); - + System.out.println(); + System.out.println(reverse("Finn")); + System.out.println(); + System.out.println(isPalindrome("palindrome")); + System.out.println(isPalindrome("not palindrome")); } @@ -80,20 +85,33 @@ private static String printCharacters(String value) private static void printPhoneNumber(String value) { - String phoneNumber = "501-555-0100"; - System.out.print("Area Code: " + phoneNumber.substring(0, 3) + " "); - System.out.print("Exchange: " + phoneNumber.substring(4, 7) + " "); - System.out.println("Line Number: " + phoneNumber.substring(8, 12)); + + System.out.print("Area Code: " + value.substring(0, 3) + " "); + System.out.print("Exchange: " + value.substring(4, 7) + " "); + System.out.println("Line Number: " + value.substring(8, 12)); + System.out.println(); + + } +//9-S-1 + private static void printPhoneNumber2(String value2) + { + + + System.out.print("Area Code: " + value2.substring(0, 3) + " "); + System.out.print("Exchange: " + value2.substring(3, 6) + " "); + System.out.println("Line Number: " + value2.substring(6, 10)); + System.out.println(); + } private static void findFirstE(String e) { - String e1 = "Hello"; + e = "Hello"; String e2 = "Goodbye"; - int index = e1.indexOf("e"); + int index = e.indexOf("e"); int index2 = e2.indexOf("e"); - System.out.println("First e in " + e1 + " is at position: " + index); + System.out.println("First e in " + e + " is at position: " + index); System.out.println("First e in " + e2 + " is at position: " + index2); } @@ -103,12 +121,31 @@ private static boolean isFinn(String value) if (value.equals("Finn")) { return true; - } - else + } else { return false; } } + // 9-S-2 + private static String reverse(String reverse) + { + reverse = "nniF"; + + return reverse; + + + } +// 9-S-3 + private static boolean isPalindrome(String value) + { + if (value.equals("palindrome")) + { + return true; + } else + { + return false; + } + } } From 06a373ac9799e3e67184f63c091d2c0a277fb718 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 07:26:32 -0500 Subject: [PATCH 089/103] up to 9-S-3 --- ch09/StringUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java index bc40779..4dd0297 100644 --- a/ch09/StringUtil.java +++ b/ch09/StringUtil.java @@ -12,7 +12,6 @@ public static void main(String[] args) System.out.println(); System.out.println(getFirstTwoCharacters("Hello")); System.out.println(getFirstTwoCharacters("Goodbye")); - System.out.println(); System.out.println(getLastTwoCharacters("Goodbye")); System.out.println(getLastTwoCharacters("Hello")); @@ -29,7 +28,6 @@ public static void main(String[] args) findFirstE("Hello"); findFirstE("Goodbye"); System.out.println(); - System.out.println(); System.out.println(isFinn("Finn")); System.out.println(isFinn("Jake")); System.out.println(); From d05aec2f322533f7ec38c5b72f9cc8fac6bbd4d7 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 10:36:11 -0500 Subject: [PATCH 090/103] 11-b-2 --- ch11/Date.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ch11/Date.java b/ch11/Date.java index ef3d30a..3ddab83 100644 --- a/ch11/Date.java +++ b/ch11/Date.java @@ -31,8 +31,11 @@ public String getFormattedDate() if (month < 10) { return getYear() + "-0" + getMonth() + "-" + getDay(); - } else - return getYear() + "-" + getMonth() + "-" + getDay(); + } + else if (day < 10) + return getYear() + "-" + getMonth() + "-0" + getDay(); + else + return getYear() + "-" + getMonth() + "-" + getDay(); } } From d134f03783339995de5f85a12368b4501fb07714 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 13:39:48 -0500 Subject: [PATCH 091/103] FinishLine Game --- FinishLine/src/com/company/Die.java | 23 ++++++++ FinishLine/src/com/company/DieTester.java | 19 +++++++ FinishLine/src/com/company/FinishLine.java | 61 ++++++++++++++++++++++ FinishLine/src/com/company/Main.java | 13 +++++ FinishLine/src/com/company/Peg.java | 28 ++++++++++ FinishLine/src/com/company/PegTester.java | 12 +++++ 6 files changed, 156 insertions(+) create mode 100644 FinishLine/src/com/company/Die.java create mode 100644 FinishLine/src/com/company/DieTester.java create mode 100644 FinishLine/src/com/company/FinishLine.java create mode 100644 FinishLine/src/com/company/Main.java create mode 100644 FinishLine/src/com/company/Peg.java create mode 100644 FinishLine/src/com/company/PegTester.java diff --git a/FinishLine/src/com/company/Die.java b/FinishLine/src/com/company/Die.java new file mode 100644 index 0000000..f1c3e80 --- /dev/null +++ b/FinishLine/src/com/company/Die.java @@ -0,0 +1,23 @@ +package com.company; + +import java.util.Random; + +public class Die +{ + private int value; + public Die() + { + roll(); + } + + public int getValue() + { + return value; + } + public void roll() + { + Random random = new Random(); + value = random.nextInt(6)+ 1; + } + +} diff --git a/FinishLine/src/com/company/DieTester.java b/FinishLine/src/com/company/DieTester.java new file mode 100644 index 0000000..8add0ce --- /dev/null +++ b/FinishLine/src/com/company/DieTester.java @@ -0,0 +1,19 @@ +package com.company; + +public class DieTester +{ + public static void main(String[] args) + { + Die die = new Die(); + Die die1 = new Die(); + + // System.out.println(die.getValue()); + die.roll(); + die1.roll(); + System.out.println(die.getValue()); + System.out.println(die1.getValue()); + + } + + +} diff --git a/FinishLine/src/com/company/FinishLine.java b/FinishLine/src/com/company/FinishLine.java new file mode 100644 index 0000000..42ea6e5 --- /dev/null +++ b/FinishLine/src/com/company/FinishLine.java @@ -0,0 +1,61 @@ +package com.company; + +public class FinishLine +{ + private Peg bluePeg; + private Peg redPeg; + + private Die dieOne; + private Die dieTwo; + + public FinishLine() + { + bluePeg = new Peg(); + redPeg = new Peg(); + + dieOne = new Die(); + dieTwo = new Die(); + } + + public void play() + { + System.out.println("Starting Game"); + + do + { + takeTurn(bluePeg); + takeTurn(redPeg); + printGameStatus(); + } + while(!bluePeg.isWinner() && !redPeg.isWinner()); + + if (bluePeg.isWinner()) + { + System.out.println("Blue Wins!"); + } + if( redPeg.isWinner()) + { + System.out.println("Red Wins!"); + } + + + } + + private void takeTurn(Peg peg) + { + dieOne.roll(); + dieTwo.roll(); + + if (peg.getNextPosition() == dieOne.getValue() || + peg.getNextPosition() == dieTwo.getValue()|| + peg.getNextPosition() == dieTwo.getValue()+dieOne.getValue() ) + { + peg.moveForward(); + } + } + private void printGameStatus() + { + System.out.println("Blue peg at: "+bluePeg.getPosition()); + System.out.println("Red peg at: "+redPeg.getPosition()); + } +} diff --git a/FinishLine/src/com/company/Main.java b/FinishLine/src/com/company/Main.java new file mode 100644 index 0000000..003bd39 --- /dev/null +++ b/FinishLine/src/com/company/Main.java @@ -0,0 +1,13 @@ +package com.company; + +public class Main { + + public static void main(String[] args) + { + + FinishLine game = new FinishLine(); + game.play(); + } + + +} diff --git a/FinishLine/src/com/company/Peg.java b/FinishLine/src/com/company/Peg.java new file mode 100644 index 0000000..9b4da3b --- /dev/null +++ b/FinishLine/src/com/company/Peg.java @@ -0,0 +1,28 @@ +package com.company; + +public class Peg +{ + private int position; + public Peg() + { + position = 1; + + } + + public int getPosition() + { + return position; + } + public void moveForward() + { + position++; + } + public int getNextPosition() + { + return position + 1; + } + public boolean isWinner() + { + return position >= 10; + } +} diff --git a/FinishLine/src/com/company/PegTester.java b/FinishLine/src/com/company/PegTester.java new file mode 100644 index 0000000..970810f --- /dev/null +++ b/FinishLine/src/com/company/PegTester.java @@ -0,0 +1,12 @@ +package com.company; + +public class PegTester +{ + public static void main(String[] args) + { + Peg bluePeg = new Peg(); + System.out.println(bluePeg.getPosition()); + bluePeg.moveForward(); + System.out.println(bluePeg.getPosition()); + } +} From be412772ebd3ff199b94510e847f938ad886a06c Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 14:08:26 -0500 Subject: [PATCH 092/103] FinishLine Game --- FinishLine/src/com/company/FinishLine.java | 7 +++++-- FinishLine/src/com/company/Main.java | 6 +++++- FinishLine/src/com/company/Peg.java | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/FinishLine/src/com/company/FinishLine.java b/FinishLine/src/com/company/FinishLine.java index 42ea6e5..da83df0 100644 --- a/FinishLine/src/com/company/FinishLine.java +++ b/FinishLine/src/com/company/FinishLine.java @@ -37,8 +37,6 @@ public void play() { System.out.println("Red Wins!"); } - - } private void takeTurn(Peg peg) @@ -58,4 +56,9 @@ private void printGameStatus() System.out.println("Blue peg at: "+bluePeg.getPosition()); System.out.println("Red peg at: "+redPeg.getPosition()); } + public void reset() + { + bluePeg.reset(); + redPeg.reset(); + } } diff --git a/FinishLine/src/com/company/Main.java b/FinishLine/src/com/company/Main.java index 003bd39..5458f5b 100644 --- a/FinishLine/src/com/company/Main.java +++ b/FinishLine/src/com/company/Main.java @@ -6,7 +6,11 @@ public static void main(String[] args) { FinishLine game = new FinishLine(); - game.play(); + for (int i = 0; i< 10000; i++) + { + game.play(); + game.reset(); + } } diff --git a/FinishLine/src/com/company/Peg.java b/FinishLine/src/com/company/Peg.java index 9b4da3b..f9fc029 100644 --- a/FinishLine/src/com/company/Peg.java +++ b/FinishLine/src/com/company/Peg.java @@ -5,7 +5,7 @@ public class Peg private int position; public Peg() { - position = 1; + reset(); } @@ -25,4 +25,8 @@ public boolean isWinner() { return position >= 10; } + public void reset() + { + position = 1; + } } From 137a00cdaac8c8fe30b8b271a32c5161494e8503 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 16:09:11 -0500 Subject: [PATCH 093/103] FinishLine Game --- FinishLine/src/com/company/FinishLine.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FinishLine/src/com/company/FinishLine.java b/FinishLine/src/com/company/FinishLine.java index da83df0..97e1a10 100644 --- a/FinishLine/src/com/company/FinishLine.java +++ b/FinishLine/src/com/company/FinishLine.java @@ -51,6 +51,8 @@ private void takeTurn(Peg peg) peg.moveForward(); } } + //RoundAbout + private void printGameStatus() { System.out.println("Blue peg at: "+bluePeg.getPosition()); From d5f794b6b3bef1aae5f95e2e0c6a75d6e56b91e6 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 16:09:34 -0500 Subject: [PATCH 094/103] FinishLine Game --- FinishLine/src/com/company/Main.java | 9 ++- FinishLine/src/com/company/Peg.java | 1 + FinishLine/src/com/company/Peg2.java | 47 ++++++++++++++ FinishLine/src/com/company/RoundAbout.java | 74 ++++++++++++++++++++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 FinishLine/src/com/company/Peg2.java create mode 100644 FinishLine/src/com/company/RoundAbout.java diff --git a/FinishLine/src/com/company/Main.java b/FinishLine/src/com/company/Main.java index 5458f5b..1828dda 100644 --- a/FinishLine/src/com/company/Main.java +++ b/FinishLine/src/com/company/Main.java @@ -5,12 +5,17 @@ public class Main { public static void main(String[] args) { - FinishLine game = new FinishLine(); + /* FinishLine game = new FinishLine(); for (int i = 0; i< 10000; i++) { game.play(); game.reset(); - } + }*/ + + RoundAbout game2 = new RoundAbout(); + + + game2.play(); } diff --git a/FinishLine/src/com/company/Peg.java b/FinishLine/src/com/company/Peg.java index f9fc029..0ce2229 100644 --- a/FinishLine/src/com/company/Peg.java +++ b/FinishLine/src/com/company/Peg.java @@ -29,4 +29,5 @@ public void reset() { position = 1; } + } diff --git a/FinishLine/src/com/company/Peg2.java b/FinishLine/src/com/company/Peg2.java new file mode 100644 index 0000000..4d7f5b9 --- /dev/null +++ b/FinishLine/src/com/company/Peg2.java @@ -0,0 +1,47 @@ +package com.company; + +public class Peg2 +{ + private int position; + + public Peg2() + { + resetToZero(); + + } + + public int getPosition() + { + return position; + } + + public void moveForward() + { + position++; + } + + public int getNextRollValueNeeded() + { + if (position == 0) + { + return 5; + + } + else + { + return position +1; + } + } + + public boolean isWinner() + { + return position >= 11; + } + + public void resetToZero() + { + position = 0; + } + +} + diff --git a/FinishLine/src/com/company/RoundAbout.java b/FinishLine/src/com/company/RoundAbout.java new file mode 100644 index 0000000..fc65f48 --- /dev/null +++ b/FinishLine/src/com/company/RoundAbout.java @@ -0,0 +1,74 @@ +package com.company; + +public class RoundAbout +{ + private Peg2 bluePeg2; + private Peg2 redPeg2; + + private Die dieOne; + private Die dieTwo; + + public RoundAbout() + { + bluePeg2 = new Peg2(); + redPeg2 = new Peg2(); + dieOne = new Die(); + dieTwo = new Die(); + } + + public void play() + { + System.out.println("Starting Game"); + + do + { + takeTurn2(bluePeg2,redPeg2); + takeTurn2(redPeg2,bluePeg2); + printGameStatus(); + } + while (!bluePeg2.isWinner() && !redPeg2.isWinner()); + + if (bluePeg2.isWinner()) + { + System.out.println("Blue Wins!"); + } + if (redPeg2.isWinner()) + { + System.out.println("Red Wins!"); + } + } + + private void takeTurn2(Peg2 peg2, Peg2 opponentPeg) + { + dieOne.roll(); + dieTwo.roll(); + + if (peg2.getNextRollValueNeeded() == dieOne.getValue() || + peg2.getNextRollValueNeeded() == dieTwo.getValue() || + peg2.getNextRollValueNeeded() == dieTwo.getValue() + dieOne.getValue()) + { + peg2.moveForward(); + if (peg2.getPosition()== opponentPeg.getPosition()) + { + System.out.println("Move it buddy!"); + opponentPeg.resetToZero(); + } + } + } + + + + private void printGameStatus() + { + System.out.println("Blue peg at: " + bluePeg2.getPosition()); + System.out.println("Red peg at: " + redPeg2.getPosition()); + } + + + public void resetToZero() + { + bluePeg2.resetToZero(); + redPeg2.resetToZero(); + } + +} From e3c6bfc3d9c5be277b1af7e8557573e26ca79244 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 16:26:32 -0500 Subject: [PATCH 095/103] FinishLine Game --- FinishLine/src/com/company/FinishLine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FinishLine/src/com/company/FinishLine.java b/FinishLine/src/com/company/FinishLine.java index 97e1a10..ac9e097 100644 --- a/FinishLine/src/com/company/FinishLine.java +++ b/FinishLine/src/com/company/FinishLine.java @@ -19,7 +19,7 @@ public FinishLine() public void play() { - System.out.println("Starting Game"); + System.out.println("Starting Game Finish Line"); do { From ff86be7a57d471569cdae2962599559ac5300750 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Mon, 30 Apr 2018 16:27:05 -0500 Subject: [PATCH 096/103] FinishLine Game and Round About Game --- FinishLine/src/com/company/Main.java | 12 ++++++++---- FinishLine/src/com/company/RoundAbout.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/FinishLine/src/com/company/Main.java b/FinishLine/src/com/company/Main.java index 1828dda..e50b3ee 100644 --- a/FinishLine/src/com/company/Main.java +++ b/FinishLine/src/com/company/Main.java @@ -5,17 +5,21 @@ public class Main { public static void main(String[] args) { - /* FinishLine game = new FinishLine(); - for (int i = 0; i< 10000; i++) - { + FinishLine game = new FinishLine(); + game.play(); game.reset(); - }*/ + + + System.out.println(); + System.out.println(); + RoundAbout game2 = new RoundAbout(); game2.play(); + game2.resetToZero(); } diff --git a/FinishLine/src/com/company/RoundAbout.java b/FinishLine/src/com/company/RoundAbout.java index fc65f48..12ae491 100644 --- a/FinishLine/src/com/company/RoundAbout.java +++ b/FinishLine/src/com/company/RoundAbout.java @@ -18,7 +18,7 @@ public RoundAbout() public void play() { - System.out.println("Starting Game"); + System.out.println("Starting Game Round About"); do { From 734c27497ef9cac4ee016d3ddd76458e69972ce3 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 12 May 2018 20:25:17 -0500 Subject: [PATCH 097/103] 4-h silver --- ch04/Employee.java | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ch04/Employee.java diff --git a/ch04/Employee.java b/ch04/Employee.java new file mode 100644 index 0000000..d92996b --- /dev/null +++ b/ch04/Employee.java @@ -0,0 +1,76 @@ +import java.util.Random; +import java.util.Scanner; + +public class Employee +{ + public static void main(String[] args) + { + int birthYear = 1992; + + boolean isUnionMember = false; + + String firstName = "Timothy"; + String middleName = "John"; + String lastName = "Heckler"; + + int employeeNumber; + Scanner scanner = new Scanner(System.in); + printHeader(); + System.out.println("Please enter your 5 digit employee number:"); + employeeNumber = scanner.nextInt(); + + printFullName(firstName, middleName, lastName); + printUnionStatus(isUnionMember); + printAge(birthYear); + printEvenOrOdd(employeeNumber); + printGenerateSecretPassword(employeeNumber); + } + + public static void printHeader() + { + System.out.println("Welcome to WallabyTech Employee Application"); + System.out.println("==========================================="); + } + + public static void printFullName(String firstName, String middleName, String lastName) + { + System.out.println(lastName + ", " + firstName + " " + middleName); + } + + public static void printUnionStatus(boolean unionStatus) + { + System.out.println("Your union status is: " + unionStatus); + } + + public static void printAge(int birthYear) + { + int age; + int currentYear = 2018; + age = currentYear - birthYear; + System.out.println("Your age is: " + age); + } + + public static void printEvenOrOdd(int x) + { + int isOdd = 1; + int isEven = 2; + if (x % 2 == 0) + { + System.out.println("Employee number is even/odd (1=odd, 2=even; " + isEven); + } else + { + System.out.println("Employee number is even/odd (1=odd, 2=even; " + isOdd); + } + } + + public static void printGenerateSecretPassword(int employeeNumber) + { + Random random = new Random(); + int min = 1; + int max = 10; + int randomNumber = random.nextInt(max - min + 1) + min; + int superSecretPassword = (employeeNumber + randomNumber) * 5; + System.out.println("Employee's random secret pw is: " + superSecretPassword); + + } +} From 26a9e66947a657f89951bee01c47ae0d05b2e12b Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 12 May 2018 20:29:20 -0500 Subject: [PATCH 098/103] 8-H(silver) --- ch08/Food.java | 3 ++ ch08/IntergalacticVendingMachines.java | 40 ++++++++++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ch08/Food.java b/ch08/Food.java index dbec312..0b264aa 100644 --- a/ch08/Food.java +++ b/ch08/Food.java @@ -3,6 +3,8 @@ public class Food private String name; private int id; + public int choice; + private int selection; public Food (String name, int id) @@ -10,6 +12,7 @@ public Food (String name, int id) this.name = name; this.id = id; + } public String getName() diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index a1ce7b5..74f3ad2 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -4,24 +4,25 @@ public class IntergalacticVendingMachines { public static void main(String[] args) { - Food driedSushi = new Food(" Freeze Dried Sushi", 1); - Food brainBlast = new Food(" Spock's Brain Blast", 2); - Food alienAsparagus = new Food(" Alien Asparagus", 3); + //Populate Food Array + Food driedSushi = new Food(" Freeze Dried Sushi", 0); + Food brainBlast = new Food(" Spock's Brain Blast", 1); + Food alienAsparagus = new Food(" Alien Asparagus", 2); Food[] meal = new Food[3]; meal[0] = driedSushi; meal[1] = brainBlast; meal[2] = alienAsparagus; - printMenu(meal); - - int[] counter = new int[3]; - counter[0] = 0; - counter[1] = 1; - counter[2] = 2; + //Counter Array + int[] counter = new int[3]; + counter[0] = 0; + counter[1] = 0; + counter[2] = 0; - //if select # 99 + //Print Food Menu Start of program + printMenu(meal); } @@ -39,32 +40,33 @@ public static void printMenu(Food[] meals) { System.out.println(meal.getId() + ") " + meal.getName()); } + System.out.println(); choice = in.nextInt(); System.out.println(); + int selection = choice; - /*------------------------------------------------------------------*/ - int selection = choice; + + + /*------------------------------------------------------------------*/ if (choice < 4) { System.out.println("Thank you for choosing: " + meals[selection].getName()); } - - if (choice >= 4 && choice < 99 || choice >99) - { - System.out.println("Invalid Selection please try again"); - - } if (choice == 99) { System.out.println("Counter goes here"); } - /*------------------------------------------------------------------*/ } + public static void printSales(int sales) + { + + } + } From 68d76f4e6a4508d336ec7012d2893b2f799058b2 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sat, 12 May 2018 22:47:13 -0500 Subject: [PATCH 099/103] 8-H(silver) --- ch08/Food.java | 3 +- ch08/IntergalacticVendingMachines.java | 78 ++++++++++++++++---------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/ch08/Food.java b/ch08/Food.java index 0b264aa..916a516 100644 --- a/ch08/Food.java +++ b/ch08/Food.java @@ -3,8 +3,7 @@ public class Food private String name; private int id; - public int choice; - private int selection; + public Food (String name, int id) diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index 74f3ad2..6fcd6bc 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -2,8 +2,16 @@ public class IntergalacticVendingMachines { + + public static void main(String[] args) { + run(); + } + private static void run () + { + Scanner in = new Scanner(System.in); + int choice; //Populate Food Array Food driedSushi = new Food(" Freeze Dried Sushi", 0); Food brainBlast = new Food(" Spock's Brain Blast", 1); @@ -20,53 +28,65 @@ public static void main(String[] args) counter[0] = 0; counter[1] = 0; counter[2] = 0; + do + { + //Print Food Menu Start of program + System.out.println("Please Select an Item:"); + printMenu(meal); + System.out.println(); + choice = in.nextInt(); + System.out.println(); + int selection = choice; + /*------------------------------------------------------------------*/ + + + if (choice <= (meal.length - 1) && choice >= 0) + { + System.out.println("Thank you for choosing: " + meal[selection].getName()); + System.out.println(); + counter[choice]++; + System.out.println("Items sold so far:"); + printSales(counter,meal); + System.out.println(); + + } else + { + //do nothing + } - //Print Food Menu Start of program - printMenu(meal); + } + while (choice != 99); + { + System.out.println(); + System.out.println("Final Total Sales"); + printSales(counter, meal); + System.out.println(); + System.out.println("GoodBye!"); + } } - - public static void printMenu(Food[] meals) { - int choice; - Scanner in = new Scanner(System.in); - //foods - System.out.println("Please Select an Item:"); - //Prints Menu for selection for (Food meal : meals) { System.out.println(meal.getId() + ") " + meal.getName()); - } - - System.out.println(); - choice = in.nextInt(); - System.out.println(); - int selection = choice; + } + } + public static void printSales(int[] counter, Food[] meal) + { + for (int i = 0; i <= counter.length-1; i++ ) + { - /*------------------------------------------------------------------*/ + System.out.println(counter[i] + " " + meal[i].getName()); - if (choice < 4) - { - System.out.println("Thank you for choosing: " + meals[selection].getName()); - } - if (choice == 99) - { - System.out.println("Counter goes here"); } - /*------------------------------------------------------------------*/ - } - public static void printSales(int sales) - { - - } } From 239c9138298e1fba8bd62c5ee417c559425e92cb Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 13 May 2018 00:20:17 -0500 Subject: [PATCH 100/103] 8-H(silver) --- ch08/IntergalacticVendingMachines.java | 67 ++++++++++++++------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index 6fcd6bc..f660506 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -8,7 +8,8 @@ public static void main(String[] args) { run(); } - private static void run () + + private static void run() { Scanner in = new Scanner(System.in); int choice; @@ -40,53 +41,55 @@ private static void run () /*------------------------------------------------------------------*/ - if (choice <= (meal.length - 1) && choice >= 0) + + if (choice <= meal.length-1 && choice >=0) + { + System.out.println("Thank you for choosing: " + meal[selection].getName()); + System.out.println(); + counter[choice]++; + + + System.out.println("Items sold so far:"); + printSales(counter, meal); + System.out.println(); + + } + + + } + + while (choice != 99) ; { - System.out.println("Thank you for choosing: " + meal[selection].getName()); + System.out.println(); - counter[choice]++; - System.out.println("Items sold so far:"); - printSales(counter,meal); + System.out.println("Final Total Sales"); + printSales(counter, meal); System.out.println(); - - } else - { - //do nothing + System.out.println("GoodBye!"); } - } - while (choice != 99); - { - - System.out.println(); - System.out.println("Final Total Sales"); - printSales(counter, meal); - System.out.println(); - System.out.println("GoodBye!"); - } - } - public static void printMenu(Food[] meals) - { - //Prints Menu for selection - for (Food meal : meals) + public static void printMenu (Food[]meals) { - System.out.println(meal.getId() + ") " + meal.getName()); + //Prints Menu for selection + for (Food meal : meals) + { + System.out.println(meal.getId() + ") " + meal.getName()); + } } - } - public static void printSales(int[] counter, Food[] meal) - { - for (int i = 0; i <= counter.length-1; i++ ) + public static void printSales ( int[] counter, Food[] meal) { + for (int i = 0; i <= counter.length - 1; i++) + { System.out.println(counter[i] + " " + meal[i].getName()); + } } - } -} + } From fda772351cb265d5d6871b05763442c100806f96 Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 13 May 2018 01:42:31 -0500 Subject: [PATCH 101/103] 8-H(GOLD) --- ch08/IntergalacticVendingMachines.java | 75 ++++++++++++++------------ 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/ch08/IntergalacticVendingMachines.java b/ch08/IntergalacticVendingMachines.java index f660506..1455f5c 100644 --- a/ch08/IntergalacticVendingMachines.java +++ b/ch08/IntergalacticVendingMachines.java @@ -12,7 +12,7 @@ public static void main(String[] args) private static void run() { Scanner in = new Scanner(System.in); - int choice; + String choice; //Populate Food Array Food driedSushi = new Food(" Freeze Dried Sushi", 0); Food brainBlast = new Food(" Spock's Brain Blast", 1); @@ -35,61 +35,70 @@ private static void run() System.out.println("Please Select an Item:"); printMenu(meal); System.out.println(); - choice = in.nextInt(); + choice = in.nextLine(); System.out.println(); - int selection = choice; - /*------------------------------------------------------------------*/ + String[] selection = choice.split(""); + if (choice.contains("99")) + { + + } + else + { - if (choice <= meal.length-1 && choice >=0) + for (String number : selection) { - System.out.println("Thank you for choosing: " + meal[selection].getName()); - System.out.println(); - counter[choice]++; + int magicNumber = Integer.parseInt(number); + int bufferVariable = Integer.parseInt(number); + if (bufferVariable < 0 || bufferVariable > meal.length-1) + {break;} - System.out.println("Items sold so far:"); - printSales(counter, meal); - System.out.println(); + System.out.println("Thank you for choosing: " + meal[magicNumber].getName()); + counter[magicNumber]++; } - - - } - - while (choice != 99) ; - { - - System.out.println(); - System.out.println("Final Total Sales"); + System.out.println("Items sold so far:"); printSales(counter, meal); System.out.println(); - System.out.println("GoodBye!"); } } + while(!choice.contains("99") ); + { + System.out.println(); + System.out.println("Final Total Sales"); + printSales(counter, meal); + System.out.println(); + System.out.println("GoodBye!"); - public static void printMenu (Food[]meals) + } + + + } + + + public static void printMenu(Food[] meals) + { + //Prints Menu for selection + for (Food meal : meals) { - //Prints Menu for selection - for (Food meal : meals) - { - System.out.println(meal.getId() + ") " + meal.getName()); + System.out.println(meal.getId() + ") " + meal.getName()); - } } + } - public static void printSales ( int[] counter, Food[] meal) + public static void printSales(int[] counter, Food[] meal) + { + for (int i = 0; i <= counter.length - 1; i++) { - for (int i = 0; i <= counter.length - 1; i++) - { - System.out.println(counter[i] + " " + meal[i].getName()); + System.out.println(counter[i] + " " + meal[i].getName()); - } } + } - } +} From 4a4a681fbd878380f92e7269735efbce100b530d Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 13 May 2018 09:01:58 -0500 Subject: [PATCH 102/103] up to 9-S-4 9-s-4 is not correct --- ch09/StringUtil.java | 55 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java index 4dd0297..85e1d08 100644 --- a/ch09/StringUtil.java +++ b/ch09/StringUtil.java @@ -1,3 +1,6 @@ +import com.sun.xml.internal.fastinfoset.util.CharArray; +import com.sun.xml.internal.fastinfoset.util.CharArrayString; + public class StringUtil { public static void main(String[] args) @@ -33,8 +36,16 @@ public static void main(String[] args) System.out.println(); System.out.println(reverse("Finn")); System.out.println(); - System.out.println(isPalindrome("palindrome")); - System.out.println(isPalindrome("not palindrome")); + System.out.println(isPalindrome("Finn")); + System.out.println(isPalindrome("dad")); + System.out.println(); + String[] wordArray = new String[4]; + wordArray[0]="pickle"; + wordArray[1]="learn"; + wordArray[2]="education"; + wordArray[3]="coding"; + + System.out.println("The result is "+allLetters(wordArray)); } @@ -91,7 +102,8 @@ private static void printPhoneNumber(String value) System.out.println(); } -//9-S-1 + + //9-S-1 private static void printPhoneNumber2(String value2) { @@ -124,20 +136,23 @@ private static boolean isFinn(String value) return false; } } + // 9-S-2 - private static String reverse(String reverse) + private static String reverse(String word) { - reverse = "nniF"; + + String reverse = new StringBuffer(word).reverse().toString(); return reverse; } -// 9-S-3 + + // 9-S-3 private static boolean isPalindrome(String value) { - - if (value.equals("palindrome")) + String reverse = new StringBuffer(value).reverse().toString(); + if (value.equals(reverse)) { return true; } else @@ -145,5 +160,29 @@ private static boolean isPalindrome(String value) return false; } } + +///don't think this is working correctly + private static boolean allLetters(String[] wordArray) + { + + char[] word = "learn".toCharArray(); + + for (int i = 0; i < wordArray.length - 1; i++) + { + for (String words : wordArray) + { + if (words.startsWith(word.toString())) + { + return true; + } else + { + return false; + } + + } + + } + return false; + } } From 3ebfba9d6152662e79ba640d542de5c333bdcc8f Mon Sep 17 00:00:00 2001 From: tjheckler Date: Sun, 13 May 2018 09:14:22 -0500 Subject: [PATCH 103/103] up to 9-S-4 9-s-4 is not correct --- ch09/StringUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java index 85e1d08..b3f7123 100644 --- a/ch09/StringUtil.java +++ b/ch09/StringUtil.java @@ -165,7 +165,7 @@ private static boolean isPalindrome(String value) private static boolean allLetters(String[] wordArray) { - char[] word = "learn".toCharArray(); + String[] word = "learn".split(""); for (int i = 0; i < wordArray.length - 1; i++) {