diff --git a/ch02/.idea/vcs.xml b/ch02/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch02/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch02/Arithmetic.java b/ch02/Arithmetic.java new file mode 100644 index 0000000..6c58e37 --- /dev/null +++ b/ch02/Arithmetic.java @@ -0,0 +1,21 @@ +public class Arithmetic +{ + public static void main (String[]args) + {int num = 100; + int factor = 20; + int sum = 0; + + sum= num + factor; //100+20 + System.out.println("Addition sum: " + sum); + sum = num - factor; // 100-20 + System.out.println("Subtraction sum: " + sum); + + sum=num*factor; //100x20 + System.out.println("Multiplication sum: " + sum); + sum=num/factor; //100/20 + System.out.println("Division sum: " + sum); + + + + } +} diff --git a/ch02/Assignment.java b/ch02/Assignment.java new file mode 100644 index 0000000..8deb6d1 --- /dev/null +++ b/ch02/Assignment.java @@ -0,0 +1,23 @@ +public class Assignment +{ + public static void main (String[]args) + { + String txt="Fantastic "; + String lang="Java"; + txt+=lang; //Assign concatenated String + System.out.println("Add & Assign Strings:" +txt); + + int sum=10; + int num=20; + sum+=num; //Assign result (10+20=30) + System.out.println("Add & Assign Integers: "+sum); + + int factor = 5; + sum*= factor; //Assign result (30x5=150) + System.out.println("Multiplication sum: "+ sum); + + sum/= factor; //Assign result (150/5=30) + System.out.println("Division sum: "+ sum); + + } +} diff --git a/ch02/Constants.java b/ch02/Constants.java new file mode 100644 index 0000000..2b8ef74 --- /dev/null +++ b/ch02/Constants.java @@ -0,0 +1,21 @@ +public class Constants +{ + public static void main(String[]args) + { + final int TOUCHDOWN = 6; + final int CONVERSION = 1; + final int FIELDGOAL = 3; + + int td, pat, fg, total; + + td=4*TOUCHDOWN; + pat=3*CONVERSION; + fg=2*FIELDGOAL; + total = (td+pat+fg); + + System.out.println("Score: " + total); + + } +} + + diff --git a/ch02/DataTypes.java b/ch02/DataTypes.java new file mode 100644 index 0000000..a986e55 --- /dev/null +++ b/ch02/DataTypes.java @@ -0,0 +1,16 @@ +public class DataTypes +{ + public static void main (String[]args) + {char letter = 'M'; + String title = "Java in easy steps"; + int number = 365; + float decimal = 98.6f; + boolean result = true; + + System.out.println("Initial is " + letter); + System.out.println("Book is " + title); + System.out.println("Days are " + number); + System.out.println("Temperature is "+ decimal); + System.out.println("Answer is " + result); + } +} diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..50137ad --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,30 @@ +public class Date + +{ + public static void main (String[]args) + { + System.out.println("Date"); + System.out.println("American format:"); + String day = "Tuesday, "; + String date = "17th,"; + String month = "April "; + String year = " 2018"; + System.out.print(day); + System.out.print(month); + System.out.print(date); + System.out.println(year); + + + + System.out.println("European format:"); + String eday = "Tuesday "; + String edate = "17 "; + String emonth = "April "; + String eyear = "2018"; + System.out.print(eday); + System.out.print(emonth); + System.out.print(edate); + System.out.print(eyear); + } + } + diff --git a/ch02/FirstVariable.java b/ch02/FirstVariable.java new file mode 100644 index 0000000..104aec6 --- /dev/null +++ b/ch02/FirstVariable.java @@ -0,0 +1,12 @@ +public class FirstVariable +{ + public static void main(String[] args) + { + String message = "Initial value"; + System.out.println(message); + + message = "Modified value"; + System.out.println(message); + + } +} diff --git a/ch02/Time.java b/ch02/Time.java new file mode 100644 index 0000000..3d7ef2b --- /dev/null +++ b/ch02/Time.java @@ -0,0 +1,22 @@ +public class Time +{ + public static void main(String[] args) + {// + //undone + int hour = 15; + + int minute = 39; + int second = 43; + System.out.println(hour); + System.out.println(minute); + System.out.println(second); + + + // + + + } +} + + + diff --git a/ch02/Variables.java b/ch02/Variables.java index a295abf..b9451ca 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -1,9 +1,13 @@ /** * Examples from Chapter 2. */ -public class Variables { +public class Variables +{ + + public static void main(String[] args) + { +//Christy - public static void main(String[] args) { String message; int x; @@ -59,7 +63,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/ch03/Input.java b/ch03/Input.java index de97dc0..78f2b6d 100644 --- a/ch03/Input.java +++ b/ch03/Input.java @@ -6,11 +6,13 @@ public class Input { public static void main(String[] args) { System.out.println(System.out); - System.out.print(4.0 / 3.0); + System.out.println(4.0 / 3.0); System.out.printf("Four thirds = %.3f", 4.0 / 3.0); double pi = 3.14159; double x = (int) pi * 20.0; + + } -} + } \ No newline at end of file diff --git a/ch03/Temperature.java b/ch03/Temperature.java new file mode 100644 index 0000000..5432a40 --- /dev/null +++ b/ch03/Temperature.java @@ -0,0 +1,29 @@ +import java.util.Scanner; +public class Temperature +{public static void main(String[] args) +{String line; + +//create some variables to hold the two temperature values + double celsius; + double fahrenheit; +//create a scanner to read the keyboard input + Scanner in = new Scanner(System.in); + + // prompt the user and get Celsius value + System.out.print("What is the temperature outside in degrees Celsius?"); + //wait for the value from the keyboard and then + //assign it to the celsius variable + celsius = in.nextDouble(); + + //Show user the value they entered + System.out.println("You entered " + celsius + " for Celsius"); +//Do some math and convert from celsius and fahrenheit + fahrenheit = (celsius * 9.0/5.0)+32; + System.out.println("The temperature in Fahrenheit is: " + fahrenheit); + + + + +} + +} diff --git a/ch04/.idea/misc.xml b/ch04/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch04/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch04/.idea/modules.xml b/ch04/.idea/modules.xml new file mode 100644 index 0000000..740d4e8 --- /dev/null +++ b/ch04/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch04/.idea/vcs.xml b/ch04/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch04/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch04/.idea/workspace.xml b/ch04/.idea/workspace.xml new file mode 100644 index 0000000..7e358c3 --- /dev/null +++ b/ch04/.idea/workspace.xml @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524237464668 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch06/Demo.java b/ch06/Demo.java new file mode 100644 index 0000000..8562e6c --- /dev/null +++ b/ch06/Demo.java @@ -0,0 +1,38 @@ +public class Demo +{ + public static void main(String[] args) + { + int firstValue = 5; + int secondValue = 50; + int thirdValue = 200; + + int firstValueBig = howBig(firstValue); + int secondValueBig = howBig(secondValue); + int thirdValueBig = howBig(thirdValue); + + System.out.println("firstValue is " + firstValue + "howBig returns: " + firstValueBig); + System.out.println("secondValue is " + secondValue + "howBig returns: " + secondValueBig); + System.out.println("thirdValue is " + thirdValue + "howBig returns: " + thirdValueBig); + } + + + //returns 0 if value less than 10 + //returns 1 if value 10 to 100 + // returns 2 if value more than 100 + private static int howBig(int value) + { + int answer; + + if (value >= 10 && value <= 100) + { + answer = 1; + } else if (value > 100) + { + answer = 2; + } else + { + answer = 0; + } + return answer; + } +} \ No newline at end of file diff --git a/ch06/Divisible.java b/ch06/Divisible.java new file mode 100644 index 0000000..5f94059 --- /dev/null +++ b/ch06/Divisible.java @@ -0,0 +1,4 @@ +public class Divisible +{ public static void main(String[] args) +{} +} diff --git a/ch06/ch06.iml b/ch06/ch06.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch06/ch06.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ch07/.idea/misc.xml b/ch07/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch07/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch07/.idea/modules.xml b/ch07/.idea/modules.xml new file mode 100644 index 0000000..644f3a5 --- /dev/null +++ b/ch07/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch07/.idea/vcs.xml b/ch07/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch07/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch07/.idea/workspace.xml b/ch07/.idea/workspace.xml new file mode 100644 index 0000000..3ad95e4 --- /dev/null +++ b/ch07/.idea/workspace.xml @@ -0,0 +1,526 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524514613632 + + + 1524581437789 + + + 1524602095195 + + + 1524604357584 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/Array.java + 10 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch08/Array.java b/ch08/Array.java new file mode 100644 index 0000000..09b50a2 --- /dev/null +++ b/ch08/Array.java @@ -0,0 +1,18 @@ +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..cf83862 --- /dev/null +++ b/ch08/ArrayDemo.java @@ -0,0 +1,109 @@ +public class ArrayDemo +{ + public static void main(String[] args) + { + int[] values = {1,5,9}; // These are the values for 8-A in main + printArray(values); + System.out.println(); + + + int[] sumNumbers = {5, 7, 13}; //These are the values for 8-B in main + int sum = arrayTotal(sumNumbers); + printArray(sumNumbers); + System.out.println("The numbers added up to " + sum); + + int[] maxNumbers = {5, 8, 21, 19, 2}; //These are the values for 8-C in main + int max = arrayMax(maxNumbers); + printArray(maxNumbers); + System.out.println("The highest number is " + max); + + int[] indexNumbers = {78, 23, 9, 34}; //These are the values for 8-D in main + int index = arrayMaxIndex(indexNumbers); + printArray(indexNumbers); + System.out.println("The highest index is " + index); + + double[] avgValue = {10.0, 15.0, 20.0}; //These are the values for 8-E in main + double average = arrayAverage(avgValue); + System.out.println("The average is " + average); + + int [] values2 = new int[10]; // 8-F adding int using new keyword + values2[0]=4; + values2[3]=2; + values2[9]=4; + printArray(values2); + + String [] values3 = new String[10]; //8-G adding string using new keyword + values3[0]="Hi"; + values3[3]="Hello"; + values3[9]="Bye"; + printArray(values3); + } + + private static void printArray(int[] values)//This is the method for 8-A + { + for (int value : values) + System.out.println(value); + } + private static void printArray(String[] values)//This is the method for 8-A + { + for (String value : values) + System.out.println(value); + } + + private static int arrayTotal(int[] values) //This is the method for 8-B + { + int sum = 0; + for (int value : values) + { + sum = sum + value; + } + return sum; + } + + private static int arrayMax(int[] values) //This is the method for 8-C + { + int max = 0; + for (int value : values) + { + if (value > max) + { + max = value; + } + } + return max; + } + + private static int arrayMaxIndex(int[] values) //This is the method for 8-D + { + int max = 0; + int indexMax = 0; + int index = 0; + + for (int value : values) + { + if (value > max) + { + max = value; + indexMax = index; + } + index = index + 1; + } + return indexMax; + } + + private static double arrayAverage(double[] values) //This is the method for 8-E + { + double sum = 0.0; + for (double value : values) + { + sum = (sum + value); + } + double average = sum/values.length; + return average; + } + + +} + + + diff --git a/ch08/ch08.iml b/ch08/ch08.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch08/ch08.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ch09/.idea/misc.xml b/ch09/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch09/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch09/.idea/modules.xml b/ch09/.idea/modules.xml new file mode 100644 index 0000000..dbdfbb9 --- /dev/null +++ b/ch09/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch09/.idea/vcs.xml b/ch09/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch09/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch09/.idea/workspace.xml b/ch09/.idea/workspace.xml new file mode 100644 index 0000000..66be2de --- /dev/null +++ b/ch09/.idea/workspace.xml @@ -0,0 +1,413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524756149220 + + + 1524778544508 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/ch10/Student.java b/ch10/Student.java new file mode 100644 index 0000000..dc582b6 --- /dev/null +++ b/ch10/Student.java @@ -0,0 +1,33 @@ +public class Student +{ + private String name; + private int studentId; + private double gpa; + + public String getName() + { + return name; + } + + public int getStudentId() + { + return studentId; + } + + public double getGpa() + { + return gpa; + } + + public Student (String name, int studentId) + { + this.name = name; + this.studentId = studentId; + } + + + + + + +} diff --git a/ch10/StudentTester.java b/ch10/StudentTester.java new file mode 100644 index 0000000..155b7b4 --- /dev/null +++ b/ch10/StudentTester.java @@ -0,0 +1,42 @@ +public class StudentTester +{ + public static void main(String[] args) + { + 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); + System.out.println(josiah.getName()); + + Student christy = new Student("Christy", 5); + System.out.println(christy.getName()); + + Student luke = new Student("Luke", 6); + System.out.println(luke.getName()); + + Student[] frontRowStudents = new Student[3]; + frontRowStudents[0] = maggie; + frontRowStudents[1] = tim; + frontRowStudents[2] = joseph; + printStudents(frontRowStudents); + + Student[] backRowStudents = new Student[3]; + backRowStudents[0] = josiah; + backRowStudents[1] = christy; + backRowStudents[2] = luke; + printStudents(backRowStudents); + } + private static void printStudents(Student[] students) + { + for (Student student :students) + { + System.out.println(student.getName()); + } + } +} \ No newline at end of file diff --git a/ch10/ch10.iml b/ch10/ch10.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ch10/ch10.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ch11/.idea/misc.xml b/ch11/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/ch11/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch11/.idea/modules.xml b/ch11/.idea/modules.xml new file mode 100644 index 0000000..6a1ca0a --- /dev/null +++ b/ch11/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ch11/.idea/vcs.xml b/ch11/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ch11/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ch11/.idea/workspace.xml b/ch11/.idea/workspace.xml new file mode 100644 index 0000000..0ad3c61 --- /dev/null +++ b/ch11/.idea/workspace.xml @@ -0,0 +1,393 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +