From ed9a5d50f153b2b37032afba3550c61fcd6eff93 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Thu, 12 May 2016 20:25:42 +0200 Subject: [PATCH 01/19] Update Hello.java --- ch01/Hello.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ch01/Hello.java b/ch01/Hello.java index 593557b..fbc8fc6 100644 --- a/ch01/Hello.java +++ b/ch01/Hello.java @@ -3,6 +3,7 @@ public class Hello { public static void main(String[] args) { // generate some simple output System.out.println("Hello, World!"); + System.out.print(" How are you?") } } From 8d39120b90482882bef5d7af265056dabb41e498 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Thu, 12 May 2016 20:39:03 +0200 Subject: [PATCH 02/19] Update Hello.java --- ch01/Hello.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch01/Hello.java b/ch01/Hello.java index fbc8fc6..503cde9 100644 --- a/ch01/Hello.java +++ b/ch01/Hello.java @@ -3,7 +3,7 @@ public class Hello { public static void main(String[] args) { // generate some simple output System.out.println("Hello, World!"); - System.out.print(" How are you?") + System.out.print(" How are you?") // an extra string I added } } From 593a331e1724f76e1f00de5bbed7ed2d17b637e9 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Thu, 12 May 2016 20:40:29 +0200 Subject: [PATCH 03/19] Update Hello.java --- ch01/Hello.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch01/Hello.java b/ch01/Hello.java index 503cde9..cf4a2ec 100644 --- a/ch01/Hello.java +++ b/ch01/Hello.java @@ -3,7 +3,7 @@ public class Hello { public static void main(String[] args) { // generate some simple output System.out.println("Hello, World!"); - System.out.print(" How are you?") // an extra string I added + System.out.print(" How are you?") // an extra line I added } } From d4b6f40373b010a9814eebb1e40ab608a8d75a31 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Fri, 13 May 2016 18:46:31 +0200 Subject: [PATCH 04/19] Update Variables.java --- ch02/Variables.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ch02/Variables.java b/ch02/Variables.java index a295abf..070df53 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -78,6 +78,24 @@ public static void main(String[] args) { hour = minute + 1; // correct // minute + 1 = hour; // compiler error + + public class Date { + public static void main(String[] args) { + System.out.println("Hello, world!"); + String day; + int date; + String month; + int year; + day = "Friday"; + date = 13; + month = "May"; + year = 2016; + + System.out.println(day); + System.out.println(date); + System.out.println(month); + System.out.println(year); + } } From 6cfacbbf2c10375078454121091ec5163031175f Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Fri, 13 May 2016 18:51:57 +0200 Subject: [PATCH 05/19] Update Variables.java --- ch02/Variables.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/ch02/Variables.java b/ch02/Variables.java index 070df53..3a9f77d 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -78,23 +78,6 @@ public static void main(String[] args) { hour = minute + 1; // correct // minute + 1 = hour; // compiler error - - public class Date { - public static void main(String[] args) { - System.out.println("Hello, world!"); - String day; - int date; - String month; - int year; - day = "Friday"; - date = 13; - month = "May"; - year = 2016; - - System.out.println(day); - System.out.println(date); - System.out.println(month); - System.out.println(year); } From 88477ee2adbe8c033d4ef2798921d70fa608a2a9 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Fri, 13 May 2016 18:53:10 +0200 Subject: [PATCH 06/19] Create Date --- ch02/Date | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ch02/Date diff --git a/ch02/Date b/ch02/Date new file mode 100644 index 0000000..66ea90b --- /dev/null +++ b/ch02/Date @@ -0,0 +1,18 @@ +public class Date { + public static void main(String[] args) { + System.out.println("Hello, world!"); + String day; + int date; + String month; + int year; + day = "Friday"; + date = 13; + month = "May"; + year = 2016; + + System.out.println(day); + System.out.println(date); + System.out.println(month); + System.out.println(year); + } +} From fe66b437d5871b25f5bcfd32c49acf435753d1a8 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Sat, 14 May 2016 19:55:44 +0200 Subject: [PATCH 07/19] Create Time --- ch02/Time | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ch02/Time diff --git a/ch02/Time b/ch02/Time new file mode 100644 index 0000000..0936300 --- /dev/null +++ b/ch02/Time @@ -0,0 +1,23 @@ +public class Time { + public static void main(String[] args) { + double hour; + double minute; + double second; + hour = 19.0; + minute = 44.0; + second = 40.0; + System.out.println("Number of seconds since midnight:"); + System.out.println((hour * 60) * 60 + (minute * 60) + second); +double secondsSinceMidnight; +secondsSinceMidnight = ((hour * 60) * 60 + (minute * 60) + second); + System.out.println("Number of seconds remaining in the day:"); +int secondsInTheDay; +secondsInTheDay = ((24 * 60) * 60); + System.out.println(secondsInTheDay - secondsSinceMidnight); + System.out.println("Percentage of the day that has passed:"); + System.out.println((secondsSinceMidnight * 100) / secondsInTheDay); + System.out.println("Time elapsed since I started working on this (seconds)"); + System.out.println(secondsSinceMidnight - 69630); + + } +} From ae0afa447cd5725e7dad6a56727bc6dc0548e166 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 17 May 2016 19:21:00 +0200 Subject: [PATCH 08/19] Create Convert2 --- ch03/Convert2 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ch03/Convert2 diff --git a/ch03/Convert2 b/ch03/Convert2 new file mode 100644 index 0000000..ae94c73 --- /dev/null +++ b/ch03/Convert2 @@ -0,0 +1,24 @@ +import java.util.Scanner; + +/** + * Converts Celsius to Fahrenheit + */ +public class Convert { + + public static void main(String[] args) { + double Celsius; + double Fahrenheit; + final double FAHRENHEIT_PER_CELSIUS = 33.8; + Scanner in = new Scanner(System.in); + + // prompt the user and get the value + System.out.print("Exactly how many degrees Celsius? "); + Celsius = in.nextDouble(); + + // convert and output the result + Fahrenheit = (double) (Celsius * FAHRENHEIT_PER_CELSIUS); + System.out.printf("%.1f C = %.1f F", + Celsius, Fahrenheit); + } + +} From 32e79ca115a1f94fefaaa99dc083c6072658adc5 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 17 May 2016 21:32:49 +0200 Subject: [PATCH 09/19] Create ConvertTime --- ch03/ConvertTime | 1 + 1 file changed, 1 insertion(+) create mode 100644 ch03/ConvertTime diff --git a/ch03/ConvertTime b/ch03/ConvertTime new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ch03/ConvertTime @@ -0,0 +1 @@ + From 104742bcad16c00127249143ee1a89270b92ae33 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 17 May 2016 21:33:19 +0200 Subject: [PATCH 10/19] Update ConvertTime --- ch03/ConvertTime | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ch03/ConvertTime b/ch03/ConvertTime index 8b13789..502dc3b 100644 --- a/ch03/ConvertTime +++ b/ch03/ConvertTime @@ -1 +1,26 @@ +import java.util.Scanner; +/** + * Converts seconnds to hours, minutes, and seconds + */ +public class Convert { + + public static void main(String[] args) { + int seconds, hours, minutes, remainder; + final int SECONDS_PER_HOUR = 3600; + final int SECONDS_PER_MINUTE = 60; + Scanner in = new Scanner(System.in); + + // prompt the user and get the value + System.out.print("Exactly how many seconds? "); + seconds = in.nextInt(); + + // convert and output the result + hours = (int) (seconds / SECONDS_PER_HOUR); + minutes = ((seconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE); + remainder = minutes % SECONDS_PER_MINUTE; + System.out.printf("%d seconds = %d hours, %d minutes, %d seconds", + seconds, hours, minutes, remainder); + } + +} From 100e1eb758243bfa1a1f15d1a72bdf805c488870 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 17 May 2016 21:33:43 +0200 Subject: [PATCH 11/19] Rename Convert2 to ConvertTemp --- ch03/{Convert2 => ConvertTemp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ch03/{Convert2 => ConvertTemp} (100%) diff --git a/ch03/Convert2 b/ch03/ConvertTemp similarity index 100% rename from ch03/Convert2 rename to ch03/ConvertTemp From 29d6b9be4c688b24503f8a556a437062a9f790c0 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 17 May 2016 22:35:58 +0200 Subject: [PATCH 12/19] Create GuessNumber --- ch03/GuessNumber | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ch03/GuessNumber diff --git a/ch03/GuessNumber b/ch03/GuessNumber new file mode 100644 index 0000000..aed0399 --- /dev/null +++ b/ch03/GuessNumber @@ -0,0 +1,33 @@ +import java.util.Scanner; +import java.util.Random; + +/** + * Starter code for the "Guess My Number" exercise. + */ +public class Guess { + + public static void main(String[] args) { + + // prompt the user and get the value + System.out.println("I'm thinking of a number between 1 and 100 (including both)."); + System.out.println("Can you guess what it is?"); + System.out.print("Type a number:"); + + Scanner in = new Scanner(System.in); + int guess, remainder; + guess = in.nextInt(); + + // pick a random number + Random random = new Random(); + int number = random.nextInt(100) + 1; + System.out.print("The number I was thinking of is: "); + System.out.printf("%d\n", + number); + remainder = guess - number; + System.out.print("You were off by: "); + System.out.printf("%d", + remainder); + + } + +} From c2f40657a5acc83824e1ca5d39dd161d6d873e76 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Fri, 20 May 2016 19:00:44 +0200 Subject: [PATCH 13/19] Create DateRevisited --- ch04/DateRevisited | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ch04/DateRevisited diff --git a/ch04/DateRevisited b/ch04/DateRevisited new file mode 100644 index 0000000..1f2bf34 --- /dev/null +++ b/ch04/DateRevisited @@ -0,0 +1,30 @@ +public class DateRevisited { + public static void main(String[] args) { + + String day; + int date; + String month; + int year; + day = "Friday"; + date = 20; + month = "May"; + year = 2016; + + printAmerican (day, month, date, year); + } + + public static void printEuropean(String day, int date, String month, int year) { + System.out.print(day); + System.out.print(", " + date); + System.out.print(", " + month); + System.out.print(", " + year); + } + + public static void printAmerican(String day, String month, int date, int year) { + System.out.print(day); + System.out.print(", " + month); + System.out.print(" " + date); + System.out.print(", " + year); + } +} + From ce812512d138ebf4a3626d163243b4eba9f6d92a Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Fri, 20 May 2016 19:01:38 +0200 Subject: [PATCH 14/19] Update Methods.java --- ch04/Methods.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ch04/Methods.java b/ch04/Methods.java index 90c1b7a..75bfc2d 100644 --- a/ch04/Methods.java +++ b/ch04/Methods.java @@ -18,5 +18,10 @@ public static void main(String[] args) { double x3 = Math.exp(Math.log(10.0)); double x4 = Math.pow(2.0, 10.0); } - +public static void zool(int a, String b, String c) { + System.out.println(a); + System.out.println(b); + System.out.println(c); + } + } From 26be44c67ee43e5869f4d07ebfe48eb550f1071c Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 31 May 2016 17:13:00 +0200 Subject: [PATCH 15/19] Create testFermat --- ch05/testFermat | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch05/testFermat diff --git a/ch05/testFermat b/ch05/testFermat new file mode 100644 index 0000000..7841dcd --- /dev/null +++ b/ch05/testFermat @@ -0,0 +1,25 @@ +public class testFermat { + +public static void main(String[] args) { + int a; + int b; + int c; + int n; + a = 3; + b = 4; + c = 5; + n = 2; + testFermat(a, b, c, n); +} + +public static void testFermat(int a, int b, int c, int n) { + if (((Math.pow(a, n) + Math.pow(b, n)) == Math.pow(c, n)) && (n > 2)) { + System.out.println("Holy smokes! Fermat was wrong!"); + } else { + System.out.println("No that doesn't work"); + } + } + + +} + From b6635aa6bac6e23a750299839781a82b72b9bc9b Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Tue, 31 May 2016 17:13:31 +0200 Subject: [PATCH 16/19] Create beerBottles --- ch05/beerBottles | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch05/beerBottles diff --git a/ch05/beerBottles b/ch05/beerBottles new file mode 100644 index 0000000..f8de099 --- /dev/null +++ b/ch05/beerBottles @@ -0,0 +1,22 @@ +public class beerBottles { + + public static void main(String[] args) { + int n; + n = 3; + beerBottles(n); + } + public static void beerBottles(int n) { + if (n >= 1) { + System.out.println(n + " bottles of beer on the wall,"); + System.out.println(n + " bottles of beer,"); + System.out.println("ya take one down, ya' pass it around,"); + System.out.println(n + " bottles of beer on the wall.\n"); + beerBottles(n - 1); + } else { + System.out.println("No bottles of beer on the wall,"); + System.out.println("No bottles of beer,"); + System.out.println("ya take one down, ya' pass it around,"); + System.out.println("No bottles of beer on the wall."); + } + } + } From ddea5d5d3533e13ce052e3a352a7efe10f971d27 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Wed, 1 Jun 2016 09:33:56 +0200 Subject: [PATCH 17/19] Create GuessNumberRevisited --- ch05/GuessNumberRevisited | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ch05/GuessNumberRevisited diff --git a/ch05/GuessNumberRevisited b/ch05/GuessNumberRevisited new file mode 100644 index 0000000..0936d08 --- /dev/null +++ b/ch05/GuessNumberRevisited @@ -0,0 +1,65 @@ +import java.util.Scanner; +import java.util.Random; + +/** + * Starter code for the "Guess My Number" exercise. + */ +public class Guess { + + public static void main(String[] args) { + // prompt the user and get the value + System.out.println("I'm thinking of a number between 1 and 100 (including both)."); + System.out.println("Can you guess what it is?"); + System.out.print("Type a number:"); + + Scanner in = new Scanner(System.in); + int guess; + guess = in.nextInt(); + + // pick a random number + Random random = new Random(); + int number = random.nextInt(100) + 1; + System.out.print("The number I was thinking of is: "); + System.out.printf("%d\n", + number); + + // prompt the user and re-run guessAgain until user guesses correctly + if (guess == number) { + System.out.print("You guessed correctly.\n"); + } else if (guess > number) { + System.out.print("You guessed too high. Try again.\n"); + guessAgain(guess, number); + } else if (guess < number) { + System.out.print("You guessed too low. Try again.\n"); + guessAgain(guess, number); + } + } + + public static void guessAgain(int guess, int number) { + // prompt the user and get the value + System.out.println("I'm thinking of a number between 1 and 100 (including both)."); + System.out.println("Can you guess what it is?"); + System.out.print("Type a number:"); + + Scanner in = new Scanner(System.in); + guess = in.nextInt(); + + // pick a random number + Random random = new Random(); + System.out.print("The number I was thinking of is: "); + System.out.printf("%d\n", + number); + + // prompt the user and re-run guessAgain until user guesses correctly + if (guess == number) { + System.out.print("You guessed correctly.\n"); + } else if (guess > number) { + System.out.print("You guessed too high. Try again.\n"); + guessAgain(guess, number); + } else if (guess < number) { + System.out.print("You guessed too low. Try again.\n"); + guessAgain(guess, number); + } + + } +} From e780f0a3c2709171cfe45fa46f991dc359a52a62 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Thu, 2 Jun 2016 19:23:59 +0200 Subject: [PATCH 18/19] Create VoidMethods --- ch06/VoidMethods | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ch06/VoidMethods diff --git a/ch06/VoidMethods b/ch06/VoidMethods new file mode 100644 index 0000000..a481050 --- /dev/null +++ b/ch06/VoidMethods @@ -0,0 +1,27 @@ +public class voidmethods { + + public static void main(String[] args) { + int a = 10; + int b = 2; + int c = 7; + isTriangle(a, b, c); + } + + public static boolean isTriangle(int a, int b, int c) { + if ((a + b) < c) { + System.out.print("False"); + return false; + } else if + ((a + c) < b) { + System.out.print("False"); + return false; + } else if + ((b + c < a)) { + System.out.print("False"); + return false; + } + System.out.print("True"); + return true; + } + } + From 5d796fa3b0a728d510cb95ed6598fab647384b99 Mon Sep 17 00:00:00 2001 From: Thissy4May Date: Thu, 9 Jun 2016 16:49:02 +0200 Subject: [PATCH 19/19] Create ExerciseCh6 --- ch06/ExerciseCh6 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ch06/ExerciseCh6 diff --git a/ch06/ExerciseCh6 b/ch06/ExerciseCh6 new file mode 100644 index 0000000..397c0de --- /dev/null +++ b/ch06/ExerciseCh6 @@ -0,0 +1,19 @@ +public class ExerciseCh6 { + + public static void main(String[] args) { + int n = 5; + oddSum(n); + System.out.println("The sum of integers from 1 to n is " + oddSum(n)); + } + + public static int oddSum(int n) { + if (n == 0) { + return 0; + } else if + (n % 2 != 0) { + return n + oddSum(n - 1); + } else { + return oddSum(n - 1); + } +} +}