diff --git a/ch04/HelloMethod.java b/ch04/HelloMethod.java new file mode 100644 index 0000000..a285fcb --- /dev/null +++ b/ch04/HelloMethod.java @@ -0,0 +1,35 @@ +import java.sql.SQLOutput; + +public class HelloMethod +{ + public static void main(String[] args) + { + String firstName = "Fred "; + String secondName = "Wilma "; + String thirdName = "Pebbles"; + String lastName = "Flintstone"; + printHelloWorld(firstName, lastName); + printHelloWorld(secondName, lastName); + printHelloWorld(thirdName, lastName); + printOhNo(); + } + + public static void printHelloWorld(String fname, String lName) + { + System.out.println("Hello World " + fname + lName); + } + + public static void printOhNo() + { + System.out.println("Oh No !!!!!!!!!!"); + + } + + public static void printNumberNoSign(int number) + { + + } + + +} + diff --git a/ch05/.idea/vcs.xml b/ch05/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch05/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch05/Comparison.java b/ch05/Comparison.java new file mode 100644 index 0000000..47b93b5 --- /dev/null +++ b/ch05/Comparison.java @@ -0,0 +1,25 @@ +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); + System.out.println("string Inequality Test: "+state); + + int dozen =12; + int score =20; + state =(dozen>score); + System.out.println("Greater Than Test: "+state); + + state =(dozen 3) + System.out.println("This order is crazy and you are stupid. We obviously don't sell that here."); + + System.out.println("How many yards would you like?"); + int length = scanner.nextInt(); + + if (length > 1000) + System.out.println("This order is crazy and you are stupid. There's not that much cheese in Wisconsin."); + System.out.println("Your total delivered cost is:"); + boolean price1 = diameter == 1; + boolean shipping1 = diameter == 1; + boolean price2 = diameter == 2; + boolean shipping2 = diameter == 2; + boolean price3 = diameter == 3; + boolean shipping3 = diameter == 3; + + + { + if (price1 && length <= 50) + System.out.println("$" + (2 * (length) + 2 * (length))); + + if (price1 && length > 50) + System.out.println("$" + (2 * (length))); + + + if (price2 && length <= 50) + System.out.println("$" + (4 * (length) + 2 * (length))); + + if (price2 && length > 50) + System.out.println("$" + (4 * (length))); + + if (price3 && length <= 50) + System.out.println("$" + (6 * (length) + 4 * (length))); + + if (price3 && length > 50) + System.out.println("$" + (6 * (length))); + + + + /* if (price4) + System.out.println("This order is crazy and you are stupid. We obviously don't sell that here."); +*/ + } +/* public static void priceperyard(int price) + { + + + switch (price) + { + case 1: price=2; + + System.out.println("The price of your order is:"+price*length); + case 2: price=3; + case 3: price=6; + + + } +*/ + } + + +} + diff --git a/ch05/Logic.java b/ch05/Logic.java new file mode 100644 index 0000000..a04845a --- /dev/null +++ b/ch05/Logic.java @@ -0,0 +1,17 @@ +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 YesNot 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/Precedence.java b/ch05/Precedence.java new file mode 100644 index 0000000..a67cc97 --- /dev/null +++ b/ch05/Precedence.java @@ -0,0 +1,14 @@ +public class Precedence +{ + public static void main(String[] args) + { + int sum = 32-8+16*2; + System.out.println("Default order: "+sum); + + sum=(32-8+16)*2; + System.out.println("Specified order: "+sum); + + sum=(32-(8+16))*2; + System.out.println("Nested specific order: "+sum); + } +} diff --git a/ch05/Switch.java b/ch05/Switch.java new file mode 100644 index 0000000..c1e8fde --- /dev/null +++ b/ch05/Switch.java @@ -0,0 +1,22 @@ +public class Switch +{ + public static void main(String[] args) + { + int month = 2, year = 2016, 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/ch06/.idea/vcs.xml b/ch06/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch06/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch06/Demo.java b/ch06/Demo.java new file mode 100644 index 0000000..c0c9486 --- /dev/null +++ b/ch06/Demo.java @@ -0,0 +1,32 @@ +import java.util.Scanner; + +public class Demo +{ + public static void main(String[] args) + { + printGreeting("HELLO"); + + + Scanner in = new Scanner(System.in); + + System.out.println("Enter a number:"); + + int firstNumber=in.nextInt(); + + System.out.println("Enter a number:"); + + int secondNumber=in.nextInt(); + + int total = firstNumber + secondNumber; + System.out.println("the total is "+total); + } + + public static void printTotal() + { + + } + public static void printGreeting(String greeting) + { + System.out.println("<<<"+ greeting + ">>>"); + } +} diff --git a/ch06/MathUtil.java b/ch06/MathUtil.java new file mode 100644 index 0000000..26e2ae8 --- /dev/null +++ b/ch06/MathUtil.java @@ -0,0 +1,55 @@ +public class MathUtil +{ + public static void main(String[] args) + { + int total = getTotal(1, 2); + + System.out.println(total); + double cargoVolume = getCargoVolume(2, 2, 2, false); + System.out.println(cargoVolume); + + int absoluteAnswer = absoluteSum(-5, 2); + System.out.println(absoluteAnswer); + + int absoluteAnswerTwo = absoluteSum(-5, 2, -3); + System.out.println(absoluteAnswerTwo); + + } + + public static int getTotal(int firstNumber, int secondNumber) + { + int sum = firstNumber + secondNumber; + + return sum; + } + + public static double getCargoVolume(double height, double length, double depth, boolean heavyDuty) + { + + double materialThickness = .25; + if (heavyDuty) ; + materialThickness = .25 * 2; + double interiorHeight = height - (2 * materialThickness); + double interiorLength = length - (2 * materialThickness); + double interiorDepth = depth - (2 * materialThickness); + double cargoVolume = interiorHeight * interiorLength * interiorDepth; + return cargoVolume; + } + + public static int absoluteSum(int numberone, int numberTwo) + { + int absoluteOne = Math.abs(numberone); + int absoluteTwo = Math.abs(numberTwo); + int absoluteAnswer = absoluteOne + absoluteTwo; + return absoluteAnswer; + } + + public static int absoluteSum(int numberone, int numberTwo, int numberThree) + { + int absoluteOne = Math.abs(numberone); + int absoluteTwo = Math.abs(numberTwo); + int absoluteThree = Math.abs(numberThree); + int absoluteAnswerTwo = absoluteOne + absoluteTwo + absoluteThree; + return absoluteAnswerTwo; + } +} diff --git a/ch06/Names.java b/ch06/Names.java new file mode 100644 index 0000000..ad8d04c --- /dev/null +++ b/ch06/Names.java @@ -0,0 +1,24 @@ +public class Names +{ + public static void main(String[] args) + { + //String decoration=%%%%%%%; + String returnValue=getMyName(); + + String fancyName=getMyFancyName("%%%%%%%%"); + + System.out.println(returnValue); + System.out.println(fancyName); + } + + public static String getMyName( ) + + { + return "Stephen"; + } + public static String getMyFancyName(String decoration) + { + String fancyName = decoration +"Stephen"+decoration; + return fancyName; + } +}