diff --git a/ch02/.idea/misc.xml b/ch02/.idea/misc.xml
new file mode 100644
index 0000000..e208459
--- /dev/null
+++ b/ch02/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ch02/.idea/modules.xml b/ch02/.idea/modules.xml
new file mode 100644
index 0000000..166c8df
--- /dev/null
+++ b/ch02/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
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..f362561
--- /dev/null
+++ b/ch02/Arithmetic.java
@@ -0,0 +1,20 @@
+public class Arithmetic
+{
+ public static void main( String[] args)
+ {
+ int num = 100;
+ int factor = 20;
+ int sum = 0;
+
+ sum =num + factor; //100+20
+ System.out.println( "Addition sum: "+ sum);
+ sum = num- factor; //100-20
+ System.out.println("Subtraction sum: "+ sum);
+
+ sum = num*factor; //100x20
+ System.out.println("Multiplication sum: "+ sum);
+ sum = num/factor; //100/20
+ System.out.println("Division sum: " + sum);
+
+ }
+}
diff --git a/ch02/Assignment.java b/ch02/Assignment.java
new file mode 100644
index 0000000..6406a8f
--- /dev/null
+++ b/ch02/Assignment.java
@@ -0,0 +1,24 @@
+public class Assignment
+{
+ public static void main(String[] args)
+ {
+ String txt= "Fantastic ";
+ String lang= "Java";
+ txt+=lang; //Assign concatenated String
+ System.out.println("Add & Assign Strings: " + txt);
+
+ int sum = 10;
+ int num = 20;
+ sum +=num; //Assign result (10+20=30)
+ System.out.println("Add & Assign Integers: " + sum);
+
+ int factor = 5;
+ sum *= factor; // Assign result (30x5= 150)
+ System.out.println("Multiplication sum: " + sum);
+
+ sum /= factor; //Assign result (150/5=30)
+ System.out.println("Division sum: " +sum);
+
+
+ }
+}
diff --git a/ch02/Constants.java b/ch02/Constants.java
new file mode 100644
index 0000000..cfd65ef
--- /dev/null
+++ b/ch02/Constants.java
@@ -0,0 +1,26 @@
+/* A program to demonstrate constant varibles.
+
+ */
+
+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;
+
+ //Output calculated total.
+ td = 4*TOUCHDOWN;
+ pat=3*CONVERSION;
+ fg=2*FIELDGOAL;
+ total= (td+pat+fg);
+
+ System.out.println("Score: "+ total);
+
+ }
+}
diff --git a/ch02/DataTypes.java b/ch02/DataTypes.java
new file mode 100644
index 0000000..a6c6d1a
--- /dev/null
+++ b/ch02/DataTypes.java
@@ -0,0 +1,17 @@
+public class DataTypes
+{
+ public static void main ( String[] args )
+ {
+ char letter= 'M';
+ String title= "Java in easy steps";
+ int number= 365;
+ float decimal= 98.6f;
+ boolean result= true;
+
+ System.out.println("Initial is " + letter);
+ System.out.println("Book is " + title);
+ System.out.println("Days are " + number);
+ System.out.println("Temperature is " + decimal);
+ System.out.println("Answer is " + result);
+ }
+}
diff --git a/ch02/Date.java b/ch02/Date.java
new file mode 100644
index 0000000..a09d982
--- /dev/null
+++ b/ch02/Date.java
@@ -0,0 +1,21 @@
+public class Date
+{
+ public static void main (String [] Args)
+ {
+ int date, year;
+ String day;
+ String month;
+
+
+ date =17;
+ day = "Tuesday";
+ month = "April ";
+ year= 2018;
+
+ System.out.println("American Format:" );
+ System.out.println( day +", " + month + date +", "+year);
+
+ System.out.println("European Format:");
+ System.out.println(day+" " + date +" "+ month +year);
+ }
+}
diff --git a/ch02/DoubleByZero.java b/ch02/DoubleByZero.java
new file mode 100644
index 0000000..375990b
--- /dev/null
+++ b/ch02/DoubleByZero.java
@@ -0,0 +1,10 @@
+public class DoubleByZero
+{
+ public static void main(String[] args)
+ {
+ double x=42;
+ double y=0;
+ double result=x/y;
+ System.out.println(result);
+ }
+}
diff --git a/ch02/FirstVariable.java b/ch02/FirstVariable.java
new file mode 100644
index 0000000..07621b7
--- /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);
+ }
+}
diff --git a/ch02/IntByZero.java b/ch02/IntByZero.java
new file mode 100644
index 0000000..011ece5
--- /dev/null
+++ b/ch02/IntByZero.java
@@ -0,0 +1,11 @@
+public class IntByZero
+{
+ public static void main(String[] arg)
+ {
+ int x=42;
+ int y=0;
+ int result;
+ result= x/y;
+ System.out.println(result);
+ }
+}
diff --git a/ch02/IntExtremes.java b/ch02/IntExtremes.java
new file mode 100644
index 0000000..5b96e04
--- /dev/null
+++ b/ch02/IntExtremes.java
@@ -0,0 +1,18 @@
+public class IntExtremes
+{
+ public static void main(String[] args)
+ {
+ int positiveInt= 2147483647;
+ System.out.println(positiveInt);
+
+ positiveInt= positiveInt+1;
+ System.out.println(positiveInt);
+
+ int negativeInt = -2147483648;
+ System.out.println(negativeInt);
+
+ negativeInt= negativeInt-1;
+ System.out.println(negativeInt);
+
+ }
+}
diff --git a/ch02/LoveJava.java b/ch02/LoveJava.java
new file mode 100644
index 0000000..c4ac1f1
--- /dev/null
+++ b/ch02/LoveJava.java
@@ -0,0 +1,12 @@
+public class LoveJava
+{
+ public static void main(String[] args)
+ {
+ String a,b,c;
+ a="I ";
+ b="love ";
+ c="Java!";
+
+ System.out.println(a+b+c);
+ }
+}
diff --git a/ch02/Time.java b/ch02/Time.java
new file mode 100644
index 0000000..0d2089e
--- /dev/null
+++ b/ch02/Time.java
@@ -0,0 +1,46 @@
+public class Time
+{
+ public static void main(String[] args)
+ {
+ double hour, minute, second;
+ String time;
+ String secondsLeft;
+ double midnight;
+ double secondsTotal;
+ double secondsInDay;
+ String percPassed;
+ double percent;
+
+ time = "Number of seconds since Midnight: ";
+ secondsLeft= "The amount of seconds left in the day: ";
+ percPassed= "The percentage of the day that has passed: ";
+
+ hour = 15.0;
+ minute = 32.0;
+ second = 45.0;
+ secondsInDay= (86400.0);
+ midnight= (second + (minute * 60) + (hour * 60 * 60));
+ secondsTotal= (((23-hour)*60*60)+((59-minute)*60)+ (60-second));
+ percent= ((midnight/secondsInDay));
+
+ System.out.println(time+midnight);
+ System.out.println(secondsLeft+secondsTotal);
+ System.out.println(percPassed+(percent*100));
+
+ hour = 16.0;
+ minute = 18.0;
+ second= 45.0;
+
+ double timeNow;
+ String timeSince;
+
+ timeNow= (second+(minute*60)+(hour*60*60));
+ timeSince= "Seconds since exercise started: ";
+
+ System.out.println(timeSince+(timeNow-midnight));
+
+
+
+
+ }
+}
diff --git a/ch02/Variables.java b/ch02/Variables.java
index a295abf..46c1918 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)
+ {
+ //Luke
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
diff --git a/ch02/Withdrawal.java b/ch02/Withdrawal.java
new file mode 100644
index 0000000..5eb8908
--- /dev/null
+++ b/ch02/Withdrawal.java
@@ -0,0 +1,25 @@
+public class Withdrawal
+{
+ public static void main(String[] args)
+ {
+ int withdrawal;
+ withdrawal=137;
+
+ int e=20;
+ int f=10;
+ int g=5;
+ int h=1;
+ int a= withdrawal/20;
+ int b= ((withdrawal-(a*e))/f);
+ int c= ((withdrawal-(a*e)-(b*f))/g);
+ int d= ((withdrawal-(a*e)-(b*f)-(c*g))/h);
+
+ System.out.println("20s:"+a);
+ System.out.println("10s:"+b);
+ System.out.println("5s:"+c);
+ System.out.println("1s:"+d);
+
+ System.out.println((a*e)+(b*f)+(c*g)+(d*h));
+
+ }
+}
diff --git a/ch02/ch02.iml b/ch02/ch02.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/ch02/ch02.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ch03/Escape.java b/ch03/Escape.java
new file mode 100644
index 0000000..f5c7cd1
--- /dev/null
+++ b/ch03/Escape.java
@@ -0,0 +1,17 @@
+public class Escape
+{
+ public static void main(String[] args)
+ {
+ String header= "\n\tNEW YORK 3-DAY FORECAST:\n";
+ header += "\n\tDay\t\tHigh\tLow\tConditions\n";
+ header += "\t---\t\t----\t---\t----------\n";
+
+ String forecast= "\tSunday\t68F\t\t48F\tSunny\n";
+ forecast += "\tMonday\t69F\t\t57F\tSunny\n";
+ forecast += "\tTueday\t71F\t\t50F\tCloudy\n";
+
+ System.out.println(header+forecast);
+
+ }
+
+}
diff --git a/ch03/Exercise31.java b/ch03/Exercise31.java
new file mode 100644
index 0000000..f835c8b
--- /dev/null
+++ b/ch03/Exercise31.java
@@ -0,0 +1,9 @@
+public class Exercise31
+{
+ public static void main(String[] args)
+ {
+ double x=49;
+ System.out.printf("%d, %f",x);
+
+ }
+}
diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java
index 64984df..679ac3b 100644
--- a/ch03/GuessStarter.java
+++ b/ch03/GuessStarter.java
@@ -1,4 +1,5 @@
import java.util.Random;
+import java.util.Scanner;
/**
* Starter code for the "Guess My Number" exercise.
@@ -9,7 +10,20 @@ public static void main(String[] args) {
// pick a random number
Random random = new Random();
int number = random.nextInt(100) + 1;
- System.out.println(number);
+ int guess;
+ Scanner in=new Scanner(System.in);
+
+ System.out.println("I'm thinking of a number between 1 and 100");
+ System.out.println("(including both). Can you guess what it is?");
+ System.out.println("Type a number:");
+
+ guess = in.nextInt();
+ int difference= number-guess;
+
+ System.out.println("Your guess is: "+guess);
+ System.out.println("The number I was thinking of is: "+number);
+ System.out.println("You were off by: "+difference);
+
}
}
diff --git a/ch03/Temperature.java b/ch03/Temperature.java
new file mode 100644
index 0000000..6bc0a39
--- /dev/null
+++ b/ch03/Temperature.java
@@ -0,0 +1,20 @@
+import java.util.Scanner;
+
+public class Temperature
+{
+ public static void main(String[] args)
+ {
+ double celsius;
+ double farenheit;
+ Scanner in = new Scanner (System.in);
+
+ System.out.print("What is the temperature in Celsius?");
+ celsius= in.nextDouble();
+ System.out.println("It is "+celsius+" degrees Celsius.");
+
+ farenheit= (celsius*9.0/5.0)+32.0;
+ System.out.println("The temperature in farenheit is "+farenheit);
+
+
+ }
+}
diff --git a/ch03/TotalTime.java b/ch03/TotalTime.java
new file mode 100644
index 0000000..411c98c
--- /dev/null
+++ b/ch03/TotalTime.java
@@ -0,0 +1,29 @@
+import java.util.Scanner;
+
+public class TotalTime
+{
+ public static void main (String[] args)
+ {
+ System.out.println("TotalTime");
+
+ Scanner in= new Scanner(System.in);
+ int seconds;
+ //seconds to minutes
+ int hours=3600;
+ int minutes=60;
+ //totals
+ int totalSeconds;
+ int totalMinutes;
+ int totalHours;
+ //how long did you run?
+ System.out.println("How many seconds did you run?");
+ seconds=in.nextInt();
+ System.out.println("You ran "+seconds+" seconds!");
+ //number of hours,minutes, seconds
+ totalHours= seconds/hours;
+ totalMinutes= ((seconds-(hours*totalHours))/minutes);
+ totalSeconds= (seconds-(hours*totalHours))%minutes;
+ System.out.printf("%d seconds= %d hours,%d minutes, %d seconds",seconds,totalHours,totalMinutes,totalSeconds);
+
+ }
+}
diff --git a/ch04/.idea/vcs.xml b/ch04/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/ch04/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ch04/BigMethodSignature.java b/ch04/BigMethodSignature.java
new file mode 100644
index 0000000..1e05972
--- /dev/null
+++ b/ch04/BigMethodSignature.java
@@ -0,0 +1,12 @@
+public class BigMethodSignature
+{
+ public static void main(String[] args)
+ {
+ printSum(1,2,3,4,5,6,7,8,9,10);
+ printSum(10,20,30,40,50,60,70,80,90,100);
+ }
+ private static void printSum(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
+ {
+ System.out.println(a+b+c+d+e+f+g+h+i+j);
+ }
+}
diff --git a/ch04/DemoMath.java b/ch04/DemoMath.java
new file mode 100644
index 0000000..e51bb05
--- /dev/null
+++ b/ch04/DemoMath.java
@@ -0,0 +1,13 @@
+public class DemoMath
+{
+ public static void main(String[] args)
+ {
+ int a = -10;
+ int b = 20;
+
+ System.out.println("The absolute value of -10 is: "+Math.abs(a));
+ System.out.println("The max of -10 and 20 is: "+Math.max(a,b));
+ System.out.println("-10 raised to the -10th power is: "+Math.pow(a,a));
+ System.out.println("The value of PI is: "+Math.PI);
+ }
+}
diff --git a/ch04/Employee.java b/ch04/Employee.java
new file mode 100644
index 0000000..c441152
--- /dev/null
+++ b/ch04/Employee.java
@@ -0,0 +1,57 @@
+import java.util.Scanner;
+import java.util.Random;
+
+public class Employee
+{
+ public static void main(String[] args)
+ {
+ System.out.println("Employee");
+ int birthYear= 1995;
+ boolean isUnionMember= true;
+ int employeeNumber;
+ Scanner scanner=new Scanner(System.in);
+
+ printHeader();
+ System.out.println("Please enter your 5 digit employee number: ");
+ employeeNumber=scanner.nextInt();
+ printFullName("Luke ","Allen ", "Martin, ");
+ printUnionStatus(true);
+ printAge(1995);
+ printEvenOrOdd(101545);
+ printGenerateSecretPassword(2);
+
+ }
+ private static void printHeader()
+ {
+ System.out.println("Welcome to the WallabyTech Employee Application");
+ System.out.println("===============================================");
+ }
+ private static void printFullName (String first, String middle, String last)
+ {
+ System.out.println(last+first+middle);
+ }
+ private static void printUnionStatus(boolean union)
+ {
+ System.out.println("Your union status is: "+union);
+ }
+ private static void printAge(int birthYear)
+ {
+ int currentYear= 2018;
+ System.out.println("Your age is: "+(currentYear-birthYear));
+ }
+ private static void printEvenOrOdd(int eo)
+ {
+ System.out.println("Employee number is even/odd (1=odd, 0=even);");
+ System.out.println(eo%2);
+ }
+ private static void printGenerateSecretPassword(int password)
+ {
+ Random random=new Random();
+ int employeeNumber=101545;
+ int randomNumber=random.nextInt(10)+1;
+
+ System.out.println("Employee's random secret pw is: "+(employeeNumber*randomNumber)*5);
+ }
+}
+
+
diff --git a/ch04/MathUtil.java b/ch04/MathUtil.java
new file mode 100644
index 0000000..125099f
--- /dev/null
+++ b/ch04/MathUtil.java
@@ -0,0 +1,16 @@
+public class MathUtil
+{
+ public static void main(String[] args)
+ {
+ printDifference(1000,400000);
+ }
+ public static void printDifference(int x, int y)
+ {
+ printAbsValue(x-y);
+ }
+ public static void printAbsValue(int z)
+ {
+ System.out.println("Value is: "+z+"\nAbsolute Value is: "+Math.abs(z));
+ }
+
+}
diff --git a/ch04/SimpleMethods.java b/ch04/SimpleMethods.java
new file mode 100644
index 0000000..056f217
--- /dev/null
+++ b/ch04/SimpleMethods.java
@@ -0,0 +1,24 @@
+public class SimpleMethods
+{
+ public static void main(String[] args)
+ {
+ printCount(5);
+ printSum(4,6);
+ printSum(7,2);
+ printBoolean(true);
+ printBoolean(false);
+ }
+ private static void printCount(int count)
+ {
+ System.out.println("The count is: "+count);
+ }
+ private static void printSum(int x,int y)
+ {
+ System.out.print(x+ " + " +y+ " = ");
+ System.out.println(x+y);
+ }
+ private static void printBoolean(boolean isStudent)
+ {
+ System.out.println("I am a student: "+isStudent);
+ }
+}
diff --git a/ch05/Coffee.java b/ch05/Coffee.java
new file mode 100644
index 0000000..bb6d1fb
--- /dev/null
+++ b/ch05/Coffee.java
@@ -0,0 +1,40 @@
+public class Coffee
+{
+ public static void main(String[] args)
+ {
+ /*
+ Travel<21=free coffee
+ Bike<30=10%
+ Ride>=35 =20%
+ Bike <50 = 20%
+ Ride <50 = 30%
+ */
+ bikeDiscount(20);
+ bikeDiscount(30);
+ bikeDiscount(52);
+ busDiscount(35);
+ busDiscount(50);
+ }
+ public static void bikeDiscount(int milesRidden)
+ {
+ int discount=0;
+ if (milesRidden<21)
+ discount=100;
+ if (milesRidden<50&&milesRidden>=30)
+ discount=20;
+ if (milesRidden<30&&milesRidden>=21)
+ discount=30;
+ System.out.println("You receive "+discount+"% off!");
+ }
+ public static void busDiscount(int milesRidden)
+ {
+ int discount=0;
+ if (milesRidden<21)
+ discount=100;
+ if (milesRidden>=35&&milesRidden<50)
+ discount=50;
+ if (milesRidden<=50&&milesRidden>35)
+ discount=30;
+ System.out.println("You receive "+discount+"% off!");
+ }
+}
diff --git a/ch05/Comparison.java b/ch05/Comparison.java
new file mode 100644
index 0000000..a1ad53d
--- /dev/null
+++ b/ch05/Comparison.java
@@ -0,0 +1,21 @@
+public class Comparison
+{
+ public static void main(String[] args)
+ {
+ String txt= "Fantastic";
+ String lang= "Java";
+ boolean state= (txt==lang); //assign test result
+ System.out.println("String Equality Test: "+state);
+
+ state= (txt != lang); //assign 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 = (dozen1) System.out.println("Five is greater than one.");
+ if (2<4) {
+ System.out.println("Two is less than four.");
+ System.out.println("Test succeeded.");
+ }
+ int num= 4;
+ if(((num>5)&&(num<10))||(num==12)) System.out.println("Number is 6-9 inclusive, or 12");
+ }
+}
diff --git a/ch05/Logic.java b/ch05/Logic.java
new file mode 100644
index 0000000..47516cc
--- /dev/null
+++ b/ch05/Logic.java
@@ -0,0 +1,18 @@
+public class Logic
+{
+ public static void main(String[] args)
+ {
+ boolean yes= true;
+ boolean no= false;
+
+ System.out.println("Both YesYes True: " +(yes&&yes));
+ System.out.println("Both YesNo True: "+ (yes&&no));
+
+ System.out.println("Either YesYes True: "+ (yes||yes));
+ System.out.println("Either YesNo True: "+(yes||no));
+ System.out.println("Either NoNo True: "+(no||no));
+
+ System.out.println("Original Yes Value: "+yes);
+ System.out.println("Inverse Yes Value: "+!yes);
+ }
+}
diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java
new file mode 100644
index 0000000..b7ab727
--- /dev/null
+++ b/ch05/LogicMethods.java
@@ -0,0 +1,52 @@
+public class LogicMethods
+{
+ public static void main(String [] args)
+ {
+ printIsLarge(100);
+ printIsLarge(20);
+ printIsLarge(1000);
+ printIsLargeOrSmall(5);
+ printIsLargeOrSmall(100);
+ printIsLargeOrSmall(1);
+ printLargest(10,2);
+ printLargest(4,8);
+ printLargest(5,5);
+ printLargestOdd(27,10);
+ printLargestOdd(13,15);
+ printLargestOdd(10,4);
+ }
+ private static void printIsLarge(int number)
+ {
+ if (number>99)
+ System.out.println("The number is large");
+ }
+ private static void printIsLargeOrSmall(int number)
+ {
+ if (number>99)
+ System.out.println("The number is large");
+ if (number<10)
+ System.out.println("The number is small");
+ }
+ private static void printLargest(int number1,int number2)
+ {
+ if (number1>number2)
+ System.out.println("The largest number is: "+number1);
+ else if (number2>number1)
+ System.out.println("The largest number is: "+number2);
+ else
+ System.out.println("The numbers are equal");
+ }
+ private static void printLargestOdd(int number1,int number2)
+ {
+ if ((number1%2!=0&&(number1>number2)))
+ System.out.println("The largest odd number is: "+number1);
+ else if ((number2%2!=0&&(number2>number1)))
+ System.out.println("The largest odd number is: "+number2);
+ else
+ {
+ System.out.print("Two odds make an even ");
+ System.out.print(number1 + " + " + number2);
+ System.out.println(" = "+(number1+number2));
+ }
+ }
+}
diff --git a/ch05/Precedence.java b/ch05/Precedence.java
new file mode 100644
index 0000000..931ad8c
--- /dev/null
+++ b/ch05/Precedence.java
@@ -0,0 +1,15 @@
+public class Precedence
+{
+ public static void main(String[] args)
+ {
+ int sum= 32-8+16*2; //16x2=32, +24=56
+ System.out.println("Default order: "+sum);
+
+ sum =(32-8+16)*2; //24+16=40, x 2= 80
+ System.out.println("Specified order: "+sum);
+
+ sum= (32-(8+16))*2; //32-24=8, *2= 16
+ System.out.println("Nested specific order: "+sum);
+
+ }
+}
diff --git a/ch05/StringCheese.java b/ch05/StringCheese.java
new file mode 100644
index 0000000..c69c867
--- /dev/null
+++ b/ch05/StringCheese.java
@@ -0,0 +1,46 @@
+import java.util.Scanner;
+
+public class StringCheese
+{
+ public static void main(String[] args)
+ {
+ /*
+ 1&2 inch cheese= $2 shipping per yard
+ 3 inch cheese= $4 shipping per yard
+ 1 inch= $2/yard
+ 2 inch= $4/yard
+ 3 inch= $6/yard
+ "The cost of your cheese is $"+
+ */
+ int inchPrice= 2;
+ int inch2Price=4;
+ int inch3Price=6;
+ int shipping12=2;
+ int shipping3=4;
+ int yards; //yards ordered
+ int cheese; //type of cheese
+
+ Scanner amount= new Scanner(System.in); //get yards
+ Scanner type= new Scanner (System.in); //get cheese type
+
+ System.out.println("What diameter cheese would you like to order?");
+ cheese=type.nextInt();
+ System.out.println("How many yards would you like to order?");
+ yards=amount.nextInt();
+
+ if ((yards>50&&cheese==1))
+ System.out.println("The cost of your cheese is $"+((yards*inchPrice)+5));
+ else if ((yards<=50&&cheese==1))
+ System.out.println("The cost of your cheese is $"+((yards*inchPrice)+(yards*shipping12)+5));
+ else if ((yards>75&&cheese==2))
+ System.out.println("The cost of your cheese is $"+((yards*inch2Price)+5));
+ else if ((yards<=75&&cheese==2))
+ System.out.println("The cost of your cheese is $"+((yards*inch2Price)+(yards*shipping12)+5));
+ else if ((yards>25&&cheese==3))
+ System.out.println("The cost of your cheese is $"+((yards*inch3Price)+5));
+ else if ((yards<=25&&cheese==3))
+ System.out.println("The cost of your cheese is $"+((yards*inch3Price)+(yards*shipping3)+5));
+ else
+ System.out.println("This order is too crazy!");
+ }
+}
diff --git a/ch05/Switch.java b/ch05/Switch.java
new file mode 100644
index 0000000..b6445cf
--- /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 9: case 11:
+ num=30; break;
+ case 2:
+ num=((year%4)==0)? 29:28; break;
+ }
+ System.out.println(month+"/"+year+": "+num+" days");
+ }
+}
diff --git a/ch05/SwitchExample.java b/ch05/SwitchExample.java
new file mode 100644
index 0000000..b9c3a27
--- /dev/null
+++ b/ch05/SwitchExample.java
@@ -0,0 +1,60 @@
+public class SwitchExample
+{
+ public static void main(String[] args)
+ {
+ lastNameWinner("smith");
+ lastNameWinner("jones");
+ lastNameWinner("Lazenby");
+ lastNameWinner("Martin");
+ dayOfWeek(2);
+ dayOfWeek(4);
+ dayOfWeek(-2);
+ dayOfWeek(100);
+
+ }
+ public static void lastNameWinner(String winner)
+ {
+ switch (winner)
+ {
+ case "smith":
+ 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");
+ }
+ }
+ private 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;
+ default:
+ System.out.println("Invalid value: day");
+ }
+
+ }
+}
diff --git a/ch05/TicketNumber.java b/ch05/TicketNumber.java
new file mode 100644
index 0000000..f857f26
--- /dev/null
+++ b/ch05/TicketNumber.java
@@ -0,0 +1,20 @@
+import java.util.Scanner;
+
+public class TicketNumber
+{
+ public static void main (String [] args)
+ {
+ int ticketNumber;
+ Scanner myTicket=new Scanner(System.in);
+ System.out.println("What is your ticket number?");
+ ticketNumber=myTicket.nextInt();
+
+ int lastDigit=ticketNumber%10;
+ int ticketPrefix= (ticketNumber-lastDigit);
+ if ((ticketPrefix/10)%7==lastDigit)
+ System.out.println("Good Number");
+ else
+ System.out.println("Bad Number");
+
+ }
+}
diff --git a/ch06/Divisible.java b/ch06/Divisible.java
new file mode 100644
index 0000000..60a1d27
--- /dev/null
+++ b/ch06/Divisible.java
@@ -0,0 +1,36 @@
+public class Divisible
+{
+ public static void main(String [] args)
+ {
+ System.out.println(isDivisible(10,5));
+ System.out.println(isDivisible(10,3));
+ System.out.println(isDivisible(12,5));
+ System.out.println(isDivisible(25,5));
+ System.out.println(isTriangle(10,2,5));
+ System.out.println(isTriangle(10,7,4));
+
+ }
+ private static boolean isDivisible(int n, int m)
+ {
+ boolean answer=false;
+ int div=n%m;
+ if (div==0)
+ {
+ answer=true;
+ }
+ return answer;
+ }
+
+ private static boolean isTriangle(int a,int b, int c)
+ {
+ boolean answer= false;
+
+ if(a<(b+c)&&b<(a+c)&&c<(b+a))
+ {
+ answer=true;
+ }
+ return answer;
+ }
+
+
+}
diff --git a/ch06/Exercise.java b/ch06/Exercise.java
index b826b44..7cf45db 100644
--- a/ch06/Exercise.java
+++ b/ch06/Exercise.java
@@ -1,6 +1,7 @@
public class Exercise {
public static void main(String[] args) {
+
boolean flag1 = isHoopy(202);
boolean flag2 = isFrabjuous(202);
System.out.println(flag1);
diff --git a/ch06/MathUtil.java b/ch06/MathUtil.java
new file mode 100644
index 0000000..7f18605
--- /dev/null
+++ b/ch06/MathUtil.java
@@ -0,0 +1,28 @@
+public class MathUtil
+{
+ public static void main (String [] args)
+ {
+ System.out.println(absoluteSum(10,-20));
+ System.out.println(absoluteSum(0,-1));
+ System.out.println(absoluteSum(12,12));
+ System.out.println(absoluteOverload(5,-20,-80));
+ System.out.println(absoluteOverload(-10,10,-1));
+ System.out.println(absoluteOverload(2,3,4));
+
+ }
+ private static int absoluteSum(int x, int y)
+ {
+ int absX= Math.abs(x);
+ int absY= Math.abs(y);
+
+ return (absX+absY);
+ }
+ private static int absoluteOverload(int x, int y, int z)
+ {
+ int absX= Math.abs(x);
+ int absY= Math.abs(y);
+ int absZ= Math.abs(z);
+
+ return (absX+absY+absZ);
+ }
+}
diff --git a/ch06/Multadd.java b/ch06/Multadd.java
new file mode 100644
index 0000000..7d2123c
--- /dev/null
+++ b/ch06/Multadd.java
@@ -0,0 +1,13 @@
+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 answer = a * b + c;
+ return answer;
+ }
+}
diff --git a/ch07/DoWhile.java b/ch07/DoWhile.java
new file mode 100644
index 0000000..ca20cca
--- /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);
+ }
+}
diff --git a/ch07/For.java b/ch07/For.java
new file mode 100644
index 0000000..65e2d7c
--- /dev/null
+++ b/ch07/For.java
@@ -0,0 +1,17 @@
+public class For
+{
+ public static void main (String [] args)
+ {
+ int num=0;
+
+ for (int i=1; i<4;i++)
+ {
+ System.out.println("Outer Loop i= "+i);
+ for(int j=1; j<4;j++)
+ {
+ System.out.print("\tInner Loop j="+j);
+ System.out.println("\t\tTotal num="+(++num));
+ }
+ }
+ }
+}
diff --git a/ch07/LoopTest.java b/ch07/LoopTest.java
new file mode 100644
index 0000000..c08d0ad
--- /dev/null
+++ b/ch07/LoopTest.java
@@ -0,0 +1,23 @@
+public class LoopTest
+{
+ public static void main(String [] args)
+ {
+ int y=1;
+ int z=1;
+ for (int x=1; x<=10; x++)
+ {
+ System.out.println("The count of x is: " +x);
+ }
+ while (y<=10)
+ {
+ System.out.println("The count of y is: "+y);
+ y++;
+ }
+ do
+ {
+ System.out.println("The count of z is : "+z);
+ z++;
+ }
+ while(z<=10);
+ }
+}
diff --git a/ch07/LoopTestB.java b/ch07/LoopTestB.java
new file mode 100644
index 0000000..e37c990
--- /dev/null
+++ b/ch07/LoopTestB.java
@@ -0,0 +1,23 @@
+public class LoopTestB
+{
+ public static void main (String [] args)
+ {
+ for(int x=0; x<=100;x+=10)
+ {
+ System.out.println("The count of x is: "+x);
+ }
+ int y=0;
+ while (y<=100)
+ {
+ System.out.println("The count of y is: "+y);
+ y+=10;
+ }
+ int z=0;
+ do
+ {
+ System.out.println("The count of z is: "+z);
+ z+=10;
+ }
+ while (z<=100);
+ }
+}
diff --git a/ch07/LoopTestC.java b/ch07/LoopTestC.java
new file mode 100644
index 0000000..c205037
--- /dev/null
+++ b/ch07/LoopTestC.java
@@ -0,0 +1,23 @@
+public class LoopTestC
+{
+ public static void main (String [] args)
+ {
+ for (int x=100; x>=-100; x-=8)
+ {
+ System.out.println("The count of x is: "+x);
+ }
+ int y=100;
+ while(y>=-100)
+ {
+ System.out.println("The count of y is: "+y);
+ y-=8;
+ }
+ int z=100;
+ do
+ {
+ System.out.println("The count of z is: "+z);
+ z-=8;
+ }
+ while(z>=-100);
+ }
+}
diff --git a/ch07/LoopTestD.java b/ch07/LoopTestD.java
new file mode 100644
index 0000000..224cee8
--- /dev/null
+++ b/ch07/LoopTestD.java
@@ -0,0 +1,17 @@
+public class LoopTestD
+{
+ public static void main (String [] args)
+ {
+ numSequence(50);
+ }
+
+ private static int numSequence(int x)
+ {
+ int num=1;
+ while(num<=x)
+ {
+ System.out.println(num++);
+ }
+ return num;
+ }
+}
diff --git a/ch07/LoopTestE.java b/ch07/LoopTestE.java
new file mode 100644
index 0000000..c4b7781
--- /dev/null
+++ b/ch07/LoopTestE.java
@@ -0,0 +1,23 @@
+import java.util.Scanner;
+
+public class LoopTestE
+{
+ public static void main(String[] args)
+ {
+ zero();
+ System.out.println("The number is zero");
+ }
+
+ private static int zero()
+ {
+ Scanner in = new Scanner(System.in);
+ System.out.println("Please type the number zero");
+ int x = in.nextInt();
+ while (x != 0)
+ {
+ System.out.println("Please type the number zero");
+ x= in.nextInt();
+ }
+ return x;
+ }
+}
\ No newline at end of file
diff --git a/ch07/LoopTestF.java b/ch07/LoopTestF.java
new file mode 100644
index 0000000..db85c87
--- /dev/null
+++ b/ch07/LoopTestF.java
@@ -0,0 +1,25 @@
+import java.util.Scanner;
+
+public class LoopTestF
+{
+ public static void main (String [] args)
+ {
+ runningTotal();
+ }
+ private static int runningTotal()
+ {
+ Scanner in= new Scanner(System.in);
+ System.out.println("Enter a number: ");
+ int x= in.nextInt();
+ int sum=0;
+ while(sum<=1000)
+ {
+ sum+=x;
+ System.out.println("The total of the numbers is " + sum);
+ System.out.println("Please enter another number: ");
+ x=in.nextInt();
+ }
+ System.out.println("The final total is: "+sum);
+ return sum;
+ }
+}
diff --git a/ch07/MultiplicationTable.java b/ch07/MultiplicationTable.java
new file mode 100644
index 0000000..716313d
--- /dev/null
+++ b/ch07/MultiplicationTable.java
@@ -0,0 +1,27 @@
+public class MultiplicationTable
+{
+ public static void main (String [] args)
+ {
+ printTable(20);
+ }
+ public static void printRow(int n,int cols)
+ {
+ int x= 1;
+
+ while (x<=cols)
+ {
+ System.out.printf("%4d",x*n);
+ x=x+1;
+ }
+ System.out.println();
+ }
+ private static void printTable(int rows)
+ {
+ int y = 1;
+ while (y <= rows)
+ {
+ printRow(y,rows);
+ y=y+1;
+ }
+ }
+}
diff --git a/ch07/While.java b/ch07/While.java
new file mode 100644
index 0000000..a21cecc
--- /dev/null
+++ b/ch07/While.java
@@ -0,0 +1,13 @@
+public class While
+{
+ public static void main (String [] args)
+ {
+ int num=100;
+
+ while (num>0)
+ {
+ System.out.println("While Countdown: " + num);
+ num-=10;
+ }
+ }
+}
diff --git a/ch08/Array.java b/ch08/Array.java
new file mode 100644
index 0000000..67bde9a
--- /dev/null
+++ b/ch08/Array.java
@@ -0,0 +1,17 @@
+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 length is "+num.length);
+ System.out.println(num[0]+","+num[1]+","+num[2]);
+ System.out.println(str[0]+str[1]+str[2]);
+ }
+}
diff --git a/ch08/ArrayDemo.java b/ch08/ArrayDemo.java
new file mode 100644
index 0000000..cf5ad5c
--- /dev/null
+++ b/ch08/ArrayDemo.java
@@ -0,0 +1,122 @@
+public class ArrayDemo
+{
+ public static void main (String [] args)
+ {
+
+ int [] numbers={1,5,9};
+ printArray(numbers);
+ System.out.println();
+
+ int [] numbers2={5,7,13};
+ int sum = arrayTotal(numbers2);
+ int sum2= arrayTotal(numbers);
+ printArray(numbers2);
+ System.out.println("The total of these numbers is: "+sum);
+ System.out.println();
+
+ printArray(numbers);
+ System.out.println("The total of these numbers is: "+sum2);
+ System.out.println();
+
+ int [] numbers3= {5,8,21,19,2};
+ int max=(arrayMax(numbers3));
+ printArray(numbers3);
+ System.out.println("The max of these numbers is: "+max);
+ System.out.println();
+
+ int [] numbers4= {78,23,9,34};
+ int max2=(arrayMax(numbers4));
+ printArray(numbers4);
+ System.out.println("The max of these numbers is: "+max2);
+
+ int maxIndex=(arrayMaxIndex(numbers4));
+ System.out.println(maxIndex);
+ int maxIndex2= arrayMaxIndex(numbers3);
+ System.out.println(maxIndex2);
+ System.out.println();
+
+ double [] numbers5= {34.2,18.0,12.5,13.1};
+ double avg= arrayAverage(numbers5);
+ System.out.println("The average of these numbers is "+avg);
+ System.out.println();
+
+ double [] numbers6= {10.0,15.0,20.0};
+ double avg2=(arrayAverage(numbers6));
+ System.out.println("The average of these numbers is " +avg2);
+
+ int [] keyword=new int [10];
+ keyword [0]=4;
+ keyword [3]=2;
+ keyword [9]=4;
+ printArray(keyword);
+
+ String [] keyword2= new String [10];
+ keyword2 [0]= "Hi";
+ keyword2 [3]= "Hello";
+ keyword2 [9]= "Bye";
+ printStrings(keyword2);
+
+
+
+ }
+ private static void printArray(int [] values)
+ {
+ for (int value:values)
+ {
+ System.out.println(value);
+ }
+ }
+ private static int arrayTotal(int[] values)
+ {
+ int sum=0;
+ for(int value: values)
+ {
+ sum=sum+value;
+ }
+ return sum;
+ }
+
+ private static int arrayMax(int [] values)
+ {
+ int max=0;
+ for(int value:values)
+ {
+ if(value>max)
+ max = value;
+ }
+ return max;
+ }
+ private static int arrayMaxIndex( int [] values)
+ {
+ int max=0;
+ int maxIndex=0;
+
+ for (int x = 0; x < values.length; x++)
+ {
+ if(values[x]>max)
+ {
+ max=values[x];
+ maxIndex=x;
+ }
+ }
+ return maxIndex;
+ }
+ private static double arrayAverage(double []values)
+ {
+ double sum=0;
+ double length= values.length;
+ for (double value:values)
+ {
+ sum= sum+value;
+ }
+ double avg= sum/length;
+ return avg;
+ }
+ private static void printStrings (String [] keywords)
+ {
+ for (String stringTest:keywords)
+ {
+ System.out.println(stringTest);
+ }
+ }
+}
diff --git a/ch08/HowManyDogs.java b/ch08/HowManyDogs.java
new file mode 100644
index 0000000..a8aa523
--- /dev/null
+++ b/ch08/HowManyDogs.java
@@ -0,0 +1,30 @@
+import java.util.Scanner;
+
+public class HowManyDogs
+{
+ public static void main (String [] args)
+ {
+ int numDogs=0;
+
+ System.out.println("How many dogs do you have?");
+ Scanner dogs= new Scanner(System.in);
+ numDogs=dogs.nextInt();
+
+ String [] dogName= new String[numDogs];
+ System.out.println("What is your dogs name?");
+ Scanner name= new Scanner(System.in);
+ for (int number=0;number=0; x++)
+ {
+
+ int choice = choose.nextInt();
+ if (choice == 99)
+ {
+ break;
+ }
+ else if (choice == 0)
+ {
+ numSold[0] = numSold[0] + 1;
+ sushi = numSold[0];
+ System.out.println("Thank you for choosing Alien Asparagus");
+ System.out.println("Sold so far: ");
+ System.out.println(sushi + " Freeze Dried Sushi");
+ System.out.println(spock + " Spock's Brain Blast");
+ System.out.println(asparagus + " Alien Asparagus");
+ }
+
+ else if (choice == 1)
+ {
+ numSold[1] = numSold[1] + 1;
+ spock=numSold[1];
+ System.out.println("Thank you for choosing Alien Asparagus");
+ System.out.println("Sold so far: ");
+ System.out.println(sushi+" Freeze Dried Sushi");
+ System.out.println(spock+" Spock's Brain Blast");
+ System.out.println(asparagus+" Alien Asparagus");
+ }
+
+ else if (choice == 2)
+ {
+ numSold[2] = numSold[2] + 1;
+ asparagus=numSold[2];
+ System.out.println("Thank you for choosing Alien Asparagus");
+ System.out.println("Sold so far: ");
+ System.out.println(sushi+" Freeze Dried Sushi");
+ System.out.println(spock+" Spock's Brain Blast");
+ System.out.println(asparagus+" Alien Asparagus");
+ }
+ }
+ System.out.println("Goodbye!");
+ printSales(sushi,spock,asparagus);
+ }
+
+ private static void printMenu(String[] menu)
+ {
+ System.out.println("Please select from: ");
+ for (String menuOptions : menu)
+ {
+ System.out.println(menuOptions);
+ }
+ }
+
+ private static void printSales(int sushiPass, int spockPass, int asparagusPass)
+ {
+ {
+ System.out.println("Thank you for choosing Alien Asparagus");
+ System.out.println("Sold so far: ");
+ System.out.println(sushiPass + " Freeze Dried Sushi");
+ System.out.println(spockPass + " Spock's Brain Blast");
+ System.out.println(asparagusPass + " Alien Asparagus");
+ }
+ }
+}
diff --git a/ch09/StringUtil.java b/ch09/StringUtil.java
new file mode 100644
index 0000000..4c09db2
--- /dev/null
+++ b/ch09/StringUtil.java
@@ -0,0 +1,61 @@
+public class StringUtil
+{
+ public static void main (String [] args)
+ {
+ getFirstCharacter("Hello");
+ getFirstCharacter("Goodbye");
+ getLastCharacter("Hello");
+ getLastCharacter("Goodbye");
+ getFirstTwoCharacters("Hello");
+ getFirstTwoCharacters("Goodbye");
+ getLastTwoCharacters("Hello");
+ getLastTwoCharacters("Goodbye");
+ getAllButFirstThreeCharacters("Hello");
+ getAllButFirstThreeCharacters("Goodbye");
+ printCharacters("Hello");
+
+ }
+ private static String getFirstCharacter(String test)
+ {
+ String answer= test.substring(0,1);
+ System.out.println(answer);
+ return answer;
+ }
+ private static String getLastCharacter (String test)
+ {
+ int start= test.length();
+ String answer=test.substring(start-1);
+ System.out.println(answer);
+ return answer;
+ }
+ private static String getFirstTwoCharacters (String test)
+ {
+ String answer=test.substring(0,2);
+ System.out.println(answer);
+ return answer;
+ }
+ private static String getLastTwoCharacters (String test)
+ {
+ int start= test.length();
+ String answer=test.substring(start-2);
+ System.out.println(answer);
+ return answer;
+ }
+ private static String getAllButFirstThreeCharacters(String test)
+ {
+ String answer=test.substring(3);
+ System.out.println(answer);
+ return answer;
+ }
+ private static int printCharacters(String test)
+ {
+ int position=0;
+ for(int x=0; x