diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e022fe3 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..160ced8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.settings/ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..5cf5293 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + APCS + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/Exam/frq2017/Digits.java b/Exam/frq2017/Digits.java new file mode 100644 index 0000000..bd183f9 --- /dev/null +++ b/Exam/frq2017/Digits.java @@ -0,0 +1,27 @@ +package frq2017; + +import java.util.ArrayList; + +public class Digits { + private ArrayList digitList; + + public static void main(String[] args) { + Digits d1 = new Digits(15704); + + } + + public Digits(int num) { + int length = Integer.toString(num).length(); + for(int i = 0; i < length; i++) { + digitList.add(0, num%10); + num/=10; + } + System.out.print(num); + } + + public boolean isStriclyIncreasing() { + return false; + } + + +} diff --git a/Exam/frq2018/Answers.txt b/Exam/frq2018/Answers.txt new file mode 100644 index 0000000..8d0e019 --- /dev/null +++ b/Exam/frq2018/Answers.txt @@ -0,0 +1,103 @@ +GARY TOU - 6th Period +May 28th, 2018 +--------------------- + +//QUESTION 1 +//a +public boolean simulate(){ + int distance = 0; + for(int i = 0; i < maxHops; i++){ + distance += hopeDistance(); + if(distance < 0){ + return false; + } else if(distance >= goalDistance){ + return true; + } + } + return false; +} + +//b +public double runSimulation(int num){ + int wins = 0; + for(int i = 0; i < num; i++){ + if(simulate()){ + wins++; + } + } + return (double)wins/num; +} + +//QUESTION 2 +//a +/** +* constructor +*/ +public WordPairList(String[] words){ + for(int i = 0; i < words.length-1; i++){ + for(int k = i+1; k < words.length; k++){ + allPairs.add(new WordPair(words[i], words[k]); + } + } +} +//b +public int numMatches(){ + int matches = 0; + for(wordPair p : allPairs){ + if(p.getFirst().equals(p.getSecond())){ + matches++; + } + } + return matches; +} + +//QUESTION 3 +//a +public class CodeWordChecker impliments StringChecker{ + int start; + int end; + String value; + + public CodeWordChecker(String value){ + StringChecker(6, 20, value); + } + public CodeWordChecker(int start, int end, String value){ + this.start = start; + this.end = end; + this.value = value; + } + boolean isValid(String str){ + if(str.length > end || str.length < start){ + return false; + } else if (str.contains(value)){ + return false; + } + return true; + } +} + +//QUESTION 4 +//a +public static int[] getColumn(int[][] arr2D, int c){ + int[] arr = new int[arr2D.length]; + + for(int i = 0; i < arr2D.length; i++){ + arr[i] = arr2D[i][c]; + } +} +//b +public static boolean isLatin(int[][] square(){ + if(containsDuplicates(square[0])){ + return false; + } + for(int i = 0; i < square.length; i++){ + if(! hasAllValues(square[0], square[i])){ + return false; + } + for(int i = 0; i < square.length[0]; i++){ + if(! hasAllValues(square[0], getColumn[i])){ + return false; + } + return true; +} + \ No newline at end of file diff --git a/ExamPrep/DiagnosticExam/AP CS MOOC Diagnostic Summary.pdf b/ExamPrep/DiagnosticExam/AP CS MOOC Diagnostic Summary.pdf new file mode 100644 index 0000000..b162326 Binary files /dev/null and b/ExamPrep/DiagnosticExam/AP CS MOOC Diagnostic Summary.pdf differ diff --git a/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_answer_sheet.pdf b/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_answer_sheet.pdf new file mode 100644 index 0000000..5cf6010 Binary files /dev/null and b/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_answer_sheet.pdf differ diff --git a/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_questions.pdf b/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_questions.pdf new file mode 100644 index 0000000..865a067 Binary files /dev/null and b/ExamPrep/DiagnosticExam/Diagnostic_AP_EXAM_questions.pdf differ diff --git a/ExamPrep/DiagnosticExam/ap-computer-science-a-2014-java-quick-reference.pdf b/ExamPrep/DiagnosticExam/ap-computer-science-a-2014-java-quick-reference.pdf new file mode 100644 index 0000000..702005e Binary files /dev/null and b/ExamPrep/DiagnosticExam/ap-computer-science-a-2014-java-quick-reference.pdf differ diff --git a/ExamPrep/DiagnosticExam/url.txt b/ExamPrep/DiagnosticExam/url.txt new file mode 100644 index 0000000..14b2344 --- /dev/null +++ b/ExamPrep/DiagnosticExam/url.txt @@ -0,0 +1,3 @@ +Check your answers: + +https://docs.google.com/forms/d/e/1FAIpQLSfmo3CJPxiKcyTku930wv8lc-SVHP_dE7wEqVhdLQFW9-lU2Q/viewform \ No newline at end of file diff --git a/README.md b/README.md index 39af1c1..e42bbb0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # APCS Edhesive Hello! My name is Gary Tou, a student who took the Edhesive AP Computer Science Course in 2017-2018. As of September 2018, I had decided to remove my solutions due to the increase attention this repository has been recieving. I hope you would learn how to solve them yourself! @@ -13,3 +14,4 @@ If you every have any questions about Java or programming in general, feel free Good luck on the AP Exam, Gary Tou + diff --git a/Term1/Assignments/Alien_Message_Board_4.java b/Term1/Assignments/Alien_Message_Board_4.java new file mode 100644 index 0000000..af4b589 --- /dev/null +++ b/Term1/Assignments/Alien_Message_Board_4.java @@ -0,0 +1,75 @@ +package Assignments; +import java.util.Scanner; + + +public class Alien_Message_Board_4 { + + static int swear1 = 0, swear2 = 0, swear3 = 0; //swear1 = ^^, swear2 = QEY, swear3 = $ + static boolean swear = false; + + static Scanner scan = new Scanner (System.in); + static String input = scan.nextLine(); + + static String username = input.substring(0, input.indexOf(' ')); + static String message = (input.substring(input.indexOf(' ') + 3)).toUpperCase(); + + + + public static void main(String[] args) { + String splitString = message; + + if(splitString.indexOf(' ') > -1) { + + while (splitString.indexOf(' ') > -1) { + String currentWord = splitString.substring(0, splitString.indexOf(' ')); + checkSwear(currentWord); + + splitString = splitString.substring(splitString.indexOf(' ')+1); + } + + checkSwear(splitString); + + } + else { + checkSwear(splitString); + } + + + + printStats(); + } + + + public static void checkSwear(String checkSwearMessage) { + //System.out.println(checkSwearMessage); + if ((checkSwearMessage.compareTo("^^")) == 0) { + swear1++; + swear = true; + } + if ((checkSwearMessage.compareTo("QEY") == 0)) { + swear2++; + swear = true; + } + if ((checkSwearMessage.compareTo("$")) == 0) { + swear3++; + swear = true; + } + + + } + + public static void printStats() { + if(!swear) { + System.out.println("Results:\nCLEAN"); + } + else { + System.out.println("Results:\nBAD"); + System.out.println(username); + + System.out.println("^^: " + swear1); + System.out.println("qey: " + swear2); + System.out.println("$: " + swear3); + + } + } +} \ No newline at end of file diff --git a/Term1/Assignments/Alien_Message_Board_4_ONE_METHOD.java b/Term1/Assignments/Alien_Message_Board_4_ONE_METHOD.java new file mode 100644 index 0000000..9709b38 --- /dev/null +++ b/Term1/Assignments/Alien_Message_Board_4_ONE_METHOD.java @@ -0,0 +1,89 @@ +package Assignments; +import java.util.Scanner; + + +public class Alien_Message_Board_4_ONE_METHOD { + + public static void main(String[] args) { + + int swear1 = 0, swear2 = 0, swear3 = 0; //swear1 = ^^, swear2 = QEY, swear3 = $ + boolean swear = false; + + Scanner scan = new Scanner (System.in); + String input = scan.nextLine(); + + String username = input.substring(0, input.indexOf(' ')); + String message = (input.substring(input.indexOf(' ') + 3)).toUpperCase(); + + + String splitString = message; + //System.out.println("start"); + if(splitString.indexOf(' ') > -1) { + //System.out.println("in if"); + while (splitString.indexOf(' ') > -1) { + String currentWord = splitString.substring(0, splitString.indexOf(' ')); + //System.out.println(currentWord); + if ((currentWord.compareTo("^^")) == 0) { + swear1++; + swear = true; + } + if ((currentWord.compareTo("QEY") == 0)) { + swear2++; + swear = true; + } + if ((currentWord.compareTo("$")) == 0) { + swear3++; + swear = true; + } + + splitString = splitString.substring(splitString.indexOf(' ')+1); + } + + if ((splitString.compareTo("^^")) == 0) { + swear1++; + swear = true; + } + if ((splitString.compareTo("QEY") == 0)) { + swear2++; + swear = true; + } + if ((splitString.compareTo("$")) == 0) { + swear3++; + swear = true; + + } + } + + else { + //System.out.println("in else"); + if ((splitString.compareTo("^^")) == 0) { + swear1++; + swear = true; + } + if ((splitString.compareTo("QEY") == 0)) { + swear2++; + swear = true; + } + if ((splitString.compareTo("$")) == 0) { + swear3++; + swear = true; + } + } + + //System.out.println("before print"); + if(!swear) { + System.out.println("Results:\nCLEAN"); + } + else { + System.out.println("Results:\nBAD"); + System.out.println(username); + + System.out.println("^^: " + swear1); + System.out.println("qey: " + swear2); + System.out.println("$: " + swear3); + } + //System.out.println("end"); + + scan.close(); + } +} diff --git a/Term1/Assignments/Crack_the_Code_3.java b/Term1/Assignments/Crack_the_Code_3.java new file mode 100644 index 0000000..c372146 --- /dev/null +++ b/Term1/Assignments/Crack_the_Code_3.java @@ -0,0 +1,65 @@ +package Assignments; + +import java.util.Scanner; + +public class Crack_the_Code_3 { + + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + boolean incorrect = false; //false, not incorrect + int one, two, three; + + System.out.println("Welcome. What is your name?"); + String name = scan.nextLine(); + System.out.println("Hello " + name + ". Try your best to crack the code!\n"); + + //PHASE ONE + if(!incorrect) { + System.out.println("PHASE 1\nEnter a number:"); + one = scan.nextInt(); + if (one == 3) { + System.out.println("Correct!\n"); + } + else { + System.out.println("Sorry, that was incorrect!\nBetter luck next time!"); + incorrect = true; + } + } + + + //PHASE TWO + if(!incorrect) { + System.out.println("PHASE 2\nEnter a number:"); + two = scan.nextInt(); + if ((two == 1) || ((two >= 33) && (two <=100))) { + System.out.println("Correct!\n"); + } + else { + System.out.println("Sorry, that was incorrect!\nBetter luck next time!"); + incorrect = true; + } + } + + + //PHASE THREE + if(!incorrect) { + System.out.println("PHASE 3\nEnter a number:"); + three = scan.nextInt(); + if ((three > 0) && ((three % 3 == 0) || (three % 7 == 0))) { + System.out.println("Correct!\n"); + } + else { + System.out.println("Sorry, that was incorrect!\nBetter luck next time!"); + incorrect = true; + } + } + + if(!incorrect) { + System.out.println("You have cracked the code!"); + } + + scan.close(); + + } + +} \ No newline at end of file diff --git a/Term1/Assignments/Movie_Ratings_1.java b/Term1/Assignments/Movie_Ratings_1.java new file mode 100644 index 0000000..22c9a61 --- /dev/null +++ b/Term1/Assignments/Movie_Ratings_1.java @@ -0,0 +1,47 @@ +package Assignments; +import java.util.Scanner; + +public class Movie_Ratings_1 { + + public static void main(String[] args) { + + //Website ratings + int web1, web2, web3; + //Focus group ratings + double fg1, fg2; + //Movie critic rating + double c; + //Averages of Website and Focus group + double aw, afg; + + Scanner scan = new Scanner (System.in); + + + System.out.println("Please enter ratings from the movie review website."); + web1 = scan.nextInt(); + web2 = scan.nextInt(); + web3 = scan.nextInt(); + + System.out.println("\nPlease enter ratings from the focus group."); + fg1 = scan.nextDouble(); + fg2 = scan.nextDouble(); + + System.out.println("\nPlease enter the average movie critic rating."); + c = scan.nextDouble(); + + + aw = (((double)web1 + (double)web2 + (double)web3)/3); + afg = (((double)fg1 + (double)fg2)/2); + + + System.out.println("\nAverage website rating: " + aw); + System.out.println("Average focus group ratting: " + afg); + System.out.println("Average movie scritic rating: " + c); + + System.out.println("Overall movie rating: " + ((aw * .20)+(afg * .30)+(c * .50))); + + + + } + +} \ No newline at end of file diff --git a/Term1/Assignments/Names_Merge_6.java b/Term1/Assignments/Names_Merge_6.java new file mode 100644 index 0000000..d326e0e --- /dev/null +++ b/Term1/Assignments/Names_Merge_6.java @@ -0,0 +1,228 @@ +package Assignments; + +import java.util.Scanner; + +//test + +/* + +In this lab, you will be creating a program that merges two arrays of names. Your program will accept each array as input from the keyboard taking all strings and then reformat them in title case. For example, "jOHN" would convert to "John", "megan" would convert to "Megan", and "ADAm" would convert to "Adam". + +You do not know ahead of time how many values will be entered, but you can assume each array will have a maximum length of 10,000 elements. To stop entering values the user will enter the word "End". Note: that any combination of lowercase and uppercase characters that spell "End" should terminate asking for input. + +The elements of the two input arrays should be in alphabetical order. In other words, each array element must have a value that is greater than or equal to the previous element value. + +After the two arrays have been input, your program must check to make sure the elements of each array have been entered in order. If an out of order element is found, print the message "ERROR: Array not in correct order". + +Your task is to merge the two input arrays into a new array, with all elements in alphabetical order. Print out each of the original arrays entered, followed by the merged array. + +Please note that your program must output the arrays with exactly one space between each name. + +Determining alphabetical order: take a look back at the lesson on String functions and specifically the compareTo method. + +Sample Run 1: + +Enter the values for the first array, up to 10000 values, enter 'End' to quit +Alf +BOB +heATher +john +ZoE +eNd + +Enter the values for the second array, up to 10000 values, enter 'End' to quit +Chloe +dylan +michAEL +END + +First Array +Alf Bob Heather John Zoe + +Second Array +Chloe Dylan Michael + +Merged Array +Alf Bob Chloe Dylan Heather John Michael Zoe +Sample Run 2: + +Enter the values for the first array, up to 10000 values, enter 'End' to quit +heATher +john +ZoE +Alf +BOB +eNd + +Enter the values for the second array, up to 10000 values, enter 'End' to quit +Chloe +dylan +michAEL +END + +First Array +Alf Bob Heather John Zoe + +Second Array +Chloe Dylan Michael + +Error: Arrays not in correct order + + */ + +public class Names_Merge_6 { + + static boolean incorrectOrder; + +//MAIN + public static void main(String[] args) { + arrayEntry(); + } + +//ARRAY ENTRY + public static void arrayEntry() { + //String[] arrayOne = entryArray(1); + //String[] arrayTwo = entryArray(2); + merge(entryArray(1), entryArray(2)); + } + +//ENTRYCODE + public static String[] entryArray(int arrayNum) { + boolean continue_entry = true; //flag varible + int elementNum = 0; + String text = null; + String last_entry = ""; + String[] array = new String[10000]; + if(arrayNum == 1) { + text = "first"; + } + else if(arrayNum == 2) { + text = "second"; + } + + + System.out.println("Enter the values for the " + text + " array, up to 10000 values, enter 'End' to quit"); + Scanner scan = new Scanner (System.in); + //scan.next(); //tired using this to fix the next line problem, doesn't work + while(continue_entry) { + //FIXME: not working, Edhesive isn't showing a nextLine + //if(scan.hasNextLine()){ + String entry = scan.nextLine(); //scans for name + //System.out.println(entry); + //} + // + + if((entry.toUpperCase().compareTo("END")==0)) { //If entry is less than last entry or if is "END" + continue_entry = false; + } + else if (entry != null){ + array[elementNum] = entry; //sets entry to it's element in the array + elementNum++; + + if(entry.compareTo(last_entry)<0) { + incorrectOrder = true; + } + + last_entry = entry; + + } + } + if(arrayNum == 1) + System.out.println(); + + //correct case, HEy -> Hey + for(int i = 0; i < array.length; i++) { + if(array[i] == null) { + break; + } + else { + //FIXME: string index out of range: 1 + array[i] = array[i].trim(); + String firstLetter = (array[i].substring(0, 1)).toUpperCase(); + String restLetters = (array[i].substring(1)).toLowerCase(); + String name = firstLetter+restLetters; + array[i] = name; + } + } + return array; + } + +//MERGE + public static void merge(String [] arrayOne, String [] arrayTwo) { + String[] mergedArray = new String[20000]; + + } + /*public static void merge(String [] arrayOne, String [] arrayTwo) { + String[] mergedArray = new String[20000]; //20,000 because if arrayOne has 10,000 and arrayTwo has 10,000. Combined will be 20,000 + int elementNumOne = 0; + int elementNumTwo = 0; + int elementNumMerged = 0; + + //TODO review how compareTo works, does it compare this to var to var to this + while(elementNumOne<=10000 && elementNumTwo<=10000) { + if((arrayOne[elementNumOne] == null) && (arrayTwo[elementNumTwo] == null)) { + break; + } + else { + if((arrayOne[elementNumOne] != null) && (arrayTwo[elementNumTwo] != null)) { + if(arrayOne[elementNumOne].compareTo(arrayTwo[elementNumTwo])<=0) { + mergedArray[elementNumMerged] = arrayOne[elementNumOne]; + elementNumMerged++; + elementNumOne++; + } + else{ + mergedArray[elementNumMerged] = arrayTwo[elementNumTwo]; + elementNumMerged++; + elementNumTwo++; + } + } + else if((arrayOne[elementNumOne] == null) && (arrayTwo[elementNumTwo] != null)) { + mergedArray[elementNumMerged] = arrayTwo[elementNumTwo]; + elementNumMerged++; + elementNumTwo++; + } + else { + mergedArray[elementNumMerged] = arrayOne[elementNumOne]; + elementNumMerged++; + elementNumOne++; + } + } + } + + print(arrayOne, 1); + print(arrayTwo, 2); + print(mergedArray, 3); + System.out.print("\n" + (incorrectOrder ? "Error: Arrays not in correct order" : "")); + }*/ + + +//PRINT + public static void print(String [] array, int arrayNum) { //This method prints out the merged array + String text = null; + if(arrayNum == 1) { + text = "First"; + } + else if(arrayNum == 2) { + text = "Second"; + } + else if(arrayNum == 3) { + text = "Merged"; + } + else { + System.out.println("ERROR - arrayNum not 1 or 2 or 3"); + } + + System.out.println(); + System.out.println(text + " Array"); + for(int i = 0; i < array.length; i++) { + if(array[i] != null) { //checks if there is something in the array element + if(i==array.length-1) //prints the last element without a space at the end + System.out.print(array[i]); + else + System.out.print(array[i] + " "); //prints element with one space at the end + } + } + System.out.println(); + } + +} \ No newline at end of file diff --git a/Term1/Assignments/Names_Merge_6_ArrayList.java b/Term1/Assignments/Names_Merge_6_ArrayList.java new file mode 100644 index 0000000..28f6bdd --- /dev/null +++ b/Term1/Assignments/Names_Merge_6_ArrayList.java @@ -0,0 +1,184 @@ +package Assignments; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +//test + +/* + +In this lab, you will be creating a program that merges two arrays of names. Your program will accept each array as input from the keyboard taking all strings and then reformat them in title case. For example, "jOHN" would convert to "John", "megan" would convert to "Megan", and "ADAm" would convert to "Adam". + +You do not know ahead of time how many values will be entered, but you can assume each array will have a maximum length of 10,000 elements. To stop entering values the user will enter the word "End". Note: that any combination of lowercase and uppercase characters that spell "End" should terminate asking for input. + +The elements of the two input arrays should be in alphabetical order. In other words, each array element must have a value that is greater than or equal to the previous element value. + +After the two arrays have been input, your program must check to make sure the elements of each array have been entered in order. If an out of order element is found, print the message "ERROR: Array not in correct order". + +Your task is to merge the two input arrays into a new array, with all elements in alphabetical order. Print out each of the original arrays entered, followed by the merged array. + +Please note that your program must output the arrays with exactly one space between each name. + +Determining alphabetical order: take a look back at the lesson on String functions and specifically the compareTo method. + +Sample Run 1: + +Enter the values for the first array, up to 10000 values, enter 'End' to quit +Alf +BOB +heATher +john +ZoE +eNd + +Enter the values for the second array, up to 10000 values, enter 'End' to quit +Chloe +dylan +michAEL +END + +First Array +Alf Bob Heather John Zoe + +Second Array +Chloe Dylan Michael + +Merged Array +Alf Bob Chloe Dylan Heather John Michael Zoe +Sample Run 2: + +Enter the values for the first array, up to 10000 values, enter 'End' to quit +heATher +john +ZoE +Alf +BOB +eNd + +Enter the values for the second array, up to 10000 values, enter 'End' to quit +Chloe +dylan +michAEL +END + +First Array +Alf Bob Heather John Zoe + +Second Array +Chloe Dylan Michael + +Error: Arrays not in correct order + + */ + +public class Names_Merge_6_ArrayList { + + static boolean incorrectOrder; + +//MAIN + public static void main(String[] args) { + merge(entryArray(1), entryArray(2)); + } + +//ENTRYCODE + public static ArrayList entryArray(int arrayNum) { + boolean continue_entry = true; //flag varible + String text = null; + String last_entry = ""; + ArrayList list = new ArrayList(); + if(arrayNum == 1) { + text = "first"; + } + else if(arrayNum == 2) { + text = "second"; + } + + + System.out.println("Enter the values for the " + text + " array, up to 10000 values, enter 'End' to quit"); + Scanner scan = new Scanner (System.in); + //scan.next(); //tired using this to fix the next line problem, doesn't work + while(continue_entry) { + String entry = scan.nextLine(); //scans for name + + if((entry.toUpperCase().compareTo("END")==0)) { //If entry is less than last entry or if is "END" + continue_entry = false; + } + else if (entry != null){ + list.add(entry); + + if(entry.compareTo(last_entry)<0) { + incorrectOrder = true; + } + + last_entry = entry; + + } + } + if(arrayNum == 1) + System.out.println(); + + //correct case, HEy -> Hey + for(int i = 0; i < list.size(); i++) { + /*array[i] = array[i].trim(); + String firstLetter = (array[i].substring(0, 1)).toUpperCase(); + String restLetters = (array[i].substring(1)).toLowerCase(); + String name = firstLetter+restLetters; + array[i] = name;*/ + String name = list.get(i).trim(); + name = name.trim(); + name = name.toUpperCase().substring(0, 1) + name.toLowerCase().substring(1); + list.set(i, name); + } + return list; + } + +//MERGE + public static void merge(ArrayList arrayOne, ArrayList arrayTwo) { + ArrayList mergedArray = new ArrayList(arrayOne); + + for(int i = 0; i < arrayTwo.size(); i++) { + mergedArray.add(arrayTwo.get(i)); + } + + Collections.sort(mergedArray); + Collections.sort(arrayOne); + Collections.sort(arrayTwo); + + print(arrayOne, 1); + print(arrayTwo, 2); + print(mergedArray, 3); + System.out.print("\n" + (incorrectOrder ? "Error: Arrays not in correct order" : "")); + + } + +//PRINT + public static void print(ArrayList array, int arrayNum) { //This method prints out the merged array + String text = null; + if(arrayNum == 1) { + text = "First"; + } + else if(arrayNum == 2) { + text = "Second"; + } + else if(arrayNum == 3) { + text = "Merged"; + } + else { + System.out.println("ERROR - arrayNum not 1 or 2 or 3"); + } + + System.out.println(); + System.out.println(text + " Array"); + for(int i = 0; i < array.size(); i++) { + if(array.get(i) != null) { //checks if there is something in the array element + if(i==array.size()-1) //prints the last element without a space at the end + System.out.print(array.get(i)); + else + System.out.print(array.get(i) + " "); //prints element with one space at the end + } + } + System.out.println(); + } + +} \ No newline at end of file diff --git a/Term1/Assignments/Names_Merge_6_Michael.java b/Term1/Assignments/Names_Merge_6_Michael.java new file mode 100644 index 0000000..027cbb6 --- /dev/null +++ b/Term1/Assignments/Names_Merge_6_Michael.java @@ -0,0 +1,282 @@ +package Assignments; + +import java.util.Scanner; + +public class Names_Merge_6_Michael { + + public static void main(String[] args) { + assignment6(); + + } + public static void assignment6() { + boolean incorrectOrder1 = false; + boolean incorrectOrder2 = false; + Scanner sc = new Scanner(System.in); + String temp = ""; + String [] one = new String[10000]; + String[] two = new String[10000]; + String text = null; + String last = temp; + System.out.println("Enter the values for the first array, up to 10000 values, enter 'End' to quit"); + + for(int i = 0; i0) + { + + mergedNull[z] = two[y]; + /*System.out.println(x); + System.out.println(y); + System.out.println(z); + System.out.println(flag); + System.out.println(Arrays.toString(mergedNull)); + System.out.println(" ");*/ + + if(y==two.length-1) + flag =2; + + if(y=0; v-- ) { + temp[v] = array[v]; + + + } + for(int v = array.length-1; v >=0; v-- ) { + array[v] = temp[count]; + + count++; + } + System.out.print(array[0]+" "+array[1]+" "+array[2]+" "); + + } + + +} diff --git a/Term1/Assignments/Time_Converter_2.java b/Term1/Assignments/Time_Converter_2.java new file mode 100644 index 0000000..a94f359 --- /dev/null +++ b/Term1/Assignments/Time_Converter_2.java @@ -0,0 +1,87 @@ +/* +Instructions: + Seconds Since Unix Epoch: + 999999999 + + Year: 2002 + Month: 1 + Day: 24 + Hour: 1 + Min: 46 + Sec: 39 + + + Seconds Since Unix Epoch: + 178437 + + Year: 1970 + Month: 0 + Day: 2 + Hour: 1 + Min: 33 + Sec: 57 + + */ + +package Assignments; + +import java.util.Scanner; + + +public class Time_Converter_2 { + + public static void main(String[] args) { + + Scanner scan = new Scanner (System.in); + + int inputSec; + int Year, Month, Day, Hour, Min, Sec; + int YearMod, MonthMod, DayMod, HourMod, MinMod; + + int secInYear = 31104000; + int secInMonth = 2592000; + int secInDay = 86400; + int secInHour = 3600; + int secInMin = 60; + + + + System.out.println("Seconds Since Unix Epoch:"); + inputSec = scan.nextInt(); + + + //Sec. in Year 60*60*24*360=31104000 + Year = (inputSec/secInYear) + 1970; + YearMod = (inputSec%secInYear); + + //Sec. in Month 60*60*24*30=2592000 + Month = YearMod/secInMonth; + MonthMod = YearMod%secInMonth; + + //Sec. in Day 60*60*24=86400 + Day = MonthMod/secInDay; + DayMod = MonthMod%secInDay; + + //Sec. in Hour 60*60=3600 + Hour = (int)DayMod/secInHour; + HourMod = DayMod%secInHour; + + //Sec. in Min 60 + Min = (int)HourMod/secInMin; + MinMod = HourMod%secInMin; + + //Sec. in Sec 1 + Sec = MinMod; + + + System.out.println(); + System.out.println("Year: " + Year); + System.out.println("Month: " + Month); + System.out.println("Day: " + Day); + System.out.println("Hour: " + Hour); + System.out.println("Min: " + Min); + System.out.println("Sec: " + Sec); + + + } +} diff --git a/Term1/Lesson1/Lesson_1_Activity_One.java b/Term1/Lesson1/Lesson_1_Activity_One.java new file mode 100644 index 0000000..a2b13ba --- /dev/null +++ b/Term1/Lesson1/Lesson_1_Activity_One.java @@ -0,0 +1,25 @@ +package Lesson1; +/* + * Lesson 1 Coding Activity Question 1 + * + * Write a program to print your name to the center of the output screen. + * Use tabs or spaces to center your output, depending on how wide your screen is. + * For the code-runner, only one tab or space will be needed for your program to + * be counted as acceptable. + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_1_Activity_One { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.println(" Gary"); + + } +} \ No newline at end of file diff --git a/Term1/Lesson1/Lesson_1_Activity_Three.java b/Term1/Lesson1/Lesson_1_Activity_Three.java new file mode 100644 index 0000000..e51e03d --- /dev/null +++ b/Term1/Lesson1/Lesson_1_Activity_Three.java @@ -0,0 +1,29 @@ +package Lesson1; +/* + * Lesson 1 Coding Activity Question 3 + * + * Write a program to output the following: + + ******** + * java * + ******** + + * For an extra challenge: complete this problem using only one line of code. +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_1_Activity_Three { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.println("********"); + System.out.println("* java *"); + System.out.print("********"); + + } +} diff --git a/Term1/Lesson1/Lesson_1_Activity_Two.java b/Term1/Lesson1/Lesson_1_Activity_Two.java new file mode 100644 index 0000000..3680782 --- /dev/null +++ b/Term1/Lesson1/Lesson_1_Activity_Two.java @@ -0,0 +1,23 @@ +package Lesson1; +/* + * Lesson 1 Coding Activity Question 2 + * + * Write a program to print your name to the center of the output screen on three different lines. + * + * For an extra challenge: complete this problem using only one line of code. +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_1_Activity_Two { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.println(" Gary"); System.out.println(" Gary"); System.out.println(" Gary"); + + } +} \ No newline at end of file diff --git a/Term1/Lesson1/T1_L1_Template.java b/Term1/Lesson1/T1_L1_Template.java new file mode 100644 index 0000000..8671e49 --- /dev/null +++ b/Term1/Lesson1/T1_L1_Template.java @@ -0,0 +1,23 @@ +package Lesson1; +/* + * Lesson 1 - Unit 1 - Output in Java + * This program uses a Scanner to ask you (the user) for their name and favorite number. + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t01_lesson1_template{ + + + public static void main (String str[]) throws IOException { + + System.out.println ("Welcome to AP Computer Science"); + + } + +} + + diff --git a/Term1/Lesson10/Lesson_10_Activity.java b/Term1/Lesson10/Lesson_10_Activity.java new file mode 100644 index 0000000..cdeb152 --- /dev/null +++ b/Term1/Lesson10/Lesson_10_Activity.java @@ -0,0 +1,46 @@ +package Lesson10; + +/* + * Lesson 10 Coding Activity Question 1 + * + * The following calculation will give roundoff error: + * double x = 1.473; + * System.out.println(2 - x); + * + * Write the code to correct it. You can assume no more than 3 decimal places will be used. + * + * Sample run: + * + * Please enter two decimal values: + * 2 + * 1.473 + * + * The difference is: 0.527 + * + * Use this starter file as your template. + * +*/ + +import java.util.Scanner; +import java.lang.Math; + + +class Lesson_10_Activity { + public static void main(String[] args) { + + Scanner scan = new Scanner (System.in); + + double input1 = scan.nextDouble(); + double input2 = scan.nextDouble(); + + int inputToInt1 = (int) (input1 * 1000000); + int inputToInt2 = (int) (input2 * 1000000); + + int answerInt = inputToInt1 - inputToInt2; + + double finalAnswer = (double)answerInt/1000000; + + System.out.println("The difference is: " + finalAnswer); + + } +} \ No newline at end of file diff --git a/Term1/Lesson10/T1_L10_Template.java b/Term1/Lesson10/T1_L10_Template.java new file mode 100644 index 0000000..ef2541b --- /dev/null +++ b/Term1/Lesson10/T1_L10_Template.java @@ -0,0 +1,40 @@ +package Lesson10; +/* + * Lesson 10 - Unit 1 - Roundoff error. + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +import java.lang.Math; + +class t1_lesson10_template{ + + public static void main (String str[]) throws IOException { + + double x = 4.35; + + System.out.println(x + " " + x * 100 ); + + + int temp = (int)(Math.round(x*100)); + System.out.println((double)(temp-500)/100); //since it's multipled by 100, -500 is the same as -5 + + } + +} + + +/* +The answer for x * 100 is not correct because of round off error +to prevent this, first change x into a integer + +round off errors occur because some doubles can't be stored as binary. 3.35 is rounded off and stored as 3.34 + +double x = 4.35; +int temp = (int)(x*100); +System.out.println((double)(x*100)/2); + +*/ \ No newline at end of file diff --git a/Term1/Lesson11/Lesson_11_Activity_Four.java b/Term1/Lesson11/Lesson_11_Activity_Four.java new file mode 100644 index 0000000..9e1fdc2 --- /dev/null +++ b/Term1/Lesson11/Lesson_11_Activity_Four.java @@ -0,0 +1,35 @@ +package Lesson11; +/* +* Lesson 11 Coding Activity 4 +* Test if an integer input from the keyboard is odd or even. +* +* Sample Run 1: +* Enter a Number: +* 78 +* Even +* +* Sample Run 2: +* Enter a Number: +* 17 +* Odd +* +*/ + +import java.util.Scanner; +import java.lang.Math; + + +class Lesson_11_Activity_Four { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + int x = scan.nextInt(); + + if((x%2)==0) { + System.out.println("Even"); + } + else { + System.out.println("Odd"); + } + + } +} \ No newline at end of file diff --git a/Term1/Lesson11/Lesson_11_Activity_One.java b/Term1/Lesson11/Lesson_11_Activity_One.java new file mode 100644 index 0000000..006a69d --- /dev/null +++ b/Term1/Lesson11/Lesson_11_Activity_One.java @@ -0,0 +1,25 @@ +package Lesson11; +/* +* Lesson 11 Coding Activity 1 +* Test if an integer input from the keyboard is equal to the integer 176. +* If it is, print "YES" (without the quotes). +*/ + +import java.util.Scanner; +import java.lang.Math; + + +class Lesson_11_Activity_One { + + public static void main(String[] args) { + + Scanner scan = new Scanner (System.in); + int x = scan.nextInt(); + + if(x == 176) { + System.out.println("YES"); + } + + + } +} \ No newline at end of file diff --git a/Term1/Lesson11/Lesson_11_Activity_Three.java b/Term1/Lesson11/Lesson_11_Activity_Three.java new file mode 100644 index 0000000..3e13b5c --- /dev/null +++ b/Term1/Lesson11/Lesson_11_Activity_Three.java @@ -0,0 +1,21 @@ +package Lesson11; +/* +* Lesson 11 Coding Activity 3 +* Get two integers from the keyboard and test if they are equal. +* If they are, print "YES" (without the quotes). +*/ + +import java.util.Scanner; +import java.lang.Math; + + +class Lesson_11_Activity_Three { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + int one = scan.nextInt(); + int two = scan.nextInt(); + if(one == two) { + System.out.println("YES"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson11/Lesson_11_Activity_Two.java b/Term1/Lesson11/Lesson_11_Activity_Two.java new file mode 100644 index 0000000..42ffaa8 --- /dev/null +++ b/Term1/Lesson11/Lesson_11_Activity_Two.java @@ -0,0 +1,24 @@ +package Lesson11; +/* +* Lesson 11 Coding Activity 2 +* Test if a decimal value input from the keyboard is equal to 48.729. +* If it is, print "YES" (without the quotes). +*/ + +import java.util.Scanner; +import java.lang.Math; + + +class Lesson_11_Activity_Two { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + + double x = scan.nextDouble(); + + if(x == 48.729) { + System.out.println("YES"); + } + + + } +} \ No newline at end of file diff --git a/Term1/Lesson11/T1_L11_Template.java b/Term1/Lesson11/T1_L11_Template.java new file mode 100644 index 0000000..86933a6 --- /dev/null +++ b/Term1/Lesson11/T1_L11_Template.java @@ -0,0 +1,28 @@ +package Lesson11; +/* + * Lesson 11 - Unit 2 - Simple Ifs + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson11_template{ + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner(System.in); + + int numberWheels = 0; + + System.out.println("How many wheels does the vehicle have?"); + + numberWheels = scan.nextInt(); + + if(numberWheels==2) + System.out.println("It is a scooter"); + + } + +} \ No newline at end of file diff --git a/Term1/Lesson12/Lesson_12_Activity_Four.java b/Term1/Lesson12/Lesson_12_Activity_Four.java new file mode 100644 index 0000000..0fe3ff9 --- /dev/null +++ b/Term1/Lesson12/Lesson_12_Activity_Four.java @@ -0,0 +1,38 @@ +package Lesson12; +/* +* Lesson 12 Coding Activity 4 +* You are running an experiment that involves hatching chicken eggs. +* Bird eggs are very sensitive to temperature and chickensÕ eggs will hatch +* between 99 and 102 degrees Fahrenheit. +* +* Write the code for the sensor that will be tracking the temperature. +* If the temperature falls below 99 or above 102 your code should print ÒWARNINGÓ. +* The input should be in doubles. +* +* Sample Run 1 +* What is the temperature? +* 45.3 +* WARNING +* +* +* Sample Run 2 +* What is the temperature? +* 100 +* +*/ + + +import java.util.Scanner; + +class Lesson_12_Activity_Four { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + System.out.println("What is the temperature?"); + Double temp = scan.nextDouble(); + + if(temp<99 || temp>102) { + System.out.println("WARNING"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson12/Lesson_12_Activity_One.java b/Term1/Lesson12/Lesson_12_Activity_One.java new file mode 100644 index 0000000..4218d11 --- /dev/null +++ b/Term1/Lesson12/Lesson_12_Activity_One.java @@ -0,0 +1,26 @@ +package Lesson12; +/* +* Lesson 12 Coding Activity 1 +* Write a program to input three integers. +* Test if the average is greater than or equal to 89.5. +* If so, print out the phrase "ABOVE AVERAGE" (without the quotes). +*/ + + +import java.util.Scanner; + +class Lesson_12_Activity_One { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int one, two, three; + one = scan.nextInt(); + two = scan.nextInt(); + three = scan.nextInt(); + double average = (((double)one+two+three)/3); + + if(average >= 89.5) { + System.out.println("ABOVE AVERAGE"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson12/Lesson_12_Activity_Three.java b/Term1/Lesson12/Lesson_12_Activity_Three.java new file mode 100644 index 0000000..2753fa1 --- /dev/null +++ b/Term1/Lesson12/Lesson_12_Activity_Three.java @@ -0,0 +1,50 @@ +package Lesson12; +/* +* Lesson 12 Coding Activity 3 +* Test if a number input from the keyboard is a valid +* test score (between 0 and 100 inclusive). +* +* Sample Run 1 +* Enter a test score: +* 78.5 +* Valid +* +* +* Sample Run 2 +* Enter a test score: +* 179 +* Not Valid +* +*/ + + +import java.util.Scanner; + +class Lesson_12_Activity_Three { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + + System.out.println("Enter a test score:"); + double score = scan.nextDouble(); + + /*if((score>100) || (score<0)) { + System.out.println("Not Valid"); + } + else if((score>=0) && (score<=100)) { + System.out.println("Vaild"); + } + */ + + if(score<0) { + System.out.println("Not Valid"); + } + else if(score>100) { + System.out.println("Not Valid"); + } + else { + System.out.println("Valid"); + + } + } +} \ No newline at end of file diff --git a/Term1/Lesson12/Lesson_12_Activity_Two.java b/Term1/Lesson12/Lesson_12_Activity_Two.java new file mode 100644 index 0000000..b0086cd --- /dev/null +++ b/Term1/Lesson12/Lesson_12_Activity_Two.java @@ -0,0 +1,44 @@ +package Lesson12; +/* +* Lesson 12 Coding Activity 2 +* Input two decimal numbers and print the largest. +* If the numbers are equal, print one of them. +* +* Sample Run 1 +* Please enter two numbers: +* 45.7 +* 45.1 +* +* Largest is: 45.7 +* +* Sample Run 2 +* Please enter two numbers: +* 14 +* 14 +* +* Largest is: 14.0 +* +*/ + + +import java.util.Scanner; + +class Lesson_12_Activity_Two { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + double one, two; + + System.out.println("Please enter two numbers:"); + one = scan.nextDouble(); + two = scan.nextDouble(); + + if(one>two) { + System.out.println("Largest is: " + one); + } + else { + System.out.println("Largest is: " + two); + + } + } +} \ No newline at end of file diff --git a/Term1/Lesson12/T1_L12_Template.java b/Term1/Lesson12/T1_L12_Template.java new file mode 100644 index 0000000..f76aa26 --- /dev/null +++ b/Term1/Lesson12/T1_L12_Template.java @@ -0,0 +1,27 @@ +package Lesson12; +/* +* Lesson 12 - Unit 2 - If's Making Decisions +*/ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson12_template{ + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner(System.in); + + System.out.println("Please enter a temperature: "); + + double temp = scan.nextDouble(); + + if(temp > 98.6) + { + System.out.println("you have a fever"); + } + } + +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_Five.java b/Term1/Lesson13/Lesson_13_Activity_Five.java new file mode 100644 index 0000000..0d2d315 --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_Five.java @@ -0,0 +1,31 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 5 + * Create a program to let the user practice their multiplication tables. + * Print two random integers between 1 and 12 each on a new line. + * Then, ask the user to input the multiplication of the two numbers. + * If they enter the correct product print "Correct!" otherwise print "Wrong". + */ + + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_13_Activity_Five { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int one = (int)(Math.random()*12)+1; + int two = (int)(Math.random()*12)+1; + + System.out.println("What is " + one + " times " + two + " ?"); + int answer= scan.nextInt(); + + if(answer == (one*two)) { + System.out.println("Correct!"); + } + else { + System.out.println("Wrong"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_Four.java b/Term1/Lesson13/Lesson_13_Activity_Four.java new file mode 100644 index 0000000..f142182 --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_Four.java @@ -0,0 +1,34 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 4 + * Input an integer grade from the keyboard and translate it to a letter grade. + * For example, if a user enters 4, print "A", and if they enter 0 print "F." + * You can assume that an integer between 0 and 4 will be input. + */ + + +import java.util.Scanner; + +class Lesson_13_Activity_Four { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int grade = scan.nextInt(); + + if(grade==4) { + System.out.println("A"); + } + else if(grade==3) { + System.out.println("B"); + } + else if(grade==2) { + System.out.println("C"); + } + else if(grade==1) { + System.out.println("D"); + } + else if(grade==0) { + System.out.println("F"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_One.java b/Term1/Lesson13/Lesson_13_Activity_One.java new file mode 100644 index 0000000..797c00b --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_One.java @@ -0,0 +1,25 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 1 + * Take input of an integer number from the keyboard + * and print "Positive" if it's positive or zero, and print "Negative" otherwise. + */ + + +import java.util.Scanner; + + +class Lesson_13_Activity_One { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int num = scan.nextInt(); + + if(num>=0) { + System.out.println("Positive"); + } + else { + System.out.println("Negative"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_Six.java b/Term1/Lesson13/Lesson_13_Activity_Six.java new file mode 100644 index 0000000..027d7a3 --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_Six.java @@ -0,0 +1,45 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 6 + * We are going to redo the last coding activity from Lesson 12, + * but this time it will also print out a message if the temperature is OK. + * + * You are running an experiment that involves hatching chicken eggs. + * Bird eggs are very sensitive to temperature and chickens' eggs will hatch between 99 and 102 degrees Fahrenheit. + * + * Write the code for the sensor that will be tracking the temperature. + * If the temperature falls below 99 or above 102 your code should print ÒWARNINGÓ otherwise ÒTemperature is OKÓ. + * The values 99 and 102 are considered to be included in the ok range and the input will be in doubles. + * + * + * Sample Run 1 + * What is the temperature? + * 45.3 + * WARNING + * + * + * Sample Run 2 + * What is the temperature? + * 100 + * Temperature is OK + * + */ + + +import java.util.Scanner; + +class Lesson_13_Activity_Six { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + System.out.println("What is the temperature?"); + Double temp = scan.nextDouble(); + + if(temp<99 || temp>102) { + System.out.println("WARNING"); + } + else { + System.out.println("Temperature is OK"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_Three.java b/Term1/Lesson13/Lesson_13_Activity_Three.java new file mode 100644 index 0000000..c1f7551 --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_Three.java @@ -0,0 +1,28 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 3 + * Input two integers and print the largest. If they are equal print "EQUAL". + * You should be able to do this with only one if statement but you may use multiple else statements. + */ + + +import java.util.Scanner; + +class Lesson_13_Activity_Three { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int one = scan.nextInt(); + int two = scan.nextInt(); + + if(one>two) { + System.out.println(one); + } + else if(two>one) { + System.out.println(two); + } + else { + System.out.println("EQUAL"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/Lesson_13_Activity_Two.java b/Term1/Lesson13/Lesson_13_Activity_Two.java new file mode 100644 index 0000000..75bdde4 --- /dev/null +++ b/Term1/Lesson13/Lesson_13_Activity_Two.java @@ -0,0 +1,24 @@ +package Lesson13; +/* + * Lesson 13 Coding Activity 2 + * Take input of an integer number from the keyboard and print "passing" + * if it's greater than or equal to 60, and print "failing" otherwise. + */ + + +import java.util.Scanner; + +class Lesson_13_Activity_Two { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int num = scan.nextInt(); + + if(num>=60) { + System.out.println("passing"); + } + else { + System.out.println("failing"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson13/T1_L13_Template.java b/Term1/Lesson13/T1_L13_Template.java new file mode 100644 index 0000000..8a907d7 --- /dev/null +++ b/Term1/Lesson13/T1_L13_Template.java @@ -0,0 +1,29 @@ +package Lesson13; +/* + * Lesson 13 - Unit 2 - Else + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson13_template{ + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner(System.in); + System.out.println("Enter your age:"); + int age = scan.nextInt(); + + if(age >= 18) + { + System.out.println("You can vote!"); + } + else { + System.out.println("You can't vote!"); + } + + } + +} \ No newline at end of file diff --git a/Term1/Lesson14/Lesson_14_Activity_One.java b/Term1/Lesson14/Lesson_14_Activity_One.java new file mode 100644 index 0000000..fb53ab8 --- /dev/null +++ b/Term1/Lesson14/Lesson_14_Activity_One.java @@ -0,0 +1,36 @@ +package Lesson14; +/* + * Lesson 14 Coding Activity 1 + * Test if an integer is not between 5 and 76 inclusive. + * + * Sample Run 1 + * Enter a number: + * 7 + * False + * + * + * Sample Run 2 + * Enter a number: + * 1 + * True + * + */ + + +import java.util.Scanner; + +class Lesson_14_Activity_One { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + System.out.println("Enter a number:"); + int num = scan.nextInt(); + + if(!(num<5 || num>76)) { + System.out.println("False"); + } + else { + System.out.println("True"); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson14/Lesson_14_Activity_Three.java b/Term1/Lesson14/Lesson_14_Activity_Three.java new file mode 100644 index 0000000..ed4271e --- /dev/null +++ b/Term1/Lesson14/Lesson_14_Activity_Three.java @@ -0,0 +1,72 @@ +package Lesson14; +/* + * Lesson 14 Coding Activity 3 + * The Internet runs on web addresses.The addresses we type represent the IP address + * for each site and how the computer finds an individual web page. + * + * IP addresses are made up of four numbers, each between 0 and 255 separated by a period. + * For example, 128.253.21.58 is an IP address. + * + * Write a program to enter four numbers and test if they make up a valid IP address. + * In other words, test to see if the numbers entered are between 0 and 255 inclusive. + * + * Sample Run 1 + * Please enter the first octet: + * 898 + * Please enter the second octet: + * 34 + * Please enter the third octet: + * 712 + * Please enter the fourth octet: + * 45 + * Octet 1 is incorrect + * Octet 3 is incorrect + * + * + * Sample Run 2 + * Please enter the first octet: + * 112 + * Please enter the second octet: + * 200 + * Please enter the third octet: + * 0 + * Please enter the fourth octet: + * 254 + * IP Address: 112.200.0.254 + * + */ + + +import java.util.Scanner; + +class Lesson_14_Activity_Three { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + System.out.println("Please enter the first octet:"); + int one = scan.nextInt(); + System.out.println("Please enter the secound octet:"); + int two = scan.nextInt(); + System.out.println("Please enter the third octet:"); + int three = scan.nextInt(); + System.out.println("Please enter the fourth octet:"); + int four = scan.nextInt(); + + if((one>=0 && one<=255)&&(two>=0 && two<=255)&&(three>=0 && three<=255)&&(four>=0 && four<=255)) { + System.out.println("IP Address: "+one+"."+two+"."+three+"."+four); + } + if(!(one>=0 && one<=255)) { + System.out.println("Octet 1 is incorrect"); + } + if(!(two>=0 && two<=255)) { + System.out.println("Octet 2 is incorrect"); + } + if(!(three>=0 && three<=255)) { + System.out.println("Octet 3 is incorrect"); + } + if(!(four>=0 && four<=255)) { + System.out.println("Octet 4 is incorrect"); + } + + } +} \ No newline at end of file diff --git a/Term1/Lesson14/Lesson_14_Activity_Two.java b/Term1/Lesson14/Lesson_14_Activity_Two.java new file mode 100644 index 0000000..97d1e0e --- /dev/null +++ b/Term1/Lesson14/Lesson_14_Activity_Two.java @@ -0,0 +1,26 @@ +package Lesson14; +/* + * Lesson 14 Coding Activity 2 + * Write a program to input two integers and print + * "Both are positive or zero." to the screen, if both are positive or zero. + * Print "One or both are negative." otherwise. + */ + + +import java.util.Scanner; + +class Lesson_14_Activity_Two { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int one = scan.nextInt(); + int two = scan.nextInt(); + + if(two>=0 && one>=0) { + System.out.println("Both are positive or zero."); + } + else { + System.out.println("One or both are negative."); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson14/T1_L14_Template.java b/Term1/Lesson14/T1_L14_Template.java new file mode 100644 index 0000000..05d0ec9 --- /dev/null +++ b/Term1/Lesson14/T1_L14_Template.java @@ -0,0 +1,29 @@ +package Lesson14; + +/* + * Lesson 14 - Unit 2 - Boolean Conditions + * + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson14_template{ + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + int num = scan.nextInt(); + + if(!(num >=45 && num <= 78)) + { + System.out.println("Not inbetween 45 and 78"); + } + + } + +} + + diff --git a/Term1/Lesson15/T1_L15_Template.java b/Term1/Lesson15/T1_L15_Template.java new file mode 100644 index 0000000..20ca54d --- /dev/null +++ b/Term1/Lesson15/T1_L15_Template.java @@ -0,0 +1,27 @@ +package Lesson15; +/* + * Lesson 15 - Unit 2 - Short Circuit Evaluation. + */ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson15_template{ + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + + int y = scan.nextInt(); + + if ( y < 0 || y > 100) + { + System.out.println( "Not a valid grade."); + } + + } + +} + + diff --git a/Term1/Lesson16/T1_L16_DeMorgan's_Law.pdf b/Term1/Lesson16/T1_L16_DeMorgan's_Law.pdf new file mode 100644 index 0000000..38fa301 Binary files /dev/null and b/Term1/Lesson16/T1_L16_DeMorgan's_Law.pdf differ diff --git a/Term1/Lesson17/Lesson_17_Activity_One.java b/Term1/Lesson17/Lesson_17_Activity_One.java new file mode 100644 index 0000000..642c449 --- /dev/null +++ b/Term1/Lesson17/Lesson_17_Activity_One.java @@ -0,0 +1,45 @@ +package Lesson17; +/* + * Lesson 17 Coding Activity 1 + * Write a program that will input a list of test scores in from the keyboard. + * When the user enters -1, print the average. + * + * What do you need to be careful about when using -1 to stop a loop? + * + * Sample Run: + * Enter the Scores: + * 45 + * 100 + * -1 + * + * The average is: 72.5 + * + * + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_17_Activity_One { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + int score = 0, sum = 0, count = 0; + double average = 0; + + while (score != -1) { + if(score>=0 && score<=100) { + sum+=score; + score = scan.nextInt(); + count++; + } + } + count--; + average = (double)sum/count; + System.out.println("The average is " + average); + + + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson17/Lesson_17_Activity_Two.java b/Term1/Lesson17/Lesson_17_Activity_Two.java new file mode 100644 index 0000000..928fcd4 --- /dev/null +++ b/Term1/Lesson17/Lesson_17_Activity_Two.java @@ -0,0 +1,49 @@ +package Lesson17; +/* + * Lesson 17 Coding Activity 2 + * Ask the user for two numbers. Print only the even numbers between them, + * you should also print the two numbers if they are even. + * + * Sample Run 1: + * + * Enter two numbers: + * 3 + * 11 + * + * 4 6 8 10 + * + * Sample Run 2: + * + * Enter two numbers: + * 10 + * 44 + * + * 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 + * + * + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_17_Activity_Two { + public static void main(String[] args) + { + Scanner scan = new Scanner (System.in); + int one = scan.nextInt(); + int two = scan.nextInt(); + + int count = one; + + String result = ""; + + while (count<=two) { + if (count%2==0) { + result += count + " "; + } + count++; + } + + System.out.println(result); + } +} \ No newline at end of file diff --git a/Term1/Lesson17/T1_L17_Template.java b/Term1/Lesson17/T1_L17_Template.java new file mode 100644 index 0000000..eeb23db --- /dev/null +++ b/Term1/Lesson17/T1_L17_Template.java @@ -0,0 +1,31 @@ +package Lesson17; +/* + * Lesson 17 - Unit 2 - While Loops + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +class t1_lesson17_template{ + + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + + int x = 0; + + while ( x < 5 ) + { + System.out.println( "Java"); + x++; + } + + } + +} + + diff --git a/Term1/Lesson18/T1_L18_Tracing.pdf b/Term1/Lesson18/T1_L18_Tracing.pdf new file mode 100644 index 0000000..c4c165d Binary files /dev/null and b/Term1/Lesson18/T1_L18_Tracing.pdf differ diff --git a/Term1/Lesson19/T1_L19_Template.java b/Term1/Lesson19/T1_L19_Template.java new file mode 100644 index 0000000..1ac2a24 --- /dev/null +++ b/Term1/Lesson19/T1_L19_Template.java @@ -0,0 +1,38 @@ +package Lesson19; +/* + * Lesson 19 - Unit 2 - More Loops + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +class t1_lesson19_template{ + + + public static void main (String str[]) throws IOException { + + int a = 45; + int b = 30; + + while ( b !=0 ) + { + int r = a % b; + a = b; + b = r; + + } + + System.out.println(a); //this finds the GCF, Greatest Common Factor + + + //IMPORTANT, MOD INSIDE LOOPS ARE ON THE AP TEST + + + } + +} + + diff --git a/Term1/Lesson2/Lesson_2_Activity_One.java b/Term1/Lesson2/Lesson_2_Activity_One.java new file mode 100644 index 0000000..a44c633 --- /dev/null +++ b/Term1/Lesson2/Lesson_2_Activity_One.java @@ -0,0 +1,26 @@ +package Lesson2; +/* + * Lesson 2 Coding Activity Question 1 + * + * Print the following shape: + + /\ + \/ + + * (Note you will have to use escape characters to make this work.) +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_2_Activity_One { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.println("/\\\n\\/"); + + } +} \ No newline at end of file diff --git a/Term1/Lesson2/Lesson_2_Activity_Three.java b/Term1/Lesson2/Lesson_2_Activity_Three.java new file mode 100644 index 0000000..4be24bd --- /dev/null +++ b/Term1/Lesson2/Lesson_2_Activity_Three.java @@ -0,0 +1,31 @@ +package Lesson2; +/* + * Lesson 2 Coding Activity Question 3 + * + * Write the code to output: + + _ + / \ +| | + \ _ / + + * It may be easier to get the correct output + * if you copy/paste each line from the sample run above. +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_2_Activity_Three { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.println(" _"); + System.out.println(" / \\"); + System.out.println("| |"); + System.out.println(" \\ _ /"); + } +} \ No newline at end of file diff --git a/Term1/Lesson2/Lesson_2_Activity_Two.java b/Term1/Lesson2/Lesson_2_Activity_Two.java new file mode 100644 index 0000000..1785dd8 --- /dev/null +++ b/Term1/Lesson2/Lesson_2_Activity_Two.java @@ -0,0 +1,27 @@ +package Lesson2; +/* + * Lesson 2 Coding Activity Question 2 + * + * Using only one "System.out.print" command, + * print the following quote. Make sure to include + * the quote marks (") in your output. + + "I do not fear computers. I fear the lack of them." + Isaac Asimov + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_2_Activity_Two { + public static void main(String[] args) { + + /* Write your code here + * Copy and paste your entire code to Code Runner to complete the activity, + * from the first import statement to the last bracket. + */ + System.out.print("\"I do not fear computers. I fear the lack of them.\"\nIsaac Asimov"); + + } +} \ No newline at end of file diff --git a/Term1/Lesson2/T1_L2_Template.java b/Term1/Lesson2/T1_L2_Template.java new file mode 100644 index 0000000..7db0abc --- /dev/null +++ b/Term1/Lesson2/T1_L2_Template.java @@ -0,0 +1,22 @@ +package Lesson2; +/* + * Lesson 2 - Unit 1 - Escape Characters + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson02_template{ + + + public static void main (String str[]) throws IOException { + + System.out.println (" /\\ \n / \\ \n / \\ \n | | \n | || | \n | || |"); + + } + +} + + diff --git a/Term1/Lesson20/Lesson_20_Activity.java b/Term1/Lesson20/Lesson_20_Activity.java new file mode 100644 index 0000000..4072337 --- /dev/null +++ b/Term1/Lesson20/Lesson_20_Activity.java @@ -0,0 +1,175 @@ +package Lesson20; +/* + * Lesson 20 Coding Activity + * + * Computer science jobs are in demand. Right now we have a shortage + * of people that can do computer programming, and one of the fastest + * growing areas of new jobs in the sector are so-called hybrid jobs. + * This means you specialize in an area like biology, + * and then use computer programming to do your job. + * + * These hybrid jobs exist in the arts, sciences, + * economics, healthcare, and entertainment fields. + * + * One of these jobs is computational biology. Computational Biology, + * sometimes referred to as bioinformatics, is the science of + * using biological data to develop algorithms and relations + * among various biological systems. + * + * In this lab we are going to investigate the data from a + * grey seal named Gracie. WeÕll input the longitude and + * latitude data from a tracking device. We want to investigate + * the farthest north, south, east and west Gracie has been. + * + * We will use the latitude to measure this. + * Write a program to enter GracieÕs longitude and Latitude data. + * Each time through the loop it should ask if you want to continue. + * Enter 1 to repeat, 0 to stop. + * + * Any value for latitude not between -90 and 90 inclusive should be ignored. + * + * Any value for longitude not between -180 and 180 inclusive should be ignored. + * + * + * Sample Run: + * + * Please enter the latitude: + * 41.678 + * Please enter the longitude: + * 69.938 + * Would you like to enter another location? + * 1 + * Please enter the latitude: + * 41.755 + * Please enter the longitude: + * 69.862 + * Would you like to enter another location? + * 1 + * Please enter the latitude: + * 41.829 + * Please enter the longitude: + * 69.947 + * Would you like to enter another location? + * 1 + * Please enter the latitude: + * 300 + * Please enter the longitude: + * 69.947 + * Incorrect Latitude or Longitude + * Please enter the latitude: + * 41.827 + * Please enter the longitude: + * 69.904 + * Would you like to enter another location? + * 0 + * Farthest North: 41.829 + * Farthest South: 41.678 + * Farthest East: 69.947 + * Farthest West: 69.862 + * + */ + + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_20_Activity{ + public static void main(String[] args) { + + Scanner scan = new Scanner (System.in); + + double longitude, latitude; + double maxNorth=0,maxSouth=0,maxEast=0,maxWest=0; + double cont = 1; + + int incorrect = 0; //1=incorrect + + + + + System.out.println("Please enter the latitude:"); + latitude = scan.nextDouble(); + System.out.println("Please enter the longitude:"); + longitude = scan.nextDouble(); + + //intital Longitude + if (longitude >=-180 && longitude <=180) { + maxEast = longitude; + maxWest = longitude; + } + else { + incorrect = 1; + } + + //intial Latitude + if (latitude >=-90 && latitude <=90) { + maxNorth = latitude; + maxSouth = latitude; + } + else { + incorrect = 1; + } + + //Checks for incorrect longitude or latiude + if (incorrect == 1) { + System.out.println("Incorrect Latitude or Longitude"); + incorrect = 0; + } + else { + System.out.println("Would you like to enter another location?"); + cont = scan.nextDouble(); + } + + + while (cont == 1) { + + System.out.println("Please enter the latitude:"); + latitude = scan.nextDouble(); + System.out.println("Please enter the longitude:"); + longitude = scan.nextDouble(); + + //Longitude + if (longitude >=-180 && longitude <=180) { + if(longitude > maxEast) { + maxEast = longitude; + } + if(longitude < maxWest) { + maxWest = longitude; + } + } + else { + incorrect = 1; + } + //Latitude + if (latitude >=-90 && latitude <=90) { + if(latitude > maxNorth) { + maxNorth = latitude; + } + if(latitude < maxSouth) { + maxSouth = latitude; + } + } + else { + incorrect = 1; + } + //Checks for incorrect longitude or latiude + if (incorrect == 1) { + System.out.println("Incorrect Latitude or Longitude"); + incorrect = 0; + } + else { + System.out.println("Would you like to enter another location?"); + cont = scan.nextDouble(); + } + } + + + System.out.println("Farthest North: " + maxNorth); + System.out.println("Farthest South: "+maxSouth); + System.out.println("Farthest East: "+maxEast); + System.out.println("Farthest West: "+maxWest); + + scan.close(); + + } +} \ No newline at end of file diff --git a/Term1/Lesson20/T1_L20_Template.java b/Term1/Lesson20/T1_L20_Template.java new file mode 100644 index 0000000..a8ff2ec --- /dev/null +++ b/Term1/Lesson20/T1_L20_Template.java @@ -0,0 +1,43 @@ +package Lesson20; +/* + * Lesson 20 - Unit 2 - Technique - flag variables + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson20_template{ + + public static void main (String str[]) throws IOException { + Scanner scan = new Scanner(System.in); + + System.out.println ("What number are we looking for?"); + int target = scan.nextInt(); + + int x = 0; + int flag = 0; + + while ( x != -1) + { + System.out.println ("Enter -1 to stop"); + x = scan.nextInt(); + + if (x == target) + flag = 1; + } + + if (flag == 1) + System.out.println (target + " was found"); + else + System.out.println (target + " was NOT found"); + + } + +} + +//Integer.MIN_VALUE will give you the smallest int possible + diff --git a/Term1/Lesson21/T1_L21_Strings_and_Classes.pdf b/Term1/Lesson21/T1_L21_Strings_and_Classes.pdf new file mode 100644 index 0000000..06f8e0a Binary files /dev/null and b/Term1/Lesson21/T1_L21_Strings_and_Classes.pdf differ diff --git a/Term1/Lesson21/T1_L21_Strings_and_Classes_NO_ACTIVITY.java b/Term1/Lesson21/T1_L21_Strings_and_Classes_NO_ACTIVITY.java new file mode 100644 index 0000000..aeafd04 --- /dev/null +++ b/Term1/Lesson21/T1_L21_Strings_and_Classes_NO_ACTIVITY.java @@ -0,0 +1,9 @@ +package Lesson21; + +public class T1_L21_Strings_and_Classes_NO_ACTIVITY { + + public static void main(String[] args) { + System.out.println("T1_L21_Strings_and_Classes\nNO ACTIVITY"); + } + +} diff --git a/Term1/Lesson22/Lesson_22_Activity_One.java b/Term1/Lesson22/Lesson_22_Activity_One.java new file mode 100644 index 0000000..2b5f605 --- /dev/null +++ b/Term1/Lesson22/Lesson_22_Activity_One.java @@ -0,0 +1,36 @@ +package Lesson22; +/* + * Lesson 22 Coding Activity 1 + * Write the code to take a String and print it with one letter per line. + + Sample run: + + Enter a string: + bought + b + o + u + g + h + t + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_22_Activity_One { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + String word = scan.nextLine(); + + for (int i = 0; i < word.length(); i++) { + System.out.println(word.substring(i, i+1)); + } + + + + } +} + + diff --git a/Term1/Lesson22/Lesson_22_Activity_Two.java b/Term1/Lesson22/Lesson_22_Activity_Two.java new file mode 100644 index 0000000..801db9d --- /dev/null +++ b/Term1/Lesson22/Lesson_22_Activity_Two.java @@ -0,0 +1,40 @@ +package Lesson22; +/* + * Lesson 22 Coding Activity 2 + * Write the code to take a String and print it diagonally. + + Sample run: + + Enter a string: + bought + b + o + u + g + h + t + Use a tab character for every four spaces in the sample. + + Hint: You may need more than one loop. + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_22_Activity_Two { + public static void main(String[] args) { + Scanner scan = new Scanner (System.in); + String word = scan.nextLine(); + + for (int i = 0; i < word.length(); i++) { + for (int k = 0; k < i; k++) { + System.out.print("\t"); + } + System.out.println(word.substring(i, i+1)); + } + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson22/T1_L22_String_Functions.pdf b/Term1/Lesson22/T1_L22_String_Functions.pdf new file mode 100644 index 0000000..4a5bb9b Binary files /dev/null and b/Term1/Lesson22/T1_L22_String_Functions.pdf differ diff --git a/Term1/Lesson23/T1_L23_1D_Arrays.pdf b/Term1/Lesson23/T1_L23_1D_Arrays.pdf new file mode 100644 index 0000000..6c5bb67 Binary files /dev/null and b/Term1/Lesson23/T1_L23_1D_Arrays.pdf differ diff --git a/Term1/Lesson24/Lesson_24_Activity_One.java b/Term1/Lesson24/Lesson_24_Activity_One.java new file mode 100644 index 0000000..4e23ceb --- /dev/null +++ b/Term1/Lesson24/Lesson_24_Activity_One.java @@ -0,0 +1,30 @@ +package Lesson24; + + +/* + * Lesson 24 Coding Activity 1 + * Use a for loop to print all of the numbers from 23 to 89, with 10 numbers on each line. + * Print one space between each number. + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_24_Activity_One { + + public static void main(String[] args) { + int i = 0; + for(int a = 23; a <= 89; a++) { + if(i == 10) { + System.out.println(); + i = 0; + } + System.out.print(a + " "); + i++; + } + + + + } + +} \ No newline at end of file diff --git a/Term1/Lesson24/Lesson_24_Activity_Three.java b/Term1/Lesson24/Lesson_24_Activity_Three.java new file mode 100644 index 0000000..8a4d125 --- /dev/null +++ b/Term1/Lesson24/Lesson_24_Activity_Three.java @@ -0,0 +1,58 @@ +package Lesson24; + +/* + * Lesson 24 Coding Activity 3 + * Input an int between 0 and 100 and print the numbers between it and 100. + * If the number is not between 0 and 100 print "error". + * Print 20 numbers per line. + * + * Sample Run 1: + * + * Enter a number between 0 and 100: + * 30 + * 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 + * 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + * 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 + * 90 91 92 93 94 95 96 97 98 99 100 + * + * + * Sample Run 2: + * + * Enter a number between 0 and 100: + * 105 + * error + * + * + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_24_Activity_Three { + public static void main(String[] args){ + Scanner scan = new Scanner (System.in); + int startNum = scan.nextInt(); + + System.out.println("Enter a number between 0 and 100:"); + + if(startNum>0 && startNum<100) { + int k = 0; + for (int i = startNum; i <100; i++) { + + if(k==20) { + System.out.println(); + k = 0; + } + else + k++; + + System.out.print(i + " "); + } + } + else { + System.out.println("error"); + } + + + } +} \ No newline at end of file diff --git a/Term1/Lesson24/Lesson_24_Activity_Two.java b/Term1/Lesson24/Lesson_24_Activity_Two.java new file mode 100644 index 0000000..41f9cbb --- /dev/null +++ b/Term1/Lesson24/Lesson_24_Activity_Two.java @@ -0,0 +1,19 @@ +package Lesson24; +/* + * Lesson 24 Coding Activity 2 + * Use a for loop to print the even numbers between 1 and 50. + * Print each number on a new line. + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_24_Activity_Two { + public static void main(String[] args){ + for (int i = 1; i <= 50; i++) { + i++; + System.out.println(i); + + } + } +} \ No newline at end of file diff --git a/Term1/Lesson24/T1_L24_Template.java b/Term1/Lesson24/T1_L24_Template.java new file mode 100644 index 0000000..21d38b1 --- /dev/null +++ b/Term1/Lesson24/T1_L24_Template.java @@ -0,0 +1,23 @@ +package Lesson24; +/* + * Lesson 24 - Unit 3 - The For Loop + */ + + + +class t1_lesson24_template{ + + public static void main (String[] args) { + + int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + for (int i = 0; i < array.length; i ++) + { + System.out.print( array[i] + " "); + } + + } + +} + + diff --git a/Term1/Lesson25/T1_L25_Template.java b/Term1/Lesson25/T1_L25_Template.java new file mode 100644 index 0000000..ff680a2 --- /dev/null +++ b/Term1/Lesson25/T1_L25_Template.java @@ -0,0 +1,31 @@ +package Lesson25; + +/* +* Lesson 25 - Unit 3 - Algorithms +*/ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson25_template{ + + public static void main (String str[]) throws IOException { + + + boolean prime[] = new boolean [100]; + + //initialize to true + for (int j = 0; j < prime.length; j++) + { + prime[j] = true; + } + + + } + +} + + diff --git a/Term1/Lesson26/T1_L26_Template.java b/Term1/Lesson26/T1_L26_Template.java new file mode 100644 index 0000000..d9e6ec8 --- /dev/null +++ b/Term1/Lesson26/T1_L26_Template.java @@ -0,0 +1,35 @@ +package Lesson26; + +/* +* Lesson 26 - Unit 3 - Algorithms on Arrays +*/ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson26_template{ + + public static void main (String str[]) throws IOException { + + int tests [] = new int[20]; + + //initialize to true + for (int i = 0; i < tests.length; i++) + { + tests[i] = (int)(Math.random()*55)+45; + } + + for (int i = 0; i < tests.length; i++) + { + System.out.print(tests[i] + " " ); + } + + + } + +} + + diff --git a/Term1/Lesson27/T1_L27_Template.java b/Term1/Lesson27/T1_L27_Template.java new file mode 100644 index 0000000..2fbe00e --- /dev/null +++ b/Term1/Lesson27/T1_L27_Template.java @@ -0,0 +1,41 @@ +package Lesson27; + +/* +* Lesson 27 - Unit 3 - Algorithms - searching +*/ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +public class T1_L27_Template{ + + + public static void main (String[] arg) { + Scanner scan = new Scanner (System.in); + + double list [] = {2.3 , 4.7 , 5.25 , 9.5 , 2.0 , 1.2 , 7.129 , 5.4 , 9.4 }; + + + System.out.println( "What are you looking for? "); + double look = scan.nextDouble(); + boolean found = false; + for (int i = 0; i < list.length; i++) { + if (list[i] == look) { + System.out.println(look + " was found at the " + i + " index"); + found = true; + } + } + if(!found) { + System.out.println("-1"); + } + + + + } + +} + + diff --git a/Term1/Lesson28/T1_L28_Template.java b/Term1/Lesson28/T1_L28_Template.java new file mode 100644 index 0000000..c13ef06 --- /dev/null +++ b/Term1/Lesson28/T1_L28_Template.java @@ -0,0 +1,30 @@ +package Lesson28; + +/* +* Lesson 28 - Unit 3 - Arrays of Strings +*/ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +public class T1_L28_Template{ + + + public static void main (String str[]) throws IOException { + + String movies [] = new String [5]; + + movies[0] = "Creature of the Black Lagoon"; + movies[2] = "Don't Eat the Daisies"; + + for(int i = 0; i list[longest].length()) { + longest = i; + } + } + System.out.println(list[longest]); + + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson29/Lesson_29_Activity_Two.java b/Term1/Lesson29/Lesson_29_Activity_Two.java new file mode 100644 index 0000000..8eab96a --- /dev/null +++ b/Term1/Lesson29/Lesson_29_Activity_Two.java @@ -0,0 +1,55 @@ +package Lesson29; + +/* + * Lesson 29 Coding Activity 2 + * Write a loop that processes an array of strings. + * Each String should be printed backwards on its own line. + * + * For example, if the list contains: + * + * {"every", "nearing", "checking", "food", "stand", "value"} + * + * It should output: + * yreve + * gniraen + * gnikcehc + * doof + * dnats + * eulav + */ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_29_Activity_Two { + + /* Fill this list with values that will be useful for you to test. + * A good idea may be to copy/paste the list in the example above. + * Do not make any changes to this list in your main method. You can + * print values from list, but do not add or remove values to this + * variable. + */ + public static String [] list = {"every", "nearing", "checking", "food", "stand", "value"}; + + public static void main(String[] args) { + + //for loop for each word & next line + //for loop for reverse + + + for(int i = 0; i < list.length; i++) { + + for(int k = list[i].length()-1; k >= 0; k--) { + System.out.print(list[i].substring(k, k+1)); + + + } + + System.out.println(""); + } + + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson29/T1_L29_Template.java b/Term1/Lesson29/T1_L29_Template.java new file mode 100644 index 0000000..d264fc2 --- /dev/null +++ b/Term1/Lesson29/T1_L29_Template.java @@ -0,0 +1,28 @@ +package Lesson29; + + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class T1_L29_Template{ +//Lesson 29: Arrays of Strings accessing Methods + + + public static void main (String str[]) throws IOException { + + String movies [ ] = { "The Thing", "I Was a Teenage Werewolf", "The Blob", "Godzilla", "Plan 9 from Outer Space" }; + + System.out.println( "\n\nThe Movies: "); + for (int i = 0; i < movies.length; i++ ) + { + System.out.println(movies[i] + "\t" + movies[i].length() ); + + } + + } + +} \ No newline at end of file diff --git a/Term1/Lesson3/Lesson_3_Activity_One.java b/Term1/Lesson3/Lesson_3_Activity_One.java new file mode 100644 index 0000000..88f6e66 --- /dev/null +++ b/Term1/Lesson3/Lesson_3_Activity_One.java @@ -0,0 +1,28 @@ +package Lesson3; +/* + * Lesson 3 Coding Activity Question 1 + * + * Write the code to ask the user to enter their name and print the following message: + +Hi ______, nice to see you. + + * Remember, you'll need to use the method println and Scanner class method nextLine. +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_3_Activity_One { + public static void main(String[] args) { + + Scanner nameScan = new Scanner (System.in); + String name; + + System.out.println("What is your name?"); + name = nameScan.nextLine(); + + System.out.println("Hi " + name + ", nice to see you."); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson3/Lesson_3_Activity_Three.java b/Term1/Lesson3/Lesson_3_Activity_Three.java new file mode 100644 index 0000000..0a5a8ea --- /dev/null +++ b/Term1/Lesson3/Lesson_3_Activity_Three.java @@ -0,0 +1,40 @@ +package Lesson3; +/* + * Lesson 3 Coding Activity Question 3 + * + * Write a program that will ask the user to enter an adjective and a name. + * Print the following sentence, replacing the ______ with the words they entered. + * + * My name is _____. I am _____. + * + * Sample Run: + +Hi there. What is your name? +Ada +What adjective describes you? +logical +My name is Ada. I am logical. + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_3_Activity_Three { + public static void main(String[] args) { + + String name; + String adjective; + + Scanner scan = new Scanner (System.in); + + System.out.println("Hi there. What is your name?"); + name = scan.nextLine(); + + System.out.println("What adjective describes you?"); + adjective = scan.nextLine(); + + System.out.println("My name is " + name + ". I am " + adjective + "."); + + } +} \ No newline at end of file diff --git a/Term1/Lesson3/Lesson_3_Activity_Two.java b/Term1/Lesson3/Lesson_3_Activity_Two.java new file mode 100644 index 0000000..6a342a8 --- /dev/null +++ b/Term1/Lesson3/Lesson_3_Activity_Two.java @@ -0,0 +1,36 @@ +package Lesson3; +/* + * Lesson 3 Coding Activity Question 2 + * + * Write a program that asks the user for three names, then prints the names in reverse order. + * + * Sample Run: + +Please enter three names: +Zoey +Zeb +Zena + +Zena Zeb Zoey + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_3_Activity_Two { + public static void main(String[] args) { + + String name1; + String name2; + String name3; + Scanner namescan = new Scanner (System.in); + + System.out.println("Please enter three names:"); + name1 = namescan.nextLine(); + name2 = namescan.nextLine(); + name3 = namescan.nextLine(); + + System.out.println(name3+ " " +name2+ " " +name1); + } +} \ No newline at end of file diff --git a/Term1/Lesson3/T1_L3_Template.java b/Term1/Lesson3/T1_L3_Template.java new file mode 100644 index 0000000..208d010 --- /dev/null +++ b/Term1/Lesson3/T1_L3_Template.java @@ -0,0 +1,30 @@ +package Lesson3; +/* + * Lesson 3 - Unit 1 - User Input and Variables + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson03_template{ + + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + + String n; + + System.out.println("What is your name?"); + n = scan.nextLine(); + System.out.println("Hello " + n + ". Nice to meet you"); + + + + } + +} + + diff --git a/Term1/Lesson30/Lesson_30_Activity.java b/Term1/Lesson30/Lesson_30_Activity.java new file mode 100644 index 0000000..8cdf14b --- /dev/null +++ b/Term1/Lesson30/Lesson_30_Activity.java @@ -0,0 +1,49 @@ +package Lesson30; +/* + * Lesson 30 Coding Activity + * Due to a problem with a scanner an array of words was created + * with spaces in incorrect places. Write the code to process the + * list of words and trim any spaces out of the words. + * + * So if the list contains: + * {"every", " near ing ", " checking", "food ", "stand", "value "} + * + * It should be changed to hold: + * {"every", "nearing", "checking", "food", "stand", "value"} + * + * Note that this activity does not require you to print anything. + * Your code should end with the array list still declared and + * containing the resulting words. + * + */ + + +import java.util.Scanner; + +class Lesson_30_Activity { + + public static String [] list = {}; + + + + public static void main(String[] args) { + + //METHOD ONE + /*String word = ""; + + for(int i = 0; i < list.length; i++) { + word=""; + for(int k = 0; k < list[i].length(); k++) { + if(list[i].charAt(k) != ' ') { + word+=list[i].charAt(k); + } + } + list[i]=word; + }*/ + + //METHOD TWO + for(int i = 0; i < list.length; i++) { + list[i]=list[i].replaceAll(" ", ""); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson30/Lesson_30_Template.java b/Term1/Lesson30/Lesson_30_Template.java new file mode 100644 index 0000000..a400405 --- /dev/null +++ b/Term1/Lesson30/Lesson_30_Template.java @@ -0,0 +1,19 @@ +package Lesson30; + +//THIS IS SUPPOSED TO BE ON PAPER + +/*Prints out the last letter in every element inside an array*/ + +public class Lesson_30_Template { + + public static String [] cities = {}; + + public static void main(String[] args) { + for(int i = 0; i < cities.length; i++) { + System.out.println(cities[i].charAt(cities[i].length()-1)); + } + + + } + +} diff --git a/Term1/Lesson30_1011/T1_Lesson1011_Binary_Octal.pdf b/Term1/Lesson30_1011/T1_Lesson1011_Binary_Octal.pdf new file mode 100644 index 0000000..5d6265f Binary files /dev/null and b/Term1/Lesson30_1011/T1_Lesson1011_Binary_Octal.pdf differ diff --git a/Term1/Lesson31/T1_L31_Template.java b/Term1/Lesson31/T1_L31_Template.java new file mode 100644 index 0000000..10c94fd --- /dev/null +++ b/Term1/Lesson31/T1_L31_Template.java @@ -0,0 +1,32 @@ +package Lesson31; +/* + * Lesson 31 - Unit 4 - Void Methods + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson31_template{ + + public static void doStuff ( ) { + System.out.println( "This is a method "); + } //doStuff + + public static void main (String str[]) throws IOException { + + System.out.println( "This is in main."); + + doStuff(); + doStuff(); + + System.out.println( " ( main is a method too ) "); + + } + +} + + diff --git a/Term1/Lesson32/Lesson_32_Activity_Four.java b/Term1/Lesson32/Lesson_32_Activity_Four.java new file mode 100644 index 0000000..7c15975 --- /dev/null +++ b/Term1/Lesson32/Lesson_32_Activity_Four.java @@ -0,0 +1,44 @@ +package Lesson32; +/* +* Lesson 32 Coding Activity 4 +* +* For the Lesson 32 activities, you will be asked to write one or more methods. +* Use the template to write a main method that tests each of your methods, +* then paste everything into the code runner box. Your submission should +* begin with the first import statement and end with the final }. +* +* Write a method that accepts a number of seconds and prints the +* correct number of hours, minutes and seconds. +* +* This method must be called realTime() and its parameter must be an integer. +* +* Calling realTime(6342) would print the following: +* +* Hours: 1 +* Minutes: 45 +* Seconds: 42 +*/ + + +import java.util.Scanner; + +class Lesson_32_Activity_Four { + + public static void realTime(int sec) { + int hour = 0; + int min = 0; + + hour = (int)(sec/(60*60)); + sec-=(hour*60*60); + min = (int)(sec/60); + sec-=(min*60); + + System.out.println("Hours: "+hour+"\nMinutes: "+min+"\nSeconds: "+sec); + } + + + public static void main(String[] args) + { + realTime(6342); + } +} diff --git a/Term1/Lesson32/Lesson_32_Activity_One.java b/Term1/Lesson32/Lesson_32_Activity_One.java new file mode 100644 index 0000000..161c6fd --- /dev/null +++ b/Term1/Lesson32/Lesson_32_Activity_One.java @@ -0,0 +1,73 @@ +package Lesson32; +/* +* Lesson 32 Coding Activity 1 +* +* For the Lesson 32 activities, you will be asked to write one or more methods. +* Use the template to write a main method that tests each of your methods, +* then paste everything into the code runner box. Your submission should +* begin with the first import statement and end with the final }. +* +* Write a method that takes a parameter for the number of a month +* and prints the month's name. +* +* This method must be called monthName() and it must have an integer parameter. +* +* Calling monthName(8) should print August to the screen. +*/ + + +import java.util.Scanner; + +class Lesson_32_Activity_One { + + public static void monthName(int monthNum) { + switch(monthNum) { + case 1: + System.out.println("January"); + break; + case 2: + System.out.println("February"); + break; + case 3: + System.out.println("March"); + break; + case 4: + System.out.println("April"); + break; + case 5: + System.out.println("May"); + break; + case 6: + System.out.println("June"); + break; + case 7: + System.out.println("July"); + break; + case 8: + System.out.println("August"); + break; + case 9: + System.out.println("September"); + break; + case 10: + System.out.println("October"); + break; + case 11: + System.out.println("November"); + break; + case 12: + System.out.println("December"); + break; + default: + System.out.println("ERROR, month was not between 1 and 12"); + break; + } + + + } + + public static void main(String[] args){ + int monthNum = 123; + monthName(monthNum); + } +} diff --git a/Term1/Lesson32/Lesson_32_Activity_Three.java b/Term1/Lesson32/Lesson_32_Activity_Three.java new file mode 100644 index 0000000..8fc50ff --- /dev/null +++ b/Term1/Lesson32/Lesson_32_Activity_Three.java @@ -0,0 +1,34 @@ +package Lesson32; +/* +* Lesson 32 Coding Activity 3 +* +* For the Lesson 32 activities, you will be asked to write one or more methods. +* Use the template to write a main method that tests each of your methods, +* then paste everything into the code runner box. Your submission should +* begin with the first import statement and end with the final }. +* +* Write a method that takes two integer parameters and prints them in reverse. +* +* This method must be called swap and should take two integer parameters. +* +* Calling swap(3, 7) would print 7 3. +* +*/ + + +import java.util.Scanner; + +class Lesson_32_Activity_Three { + + public static void swap(int one, int two) { + System.out.println(two + " " + one); + } + + + public static void main(String[] args) + { + /* + * Test your method here + */ + } +} diff --git a/Term1/Lesson32/Lesson_32_Activity_Two.java b/Term1/Lesson32/Lesson_32_Activity_Two.java new file mode 100644 index 0000000..a7db39a --- /dev/null +++ b/Term1/Lesson32/Lesson_32_Activity_Two.java @@ -0,0 +1,73 @@ +package Lesson32; +/* +* Lesson 32 Coding Activity 2 +* +* For the Lesson 32 activities, you will be asked to write one or more methods. +* Use the template to write a main method that tests each of your methods, +* then paste everything into the code runner box. Your submission should +* begin with the first import statement and end with the final }. +* +* Write a method that takes a parameter for the number of a month +* and prints the number of days in the month. Assume that February +* will always have 28 days for this activity. +* +* This method must be called monthDays()and it must take a integer parameter. +* +* Calling monthDays(2) would print 28 and monthDays(9) would print 30. +* +*/ + + +import java.util.Scanner; + +class Lesson_32_Activity_Two { + + + public static void monthDays(int monthNum) { + switch(monthNum) { + case 1: + System.out.println("31"); + break; + case 2: + System.out.println("28"); + break; + case 3: + System.out.println("31"); + break; + case 4: + System.out.println("30"); + break; + case 5: + System.out.println("31"); + break; + case 6: + System.out.println("30"); + break; + case 7: + System.out.println("31"); + break; + case 8: + System.out.println("31"); + break; + case 9: + System.out.println("30"); + break; + case 10: + System.out.println("31"); + break; + case 11: + System.out.println("30"); + break; + case 12: + System.out.println("31"); + break; + default: + System.out.println("ERROR, month was not between 1 and 12"); + break; + } + } + + public static void main(String[] args) + { + } +} diff --git a/Term1/Lesson32/T1_L32_Template.java b/Term1/Lesson32/T1_L32_Template.java new file mode 100644 index 0000000..e98b85b --- /dev/null +++ b/Term1/Lesson32/T1_L32_Template.java @@ -0,0 +1,29 @@ +package Lesson32; +/* + * Lesson 32 - Unit 4 - Parameters + */ + + +import java.util.Scanner; +import java.lang.Math; + +public class T1_L32_Template{ + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + System.out.println("Please enter a decimal value"); + double value = scan.nextDouble(); + + System.out.println(square(value)); + scan.close(); + } + public static double square (double num) { + double squaredNum = num * num; + return squaredNum; + } + +} + + diff --git a/Term1/Lesson33/Lesson_33_Activity_Five.java b/Term1/Lesson33/Lesson_33_Activity_Five.java new file mode 100644 index 0000000..d5543c8 --- /dev/null +++ b/Term1/Lesson33/Lesson_33_Activity_Five.java @@ -0,0 +1,52 @@ +package Lesson33; +/* + * Lesson 33 Coding Activity 5 + * + * For the Lesson 33 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * For questions 2-5, you may want to start with the printIt method + * and use it to test the other three. + * + * Write a method that takes an array of ints, an integer value, + * and an integer index.The method should insert the value at the given + * index and move the values afterwards by one. + * + * This method must be called insertValue() and must have the following + * parameter types: int[], integer, integer. + * + * Calling insertValue(a, 100, 2) would change the array {1, 2, 3, 4, 5} + * to {1, 2, 100, 3, 4}. + */ + + +import java.util.Arrays; +import java.util.Scanner; + +class Lesson_33_Activity_Five { + public static void main(String[] args) { + int[] a = {3, 4, 5, 6, 7}; + insertValue(a, 100, 2); + + } + public static void insertValue(int[] array, int num, int index) { + int[] newarray = new int [array.length]; + for(int i = array.length-1; i >= 0; i--) { + if(i == index) { + newarray[i] = num; + } + else if(i > index){ + newarray[i] = array[i-1]; + } + else { + newarray[i] = array[i]; + } + } + for(int i = 0; i < array.length; i++) { + array[i] = newarray[i]; + } + //System.out.print(Arrays.toString(array)); + } +} \ No newline at end of file diff --git a/Term1/Lesson33/Lesson_33_Activity_Four.java b/Term1/Lesson33/Lesson_33_Activity_Four.java new file mode 100644 index 0000000..57a0866 --- /dev/null +++ b/Term1/Lesson33/Lesson_33_Activity_Four.java @@ -0,0 +1,40 @@ +package Lesson33; +/* + * Lesson 33 Coding Activity 4 + * + * For the Lesson 33 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * For questions 2-5, you may want to start with the printIt method + * and use it to test the other three. + * + * Write a method that takes an array of ints and reverses the order + * of the values in the array. So the array {1, 2, 3} would be changed to {3, 2, 1} + * + * This method must be called reverse() and it must take an int[] parameter. + */ + + +import java.util.Scanner; + +class Lesson_33_Activity_Four { + public static void main(String[] args) { + + + } + public static void reverse(int[] array) { + int reversedArrayIndex = 0; + int[] reversedArray = new int [array.length]; + for(int i = array.length-1; i >= 0; i--) { + reversedArray[reversedArrayIndex] = array[i]; + reversedArrayIndex++; + } + reversedArrayIndex = 0; + for(int i = 0; i < array.length; i++) { + array[i] = reversedArray[reversedArrayIndex]; + reversedArrayIndex++; + } + } +} \ No newline at end of file diff --git a/Term1/Lesson33/Lesson_33_Activity_One.java b/Term1/Lesson33/Lesson_33_Activity_One.java new file mode 100644 index 0000000..025f5df --- /dev/null +++ b/Term1/Lesson33/Lesson_33_Activity_One.java @@ -0,0 +1,35 @@ +package Lesson33; +/* + * Lesson 33 Coding Activity 1 + * + * For the Lesson 33 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * For questions 2-5, you may want to start with the printIt method + * and use it to test the other three. + * + * Write a method that takes an array of Strings and changes of the Strings to UPPER CASE. + * + * This method must be called upper() and it must take a String[] parameter. + * + * Use T1_L33_Reference_Tempate.java, which is included in this folder, + * as a reference. + * + */ + + +import java.util.Scanner; + +class Lesson_33_Activity_One { + public static void main(String[] args) { + + + } + public static void upper(String[] array) { + for(int i = 0; i < array.length; i++) { + array[i] = array[i].toUpperCase(); + } + } +} \ No newline at end of file diff --git a/Term1/Lesson33/Lesson_33_Activity_Three.java b/Term1/Lesson33/Lesson_33_Activity_Three.java new file mode 100644 index 0000000..5d7c94e --- /dev/null +++ b/Term1/Lesson33/Lesson_33_Activity_Three.java @@ -0,0 +1,34 @@ +package Lesson33; +/* + * Lesson 33 Coding Activity 3 + * + * For the Lesson 33 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * For questions 2-5, you may want to start with the printIt method + * and use it to test the other three. + * + * Write a method that takes an array of ints and prints the array on a + * single line. Print one space between each number. + * + * This method must be called printit() and it must take an int[] parameter. + */ + + +import java.util.Scanner; + +class Lesson_33_Activity_Three { + public static void main(String[] args) { + + + } + public static void printit(int[] array) { + String print = ""; + for(int i = 0; i < array.length; i++) { + print += array[i] + " "; + } + System.out.println(print); + } +} \ No newline at end of file diff --git a/Term1/Lesson33/Lesson_33_Activity_Two.java b/Term1/Lesson33/Lesson_33_Activity_Two.java new file mode 100644 index 0000000..3b70ede --- /dev/null +++ b/Term1/Lesson33/Lesson_33_Activity_Two.java @@ -0,0 +1,35 @@ +package Lesson33; +/* + * Lesson 33 Coding Activity 2 + * + * For the Lesson 33 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * For questions 2-5, you may want to start with the printIt method + * and use it to test the other three. + * + * Write a method that takes an array of ints and stores random numbers + * between 10 and 99 in the array. Use Math.random() to generate + * random numbers and convert them to integers between 10 and 99 inclusive. + * + * This method must be called randomize() and it must take an int[] parameter. + * + */ + + +import java.util.Scanner; + +class Lesson_33_Activity_Two { + public static void main(String[] args) { + + + } + public static void randomize(int[] array) { + for(int i = 0; i < array.length; i++) { + int randomNum = (int)(Math.random()*90+10); + array[i] = randomNum; + } + } +} \ No newline at end of file diff --git a/Term1/Lesson33/T1_L33_Template.java b/Term1/Lesson33/T1_L33_Template.java new file mode 100644 index 0000000..aa564d0 --- /dev/null +++ b/Term1/Lesson33/T1_L33_Template.java @@ -0,0 +1,60 @@ +package Lesson33; +/* + * Lesson 33 - Unit 4 - Parameters - Primitive vs. Class + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson33_template{ + + public static void addOne(int c) + { + c++; + System.out.println("Value in method: \t\t" +c); + + }//addOne + public static void addOneArray (int nums []) + { + for (int i = 0; i < nums.length; i++) + { + nums[i] ++; + } + + System.out.print("\nValue of array in the method: \t" ); + + for (int i = 0; i < nums.length; i++) + { + System.out.print (nums[i] + " "); + } + }//addOneArray + + public static void main (String str[]) throws IOException { + + int x = 9; + + System.out.print ("Value before method: \t" + x ); + addOne(x); + System.out.print ("Value after method: \t\t" + x ); + +/* + int list[] = {4,5,6,7,8,3}; + System.out.print ("\nValue of array before method: \t" ); + for(int i=0; i < list.length; i++) + System.out.print(list[i] + " "); + + addOneArray(list); + + System.out.print ("\nValue of array after method: \t" ); + for(int i=0; i < list.length; i++) + System.out.print(list[i] + " "); +*/ + } + +} + + diff --git a/Term1/Lesson34/Lesson_34_Activity_Five.java b/Term1/Lesson34/Lesson_34_Activity_Five.java new file mode 100644 index 0000000..e943ab9 --- /dev/null +++ b/Term1/Lesson34/Lesson_34_Activity_Five.java @@ -0,0 +1,40 @@ +package Lesson34; +/* + * Lesson 34 Coding Activity 5 + * + * For the Lesson 34 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * Write a method that takes an array of ints + * and returns a sum of only the even values. + * + * public static int sumEven(int [] a) + * + * For example, sumEven(a) would return 6 if a = {1, 2, 3, 4, 5}. + */ + + +import java.util.Scanner; + +class Lesson_34_Activity_Five { + + public static int sumEven(int [] a) + { + int sum = 0; + for(int i = 0; imax) { + max = a[i]; + } + } + return max; + } + + public static void main(String[] args) + { + /* + * Test your method here + */ + } +} \ No newline at end of file diff --git a/Term1/Lesson34/Lesson_34_Activity_Two.java b/Term1/Lesson34/Lesson_34_Activity_Two.java new file mode 100644 index 0000000..428828b --- /dev/null +++ b/Term1/Lesson34/Lesson_34_Activity_Two.java @@ -0,0 +1,42 @@ +package Lesson34; +/* + * Lesson 34 Coding Activity 2 + * + * For the Lesson 34 activities, you will be asked to write one or more methods. + * Use the template to write a main method that tests each of your methods, + * then paste everything into the code runner box. Your submission should + * begin with the first import statement and end with the final }. + * + * Write a method that takes an array of ints as a parameter + * and returns the average value of the array as a double. + * + * public static double average(int [] a) + * + * For example, average(a) would return 2.0 + * if a = {1, 2, 3} or 1.0 if a = {1, 1, 1}. + */ + + +import java.util.Scanner; + +class Lesson_34_Activity_Two { + + public static double average(int [] a) + { + int sum = 0; + double aLength = a.length; + for(int i = 0; i < a.length; i++) { + sum+=a[i]; + } + double average = sum/aLength; + return average; + } + + + public static void main(String[] args) + { + /* + * Test your method here + */ + } +} \ No newline at end of file diff --git a/Term1/Lesson34/T1_L34_Template.java b/Term1/Lesson34/T1_L34_Template.java new file mode 100644 index 0000000..d3ba6b8 --- /dev/null +++ b/Term1/Lesson34/T1_L34_Template.java @@ -0,0 +1,36 @@ +package Lesson34; +//FIXME: WATCH LESSON 34!!!!! +/* +* Lesson 34 - Unit 4 - Return Methods +*/ +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson34_template{ + + public static int max (int a, int b) + { + if (a>b) + return a; + return b; + }//max + + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + System.out.println ("Enter two integers: "); + + int x = scan.nextInt(); + int y = scan.nextInt(); + + System.out.println ("The largest is: " + max (x, y)); + + } +} + + diff --git a/Term1/Lesson35/Lesson_35_Activity.java b/Term1/Lesson35/Lesson_35_Activity.java new file mode 100644 index 0000000..6280208 --- /dev/null +++ b/Term1/Lesson35/Lesson_35_Activity.java @@ -0,0 +1,50 @@ +package Lesson35; +/* + * Lesson 35 Coding Activity + * + * Write four overloaded methods called randomize. Each method will + * return a random number based on the parameters that it receives: + * + * Write four overloaded methods called randomize. + * Each method will return a random number based on the parameters that it receives: + * randomize() - Returns a random int between min and max inclusive. Must have two int parameters. + * randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. + * randomize() - Returns a random double between min and max inclusive. Must have two double parameters. + * randomize() - Returns a random double between 0 and max inclusive. Must have one double parameter. + * + * Because these methods are overloaded, they should be declared in the same class. + * To simulate this, copy all four methods into the single Code Runner box. + */ + + +import java.util.Scanner; + +class Lesson_35_Activity { + + public static int randomize(int min, int max) { + int range = Math.abs(max-min); + return (int)(Math.random()*range)+min; + } + + public static int randomize(int max) { + return randomize(0, max); + } + + public static double randomize(double min, double max) { + double range = Math.abs(max-min); + return Math.random()*range+min; + } + + public static double randomize(double max) { + return randomize(0, max); + } + + + public static void main(String[] args) + { + /* + * Test your method here + * Copy and paste this entire class to Code Runner. + */ + } +} \ No newline at end of file diff --git a/Term1/Lesson35/T1_L35_Template.java b/Term1/Lesson35/T1_L35_Template.java new file mode 100644 index 0000000..846972b --- /dev/null +++ b/Term1/Lesson35/T1_L35_Template.java @@ -0,0 +1,45 @@ +package Lesson35; +/* + * Lesson 35 - Unit 4 - Overloaded Methods + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + + +class t1_lesson35_template{ + + public static int sum (int a, int b) + { + return a + b; + }//sum + + public static int sum (int v[]) + { + int s =0; + for (int i =0; i < v.length; i++) + s += v[i]; + return s; + }//sum + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + System.out.println ("Enter two integers: "); + + int x = scan.nextInt(); + int y = scan.nextInt(); + + System.out.println ("The sum is: " + sum (x, y)); + + + int vals []= { 3, 6, 2, 9, 11}; + System.out.println ("The sum is: " + sum (vals)); + } + +} + + diff --git a/Term1/Lesson36/T1_L36_Introduction_to_Recursion.pdf b/Term1/Lesson36/T1_L36_Introduction_to_Recursion.pdf new file mode 100644 index 0000000..46c9fc9 Binary files /dev/null and b/Term1/Lesson36/T1_L36_Introduction_to_Recursion.pdf differ diff --git a/Term1/Lesson37/T1_L37_Recursion_Function_with_Returns.pdf b/Term1/Lesson37/T1_L37_Recursion_Function_with_Returns.pdf new file mode 100644 index 0000000..07d2862 Binary files /dev/null and b/Term1/Lesson37/T1_L37_Recursion_Function_with_Returns.pdf differ diff --git a/Term1/Lesson4/Lesson_4_Activity_One.java b/Term1/Lesson4/Lesson_4_Activity_One.java new file mode 100644 index 0000000..c4d2237 --- /dev/null +++ b/Term1/Lesson4/Lesson_4_Activity_One.java @@ -0,0 +1,35 @@ +package Lesson4; +/* + * Lesson 4 Coding Activity Question 1 + * + * Input two doubles and print them backwards on the screen. + * + * So if the user enters: + + 1.3 6.8 + + * It should output: + + 6.8 1.3 + + * Notice there is exactly one space between the numbers. +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_4_Activity_One { + public static void main(String[] args) { + + double one; + double two; + Scanner scan = new Scanner (System.in); + + System.out.println("Please enter two decimal numbers"); + one = scan.nextDouble(); + two = scan.nextDouble(); + + System.out.println(two + " " + one); + + } +} \ No newline at end of file diff --git a/Term1/Lesson4/Lesson_4_Activity_Two.java b/Term1/Lesson4/Lesson_4_Activity_Two.java new file mode 100644 index 0000000..82ede50 --- /dev/null +++ b/Term1/Lesson4/Lesson_4_Activity_Two.java @@ -0,0 +1,36 @@ +package Lesson4; +/* + * Lesson 4 Coding Activity Question 2 + * + * Ask the user their name and age and print out how many years until + * they are 100. Note that age should be an integer, not a double. + * + * Sample run: + +Hi there. What is your name? +Pascal +Hi Pascal. How old are you? +16 +Pascal, you will be 100 in 84 years. + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_4_Activity_Two { + public static void main(String[] args) { + + int age; + String name; + Scanner scan = new Scanner (System.in); + + System.out.println("Hi there. What is your name?"); + name = scan.nextLine(); + System.out.println("Hi " + name + ". How old are you?"); + age = scan.nextInt(); + System.out.println(name + ", You will be 100 in " + (100 - age) + " years."); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson4/T1_L4_Template.java b/Term1/Lesson4/T1_L4_Template.java new file mode 100644 index 0000000..aa2db4f --- /dev/null +++ b/Term1/Lesson4/T1_L4_Template.java @@ -0,0 +1,30 @@ +package Lesson4; +/* + * Lesson 4 - Unit 1 - Data types + */ + +import java.io.*; +import static java.lang.System.*; +import java.util.Scanner; + +class t1_lesson04_template{ + + + public static void main (String str[]) throws IOException { + + + int x = 9; + + System.out.println(x ); + System.out.println(x * 7); + + int y = 2147483647; + y++; + System.out.println(y); + + + } + +} + + diff --git a/Term1/Lesson5/Lesson_5_Activity_Four.java b/Term1/Lesson5/Lesson_5_Activity_Four.java new file mode 100644 index 0000000..a9a698a --- /dev/null +++ b/Term1/Lesson5/Lesson_5_Activity_Four.java @@ -0,0 +1,32 @@ +package Lesson5; +/* + * Lesson 5 Coding Activity Question 4 + * + * Ask the user to enter the price of an item and tell them + * how much money they would get back from $20. It's okay to + * return a negative number. Also, Don't forget to include the dollar sign. + * + * Sample Run: + +Enter a price: +3.50 +Change from $20: $16.5 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_5_Activity_Four { + public static void main(String[] args) { + + double p; + Scanner scan = new Scanner (System.in); + + System.out.println("Enter a price:"); + p = scan.nextDouble(); + System.out.println("Change from $20: $" + (20 - p)); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson5/Lesson_5_Activity_One.java b/Term1/Lesson5/Lesson_5_Activity_One.java new file mode 100644 index 0000000..249fa21 --- /dev/null +++ b/Term1/Lesson5/Lesson_5_Activity_One.java @@ -0,0 +1,26 @@ +package Lesson5; +/* + * Lesson 5 Coding Activity Question 1 + * + * Input two double values and print the difference between them. + * (The difference can be found by subtracting the second value from the first). + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_5_Activity_One { + public static void main(String[] args) { + + double one; + double two; + Scanner scan = new Scanner (System.in); + + System.out.println("Hey! Plase enter two numbers"); + one = scan.nextDouble(); + two = scan.nextDouble(); + System.out.println("THe difference between the two numbers is " + (two - one)); + + } +} \ No newline at end of file diff --git a/Term1/Lesson5/Lesson_5_Activity_Three.java b/Term1/Lesson5/Lesson_5_Activity_Three.java new file mode 100644 index 0000000..c0bca50 --- /dev/null +++ b/Term1/Lesson5/Lesson_5_Activity_Three.java @@ -0,0 +1,36 @@ +package Lesson5; +/* + * Lesson 5 Coding Activity Question 3 + * + * Input the radius of a circle and print the circumference and area. + * The answer should be a decimal value. + * + * Remember the formula for circumference is 2 * pi * r and the formula + * for area is pi * r * r. You can use 3.14 for the value of pi in this activity. + * + * Sample Run: + +Enter a radius: +4 +Circumference: 25.12 +Area: 50.24 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_5_Activity_Three { + public static void main(String[] args) { + + double r; + Scanner scan = new Scanner (System.in); + + System.out.println("Enter a radius:"); + r = scan.nextDouble(); + System.out.println("Circumference: " + (2 * 3.14 * r)); + System.out.println("Area: " + (3.14 * r * r)); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson5/Lesson_5_Activity_Two.java b/Term1/Lesson5/Lesson_5_Activity_Two.java new file mode 100644 index 0000000..2b942e7 --- /dev/null +++ b/Term1/Lesson5/Lesson_5_Activity_Two.java @@ -0,0 +1,32 @@ +package Lesson5; +/* + * Lesson 5 Coding Activity Question 2 + * + * Input four integer values and print the sum of all four values. + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_5_Activity_Two { + public static void main(String[] args) { + + int one; + int two; + int three; + int four; + Scanner scan = new Scanner (System.in); + + System.out.println("Please enter 4 integers"); + one = scan.nextInt(); + two = scan.nextInt(); + three = scan.nextInt(); + four = scan.nextInt(); + System.out.println("The sum of the 4 integers is " + (one+two+three+four)); + + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson5/T1_L5_Template.java b/Term1/Lesson5/T1_L5_Template.java new file mode 100644 index 0000000..22cee79 --- /dev/null +++ b/Term1/Lesson5/T1_L5_Template.java @@ -0,0 +1,31 @@ +package Lesson5; + +/* + * Lesson 5 - Unit 1 - Number Calculations and Order of Operations + */ + +import java.io.*; +import static java.lang.System.*; +import java.util.Scanner; + +class t1_lesson05_template{ + + + public static void main (String str[]) throws IOException { + + Scanner scan = new Scanner (System.in); + + int num1 = 18; + int num2 = 3; + + System.out.println("Please enter two intagers"); + num1 = scan.nextInt(); + num2 = scan.nextInt(); + + System.out.println(((double)num1 + num2)/2); + + } + +} + + diff --git a/Term1/Lesson6/Lesson_6_Activity_One.java b/Term1/Lesson6/Lesson_6_Activity_One.java new file mode 100644 index 0000000..8b1a8c8 --- /dev/null +++ b/Term1/Lesson6/Lesson_6_Activity_One.java @@ -0,0 +1,43 @@ +package Lesson6; +/* + * Lesson 6 Coding Activity Question 1 + +double x = (11+4)/2 + + * What answer do you get? The answer is imprecise! + * + * Write a Java program that precisely calculates the average + * between two integers that input from the keyboard, and prints + * the answer to the screen. The average must include the integer + * and decimal portions of the calculation. + * + * Sample Run: + +Please enter two integers: +4 +11 + +The average is: 7.5 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_6_Activity_One { + public static void main(String[] args) { + + int one; + int two; + Scanner scan = new Scanner (System.in); + + System.out.println("Please enter two integers:"); + one = scan.nextInt(); + two = scan.nextInt(); + + System.out.println("The average is: " + ((double)(one+two)/2)); + + + + } +} \ No newline at end of file diff --git a/Term1/Lesson6/Lesson_6_Activity_Three.java b/Term1/Lesson6/Lesson_6_Activity_Three.java new file mode 100644 index 0000000..e67b2f7 --- /dev/null +++ b/Term1/Lesson6/Lesson_6_Activity_Three.java @@ -0,0 +1,34 @@ +package Lesson6; +/* + * Lesson 6 Coding Activity Question 3 + * + * Input a double and print the first two digits after the decimal point. + * + * Sample run: + +Please input a decimal number: +57.8934 +Answer: 89 + + * Hint - you will need to do a numeric cast and some division and/or subtraction. + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_6_Activity_Three { + public static void main(String[] args) { + + double num; + double answer; + Scanner scan = new Scanner (System.in); + + System.out.println("Please input a decimal number:"); + num = scan.nextDouble(); + answer = (num - ((int)num))*100; + System.out.println("Answer: " + (int)answer); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson6/Lesson_6_Activity_Two.java b/Term1/Lesson6/Lesson_6_Activity_Two.java new file mode 100644 index 0000000..3cb55fb --- /dev/null +++ b/Term1/Lesson6/Lesson_6_Activity_Two.java @@ -0,0 +1,29 @@ +package Lesson6; +/* + * Lesson 6 Coding Activity Question 2 + * + * Input a double value and print only the integer part. + * + * Sample run: + +Please input a decimal number: +57.8934 +Answer: 57 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_6_Activity_Two { + public static void main(String[] args) { + + double num; + Scanner scan = new Scanner (System.in); + System.out.println("Please input a decimal number:"); + num = scan.nextDouble(); + System.out.println("Answer: " + (int)num); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson6/T1_L6_Template.java b/Term1/Lesson6/T1_L6_Template.java new file mode 100644 index 0000000..dad6a14 --- /dev/null +++ b/Term1/Lesson6/T1_L6_Template.java @@ -0,0 +1,28 @@ +package Lesson6; +/* + * Lesson 6 - Unit 1 - Output in Java + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson06_template{ + + + public static void main (String str[]) throws IOException { + + + int x = 15; + double half = (double)x/2; + + System.out.println(half); + + + + } + +} + + diff --git a/Term1/Lesson7/Lesson_7_Activity_One.java b/Term1/Lesson7/Lesson_7_Activity_One.java new file mode 100644 index 0000000..4b0ae41 --- /dev/null +++ b/Term1/Lesson7/Lesson_7_Activity_One.java @@ -0,0 +1,47 @@ +package Lesson7; +/* + * Lesson 7 Coding Activity Question 1 + * + * Input a positive three digit integer. Print out the digits one per line. + * + * Sample run: + +Please enter a three digit number: +678 + +Here are the digits: +6 +7 +8 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_7_Activity_One { + public static void main(String[] args) { + + int enteredDigit; + int digit1; + int digit2; + int digit3; + + Scanner scan = new Scanner (System.in); + + + System.out.println("Please enter a three digit number:"); + enteredDigit = scan.nextInt(); + + digit1 = (enteredDigit % 1000)/100; + digit2 = (enteredDigit % 100)/10; + digit3 = enteredDigit % 10; + + System.out.println("Here are the digits:"); + System.out.println(digit1); + System.out.println(digit2); + System.out.println(digit3); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson7/Lesson_7_Activity_Two.java b/Term1/Lesson7/Lesson_7_Activity_Two.java new file mode 100644 index 0000000..2e4f7da --- /dev/null +++ b/Term1/Lesson7/Lesson_7_Activity_Two.java @@ -0,0 +1,53 @@ +package Lesson7; +/* + * Lesson 7 Coding Activity Question 2 + * + * Change the last problem so that it also prints the sum of the digits. + * Use the format shown below. + * + * Make sure your output is printed in the same order as the sample run. + * + * Sample run: + +Please enter a three digit number: +678 + +Here are the digits: +6 +7 +8 + +6 + 7 + 8 = 21 + +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_7_Activity_Two { + public static void main(String[] args) { + + int enteredDigit; + int digit1; + int digit2; + int digit3; + + Scanner scan = new Scanner (System.in); + + + System.out.println("Please enter a three digit number:"); + enteredDigit = scan.nextInt(); + + digit1 = (enteredDigit % 1000)/100; + digit2 = (enteredDigit % 100)/10; + digit3 = enteredDigit % 10; + + System.out.println("Here are the digits:"); + System.out.println(digit1); + System.out.println(digit2); + System.out.println(digit3); + System.out.println("\n" + digit1 + " + " + digit2 + " + " + digit3 + " = " + (digit1+digit2+digit3)); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson7/T1_L7_Template.java b/Term1/Lesson7/T1_L7_Template.java new file mode 100644 index 0000000..e298ef3 --- /dev/null +++ b/Term1/Lesson7/T1_L7_Template.java @@ -0,0 +1,28 @@ +package Lesson7; +/* + * Lesson 7 - Unit 1 - Modular Division + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson07_template{ + + public static void main (String str[]) throws IOException { + + + Scanner scan = new Scanner(System.in); + + int x = scan.nextInt(); + int y = scan.nextInt(); + + System.out.println ("Division: " + ( x / y) + "\tRemainder: " + (x % y)); + + + } + +} + + diff --git a/Term1/Lesson8/T1_L8_Template.java b/Term1/Lesson8/T1_L8_Template.java new file mode 100644 index 0000000..547f1fb --- /dev/null +++ b/Term1/Lesson8/T1_L8_Template.java @@ -0,0 +1,23 @@ +package Lesson8; +/* + * Lesson 8 - Unit 1 - Strings and numbers + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t1_lesson08_template{ + + public static void main (String str[]) throws IOException { + + int x = 9; + int y = 3; + System.out.println ("The sum is: " + x + y); + + } + +} + + diff --git a/Term1/Lesson9/Lesson_9_Activity_One.java b/Term1/Lesson9/Lesson_9_Activity_One.java new file mode 100644 index 0000000..0263427 --- /dev/null +++ b/Term1/Lesson9/Lesson_9_Activity_One.java @@ -0,0 +1,19 @@ +package Lesson9; + +/* + * Lesson 9 Coding Activity Question 1 + * + * Write the code to print a random integer from 1 to 10 inclusive using Math.random(). + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_9_Activity_One { + public static void main(String[] args) { + + System.out.println((int)(Math.random() * 10+1)); + + } +} \ No newline at end of file diff --git a/Term1/Lesson9/Lesson_9_Activity_Three.java b/Term1/Lesson9/Lesson_9_Activity_Three.java new file mode 100644 index 0000000..25ffe4f --- /dev/null +++ b/Term1/Lesson9/Lesson_9_Activity_Three.java @@ -0,0 +1,20 @@ +package Lesson9; + +/* + * Lesson 9 Coding Activity Question 3 + * + * Write the code to print a random integer from 20 to 40 inclusive using Math.random(). + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_9_Activity_Three { + public static void main(String[] args) { + + System.out.println((int)(Math.random() * 21)+40); + + + } +} diff --git a/Term1/Lesson9/Lesson_9_Activity_Two.java b/Term1/Lesson9/Lesson_9_Activity_Two.java new file mode 100644 index 0000000..507addb --- /dev/null +++ b/Term1/Lesson9/Lesson_9_Activity_Two.java @@ -0,0 +1,20 @@ +package Lesson9; + +/* + * Lesson 9 Coding Activity Question 2 + * + * Write the code to print a random integer from -20 to 20 inclusive using Math.random(). + * +*/ + +import java.util.Scanner; +import java.lang.Math; + +class Lesson_9_Activity_Two { + public static void main(String[] args) { + + System.out.println((int)(Math.random() * 41)-20); + + + } +} \ No newline at end of file diff --git a/Term1/Lesson9/T1_L9_Template.java b/Term1/Lesson9/T1_L9_Template.java new file mode 100644 index 0000000..4f670ae --- /dev/null +++ b/Term1/Lesson9/T1_L9_Template.java @@ -0,0 +1,39 @@ +package Lesson9; +/* + * Lesson 9 - Unit 1 - Math functions. + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +import java.lang.Math; + +class t1_lesson09_template{ + + public static void main (String str[]) throws IOException { + + + Scanner scan = new Scanner (System.in); + + System.out.println("Please enter 2 ints: "); + int x = scan.nextInt(); + int y = scan.nextInt(); + + System.out.println("Please enter 2 doubles: "); + double a = scan.nextDouble(); + double b = scan.nextDouble(); + + System.out.println("Answers: "); + System.out.println(Math.abs(x - y)); + System.out.println(Math.abs(a - b)); + + + + + } + +} + + diff --git a/Term1/_Class_Labs/WhileLoops.java b/Term1/_Class_Labs/WhileLoops.java new file mode 100644 index 0000000..fa2194b --- /dev/null +++ b/Term1/_Class_Labs/WhileLoops.java @@ -0,0 +1,57 @@ +package _Class_Labs; + +public class WhileLoops { + + public static void main(String[] agrs) { + + LoopDivisor(); + + } + + public static void LoopDigit() { + + int num = 234, digits=0; + int orginal = num; + while(num>0) { + digits++; + num = (num/10); + } + System.out.println(orginal + " contains " + digits +" digits"); + } + + public static void LoopAdd() { + int num = 234, orginal = num, sum = 0; + while(num>0) { + sum += (num%10); + num = num/10; + } + System.out.println(sum + " is the sum of the digits of " + orginal); + } + + public static void LoopAvg() { + int num = 234, orginal = num, sum = 0; + double digits = 0; + while(num>0) { + sum += (num%10); + num = num/10; + digits++; + } + System.out.println(orginal + " has a digit average of " + (sum/digits)); + } + + public static void LoopDivisor() { + int num= 100, count = 1; + String divisors = ""; + while(count two) { + System.out.println("largest == " + one); + System.out.println("samllest == " + two); + } + else { + System.out.println("largest == " + two); + System.out.println("largest == " + one); + } + } + + public static void lab2() { + //hello does not have the same letters as goodbye + + Scanner scan = new Scanner (System.in); + + String one, two; + + one = scan.nextLine(); + two = scan.nextLine(); + + if (one.equals(two)) { + System.out.println(one + " has the same letters as " + two); + } + else { + System.out.println(one + " does not have the same letters as " + two); + } + + + } + + public static void lab3() { + + Scanner scan = new Scanner (System.in); + + String one, two; + + one = scan.nextLine(); + two = scan.nextLine(); + + int result = one.compareTo(two); + + if(result < 0) { + System.out.println(one + " should be placed before " + two); + } + else { + System.out.println(one + " should be placed after " + two); + } + } + + public static void lab4() { + Scanner scan = new Scanner (System.in); + + int dash1, dash2; + int oneInt, twoInt, threeInt; + String securityNum; + String one, two, three; + int lengthOfNum; + + securityNum = scan.nextLine(); + + dash1 = securityNum.indexOf('-'); + dash2 = securityNum.lastIndexOf('-'); + + one = securityNum.substring(0,dash1); + two = securityNum.substring((dash1+1),dash2); + three = securityNum.substring((dash2+1),(securityNum.length())); + + oneInt = Integer.parseInt(one); + twoInt = Integer.parseInt(two); + threeInt = Integer.parseInt(three); + System.out.println("ss# " + securityNum + " has a total of " + (oneInt+twoInt+threeInt)); + + + + } + + public static void lab5() { + String one, two; + Scanner scan = new Scanner (System.in); + one = scan.nextLine(); + two = scan.nextLine(); + int oneLength, twoLength; + oneLength = one.length(); + twoLength = two.length(); + + if(oneLength == twoLength) { + System.out.println(one + " has the same # of letters as " + two); + } + else { + System.out.println(one + " does not has the same # of letters as " + two); + } + } + + public static void lab6() { + Scanner scan = new Scanner (System.in); + String one, two; + one = scan.nextLine(); + two = scan.nextLine(); + char oneL = one.charAt(0); + char twoL = two.charAt(0); + + if(oneL==twoL) { + System.out.println(one + " has the same first letter as " + two); + } + else { + System.out.println(one + " does not has the same first letter as " + two); + } + + } + + public static void lab7() { + Scanner scan = new Scanner (System.in); + String word = scan.nextLine(); + System.out.println(word); + String wordUpper = word.toUpperCase(); + System.out.println(wordUpper); + int wordUpperSpace = wordUpper.indexOf(' '); + String wordUpperH = (wordUpper.substring(0,wordUpperSpace)+"-"+wordUpper.substring(wordUpperSpace+1)); + System.out.println(wordUpperH); + + + + + } +} + \ No newline at end of file diff --git a/Term1/_Class_Work/APCSQuiz3_Practice.java b/Term1/_Class_Work/APCSQuiz3_Practice.java new file mode 100644 index 0000000..d41a67e --- /dev/null +++ b/Term1/_Class_Work/APCSQuiz3_Practice.java @@ -0,0 +1,216 @@ +package _Class_Work; + +/* +************************ANSWER ON PAPER*********************** + +Name: Date: + +public class APCSQuiz3_Practice +{ + public static void main(String[] args) + { + // Question 1 [5 points]: Go to each function and find out and write its output. + + question1_f(); System.out.println(); + question1_g(); System.out.println(); + question1_h(); System.out.println(); + question1_i(); System.out.println(); + question1_j(); System.out.println(); + + // Question 2 [5 points]: Go to each function and find out errors and fix them. + question2_f(); System.out.println(); + question2_g(); System.out.println(); + question2_h(); System.out.println(); + question2_i(); System.out.println(); + question2_j(); System.out.println(); + + + // Question 3 [6 points]: Write for loops to produce the intended output. Points will be deducted for using "if statements'. + + } + + +  +// Start of Question 1 methods + + + public static void question1_f() + { + for (int i = 0; i < 3; i++) + { + int total = i + i; + System.out.print(total); + } + } + // Above method prints ___________________? + + public static void question1_g() + { + int a = 1; + int b = 1; + int c = 1; + for (int i = 0; i < 2; i++) + { + System.out.print(c); + c = b; + b = a + b; + a = c; + } + } + // Above method prints ___________________? + + public static void question1_h() + { + int i = 2; + for (i = 0; i < 2; i++) + { + + } + + for (int j = 0; j < 2; j++) + { + System.out.print(i * j); + } + } + // Above method prints ___________________? + + +  +public static void question1_i() + { + int i = 0, j = 0; + int k = 1; + for (i = 0; i < 2; i++) + { + k = 2; + } + + for (j = 4; j < 2; j++) + { + k = 3; + } + + System.out.print(i); + System.out.print(j); + System.out.print(k); + } + // Above method prints ___________________? + + public static void question1_j() + { + int total = 5; + for (int i = 0; i < 2; i++) + { + total = total + 1; + } + + for (int j = 3; j >= 2; j--) + { + total--; + } + System.out.print(total); + } + // Above method prints ___________________? + + // End of Question 1 methods + + +  +// Start of Question 2 methods + + // Something wrong with following methods which we need to fix. + // Each method has only one syntax error to be fix. Can you find and fix those errors? + + + + public static void question2_f() + { + for (int i = 0; i < 3; i++) + { + int i = 5; + System.out.print(i);; + }; + } + + public static void question2_g() + { + for (int i = 0; i < 3; i++) + { + int total = total + i; + } + System.out.print(total); + } + + public static void question2_h() + { + for (int i = 0; i < 3; i++) + { + System.out.print(i); + } + + for (i = 0; i < 3; i++) + { + int total = i; + System.out.print(total); + } + } + + +  +public static void question2_i() + { + String s = "1"; + for (int i = 4; i > 2; i--) + { + s <= s + "1"; + } + System.out.print(s); + } + + public static void question2_j() + { + int i = 0, total = 0; + for (i = 0; i < 2; i++) + { + total = total + 1; + { + + System.out.print(total); + } + + // End of Question 2 + + + +  +// Start of Question 3 writing for loops + +3.a Write nested for loops to produce the following output: + +1 +22 +333 +4444 +55555 +666666 +7777777 + +3.b Write nested for loops to produce the following output: + + 1 + 22 + 333 + 4444 + 55555 + +3.c Write nested for loops to produce the following output: + +00112233445566778899 +00112233445566778899 +00112233445566778899 + + + + + +*/ diff --git a/Term1/_Class_Work/AutoBart.java b/Term1/_Class_Work/AutoBart.java new file mode 100644 index 0000000..ed2f112 --- /dev/null +++ b/Term1/_Class_Work/AutoBart.java @@ -0,0 +1,33 @@ +package _Class_Work; + +public class AutoBart { + + public static void main(String[] args) { + //writePunishment("I will use for-loops!", 18); + //writePunishment("I love Edhesive", 12); + //padString("hey", 6); + vertical("HEY NOW"); + + } + + public static void writePunishment(String message, int numOfTimes) { + for(int i = 1; i <= numOfTimes; i++) { + System.out.println(message); + } + } + + public static void padString(String message, int length) { + System.out.print(message); + int mLength = message.length(); + for(int i = mLength; i<=length; i++) { + System.out.print(" "); + } + } + + public static void vertical(String message) { + for(int i = 0; i < message.length(); i++) { + System.out.println(message.substring(i, i+1)); + } + } + +} diff --git a/Term1/_Class_Work/arrayFun.java b/Term1/_Class_Work/arrayFun.java new file mode 100644 index 0000000..acf3c68 --- /dev/null +++ b/Term1/_Class_Work/arrayFun.java @@ -0,0 +1,67 @@ +package _Class_Work; + +import java.util.*; + +public class arrayFun { + + public static void main(String[] args) { + //ARRAYS + int[] array1 = {7, 4, 10, 0, 1, 7, 6, 5, 3, 2, 9, 7}; + int[] array2 = {7, 4, 2, 7, 3, 4, 6, 7, 8, 9, 7, 0, 10, 7, 0, 1, 7, 6, 5, 7, 3, 2, 7, 9, 9, 8,7}; + + //SETTINGS: true = array1 false = array2 + boolean whichArrayToUse = false; + + //PRINT + System.out.println(Arrays.toString(whichArrayToUse ? array1 : array2)); + System.out.println(sum((whichArrayToUse ? array1 : array2), 3, 6)); //arrayName, startIndex, stopIndex + System.out.println(sum((whichArrayToUse ? array1 : array2), 2, 9)); //arrayName, startIndex, stopIndex + System.out.println(); + System.out.println(numCount((whichArrayToUse ? array1 : array2), 4)); //arrayName, numToLookFor + System.out.println(numCount((whichArrayToUse ? array1 : array2), 9)); //arrayName, numToLookFor + System.out.println(numCount((whichArrayToUse ? array1 : array2), 7)); //arrayName, numToLookFor + System.out.println(); + System.out.println(delete((whichArrayToUse ? array1 : array2), 7)); //arrayName, numToDelete + + } + public static String sum(int[] array, int start, int stop) { + int sum = 0; + for(int i = start; i < array.length || i < stop; i ++) { + sum+=array[i]; + } + String printHeader = "sum of spots " + start + "-" + stop + " = "; + return new String (printHeader + sum); + } + public static String numCount(int[] array, int num) { + int counter = 0; + for(int i = 0; i < array.length; i++) { + if(array[i] == num) { + counter++; + } + } + String printHeader = "# of " + num + "s = "; + return new String (printHeader + counter); + } + public static String delete(int[] array, int num) { + //This is the same code as numCount + int numOfNum = 0; + for(int i = 0; i < array.length; i++) { + if(array[i] == num) { + numOfNum++; + } + } + + + int[] newArray = new int [(array.length-numOfNum)]; + int newArrayIndex = 0; + for(int i = 0; i < array.length; i++) { + if(array[i] != num) { + newArray[newArrayIndex]=array[i]; + newArrayIndex++; + } + } + String printHeader = "new array with all " + num + "s removed = "; + return new String (printHeader + Arrays.toString(newArray)); + } + +} diff --git a/Term1/_Class_Work/arrayOdd.java b/Term1/_Class_Work/arrayOdd.java new file mode 100644 index 0000000..c5721ec --- /dev/null +++ b/Term1/_Class_Work/arrayOdd.java @@ -0,0 +1,91 @@ +package _Class_Work; + +import java.util.*; + +public class arrayOdd { + + public static void main(String[] args) { + int [] Array1 = {2, 4, 6, 8, 10, 12, 14}; + int [] Array2 = {2, 3, 4, 5, 6, 7, 8, 9}; + int [] Array3 = {2, 10, 20, 21, 23, 24, 40, 55, 60, 61}; + + boolean selected = false; + while(!selected) { + Scanner scan = new Scanner (System.in); + System.out.println("Would you like to scan an array or use one of the presets?"); + String answer = scan.next(); + int arrayNum = 0; + if(answer.equalsIgnoreCase("scan")) { + System.out.println("How many integers would you like to scan?"); + arrayNum = scan.nextInt(); + int[] scannedArray = new int [arrayNum]; + for(int i = 0; i < scannedArray.length; i++) { + System.out.println("Please enter an integer for index " + i); + String input = scan.next(); + if(input.toUpperCase().equals(input.toLowerCase())) { + int intInput = Integer.parseInt(input); + scannedArray[i] = intInput; + } + else { + System.out.println("that was not an integer"); + i--; + } + } + System.out.println(""); + sort(scannedArray, numOddEven(scannedArray)); + selected = true; + } + else if(answer.equalsIgnoreCase("preset")){ + sort(Array1, numOddEven(Array1)); + System.out.println(); + sort(Array2, numOddEven(Array2)); + System.out.println(); + sort(Array3, numOddEven(Array3)); + selected = true; + } + else { + System.out.println("please enter either either \"scan\" or \"preset\""); + selected = false; + } + } + } + public static int[] numOddEven(int[] array) { + int odd = 0; + int even = 0; + + for(int i = 0; i < array.length; i++) { + if(array[i]%2 == 0) { + even++; + } + else { + odd++; + } + } + int[] data = {even, odd}; + return data; + } + public static void sort(int[] array, int[] OddEven) { + int numOfEven = OddEven[0]; + int numOfOdd = OddEven[1]; + + int[] even = new int [numOfEven]; + int[] odd = new int [numOfOdd]; + + int indexEven = 0; + int indexOdd = 0; + + for(int i = 0; i < array.length; i++) { + if(array[i]%2 == 0) { + even[indexEven] = array[i]; + indexEven++; + } + else { + odd[indexOdd] = array[i]; + indexOdd++; + } + } + System.out.println("Odds = " + Arrays.toString(odd)); + System.out.println("Evens = " + Arrays.toString(even)); + } + +} diff --git a/Term1/_Class_Work/recursiveMethod.java b/Term1/_Class_Work/recursiveMethod.java new file mode 100644 index 0000000..6087280 --- /dev/null +++ b/Term1/_Class_Work/recursiveMethod.java @@ -0,0 +1,23 @@ +package _Class_Work; + +public class recursiveMethod { + + public static void main(String[] args) { + //printDecimal(1497); + recur1(6); + + } + public static void printDecimal(int n){ + if(n>=10) { + printDecimal(n/10); + } + System.out.println(n/10); + } + public static void recur1(int n) { + if(n>0) + recur1(n-2); + System.out.println(n + " "); + } + + +} diff --git a/Term2/Assignment/Boxcar.java b/Term2/Assignment/Boxcar.java new file mode 100644 index 0000000..3f9a73f --- /dev/null +++ b/Term2/Assignment/Boxcar.java @@ -0,0 +1,383 @@ +package Assignment; +/* + * AP CS MOOC + * Term 2 - Assignment 2, Part 1: Boxcar + * A class which represents a single car on a freight train. + */ + + + +/* +For this assignment, you will be writing a class called Boxcar that represents a single car on a freight train. Download the template file, Boxcar.java (Links to an external site.)Links to an external site., as a starting point. Your job is to add code to Boxcar.java so that your implementation meets the requirements specified below. To complete the assignment, replace all the/* missing code*\/ comments in the file with your own code. You do not need to change any other code in the file. + +In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named Boxcar. + +Boxcar.java includes a main method that will help test your code. In order to fully test the Boxcar class, you will need to add more test cases to the main method. At a minimum, run the main to make sure your implementation output matches the sample run listed below. We will test your code using our own main method that is similar to the one provided. + +When you are done coding and testing, copy and paste your entire Boxcar class (including the main method) into the Code Runner and press "Submit" in order for your assignment to count as turned in. + +Variables + +String cargo - Represents the type of cargo carried by the boxcar, with possible values of "gizmos", "gadgets", "widgets" and "wadgets". No other cargo types are allowed. +int numUnits - Represents the number of units carried by the boxcar. Must be between 0 and 10 inclusive. +boolean repair - Represents whether the boxcar is in repair or in service. Set to true if the boxcar is in repair. If the boxcar is in repair, numUnits must be 0. +Methods + +Boxcar() - Default constructor that sets the boxcar to “gizmos”, 5 units, and in service (not in repair). +Boxcar(String c, int u, boolean r) - This constructor sets the cargo variable to the parameter c, but only if c is "gizmos", "gadgets", "widgets", or "wadgets". The constructor ignores the case of the value in c. If c holds any value other than "gizmos", "gadgets", "widgets", or "wadgets", the constructor sets cargo to "gizmos". The numUnits variable is set to the parameter u. If u is less than 0 or higher than the maximum capacity of 10 units, numUnits is set to 0. The repair variable is set to the parameter r. If repair is true, numUnits is set to 0 no matter what value is stored in the u parameter. +String toString () - returns a String with the Boxcar in the format: +5 gizmos in service +10 widgets in service +0 gadgets in repair +Notice there is one space in between the number of units and the cargo and a tab between the value for cargo and "in repair"/"in service” + +void loadCargo() - This method adds 1 to the number of units in the BoxCar. The maximum capacity of a boxcar is 10 units. If increasing the number of units would go beyond the maximum, keep numUnits at the max capacity. If the repair variable is true, then numUnits may only be set to 0. +String getCargo() - This method returns the cargo type of the boxcar. +void setCargo(String c) - The cargo variable is set to c only if c is "gizmos", "gadgets", "widgets", or "wadgets", ignoring case. The value stored for cargo should be lowercase. If c holds any value other than "gizmos", "gadgets", "widgets", or "wadgets" (ignoring case), the method sets the cargo to "gizmos". +boolean isFull() - The isFull method returns true if numUnits is equal to 10, false otherwise. +void callForRepair() - Sets repair to true. Recall that if the repair variable is true, then the numUnits variable may only be set to 0. +Sample Run + +1. Test Boxcar() +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (5) +*** PASS: repair is set correctly (false) +*** PASS: toString produced the correct output (5 gizmos in service) + +2. Test Boxcar(String c, int u, boolean r) +*** PASS: cargo is set correctly (gadgets) +*** PASS: numUnits is set correctly (0) +*** PASS: repair is set correctly (true) +*** PASS: toString produced the correct output (0 gadgets in repair) + +3. Test callForRepair() +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (0) +*** PASS: repair is set correctly (true) +*** PASS: toString produced the correct output (0 gizmos in repair) + +4. Test loadCargo() +car3 holds 5 units. +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (5) +*** PASS: repair is set correctly (false) +*** PASS: toString produced the correct output (5 gizmos in service) +now car3 should hold 6 units. +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (6) +*** PASS: repair is set correctly (false) +*** PASS: toString produced the correct output (6 gizmos in service) +now car3 should hold 10 units. +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (10) +*** PASS: repair is set correctly (false) +*** PASS: toString produced the correct output (10 gizmos in service) +car1 is in repair, so we can't load cargo +*** PASS: cargo is set correctly (gizmos) +*** PASS: numUnits is set correctly (0) +*** PASS: repair is set correctly (true) +*** PASS: toString produced the correct output (0 gizmos in repair) + +5. Test isFull() +*** PASS: isFull() working properly +*** PASS: isFull() working properly + +6. Test getCargo() +*** PASS: getCargo() working properly + +7. Test setCargo(String) +*** PASS: cargo is set correctly (gadgets) +*** PASS: cargo is set correctly (widgets) +*** PASS: cargo is set correctly (wadgets) +*** PASS: cargo is set correctly (gizmos) +*/ + + + + + + + +public class Boxcar +{ + // Variables that will be initialized in the Boxcar constructors. + private String cargo = ""; //"gizmos", "gadgets", "widgets" and "wadgets". No other cargo types are allowed. + private int numUnits; //Must be between 0 and 10, inclusive + private boolean repair; //in repair/service? If true, numUnits must be 0 + + // Default constructor that sets the boxcar to "gizmos", 5, and false. + public Boxcar() + { + cargo = "gizmos"; + numUnits = 5; + repair = false; + } + + + // This constructor sets the cargo variable to the parameter c, but only if + // c is "gizmos", "gadgets", "widgets", or "wadgets". The constructor ignores + // the case of of the value in c. If c holds any value other than + // "gizmos", "gadgets", "widgets", or "wadgets", the constructor sets cargo + // to "gizmos". The numUnits variable is set to the parameter u. If u is less than + // 0 or higher than the maximum capacity of 10 units, numUnits is set to 0. The repair + // variable is set to the parameter r. If repair is true, numUnits is set to 0 + // no matter what value is stored in the u parameter. + public Boxcar(String c, int u, boolean r) + { + //cargo + this.setCargo(c); + //numUnits + if(u >= 0 && u <= 10) { + numUnits = u; + } + else { + numUnits = 0; + } + //repair + repair = r; + if(repair) { + numUnits = 0; + } + } + + // The toString method returns a String with the Boxcar in the format: + // 5 gizmos in service + // 10 widgets in service + // 0 gadgets in repair + // + // Notice there is one space in between the number of units and the cargo + // and a tab between the value for cargo and "in repair"/"in service" + public String toString() + { + String print = numUnits + " " + cargo; + if(repair) { + print += "\tin repair"; + } + else { + print += "\tin service"; + } + return print; + } + + // This method adds 1 to the number of units in the BoxCar. The maximum + // capacity of a boxcar is 10 units. If increasing the number of units + // would go beyond the maximum, keep numUnits at the max capacity. + // If the repair variable is true, then numUnits may only be set to 0. + public void loadCargo() { + if(numUnits < 10) { + numUnits++; + } + if(repair) { + numUnits = 0; + } + } + + // The getCargo method returns the cargo of the boxcar. + public String getCargo() + { + return cargo; + } + + // The setCargo method sets the cargo type of the boxcar. The cargo variable is + // set to c only if c is "gizmos", "gadgets", "widgets", or "wadgets". + // The method ignores the case of of the value in c. If c holds any value other than + // "gizmos", "gadgets", "widgets", or "wadgets" (ignoring case), the method sets cargo + // to "gizmos". + public void setCargo(String c) + { + if(c.equalsIgnoreCase("gizmos") || + c.equalsIgnoreCase("gadgets") || + c.equalsIgnoreCase("widgets") || + c.equalsIgnoreCase("wadgets")) + { + cargo = c.toLowerCase(); + } + else { + cargo = "gizmos"; + } + } + + // The isFull method returns true if numUnits is equal to 10, false otherwise. + public boolean isFull() + { + if(numUnits == 10) { + return true; + } + return false; + } + + // The callForRepair method sets the variable repair to true, and numUnits to 0. + public void callForRepair() + { + repair = true; + numUnits = 0; + } + + public static void main(String[] args) + { + + /* The main method allows you to run Boxcar on its own, with a built-in tester. */ + + //************************************************************************* + // 1. Test Boxcar() + //************************************************************************* + Boxcar car1 = new Boxcar(); + System.out.println("1. Test Boxcar()"); + testBoxcar(car1, "gizmos", 5, false, "5 gizmos\tin service"); + + //************************************************************************* + // 2. Test Boxcar(String c, int u, boolean r) + //************************************************************************* + System.out.println("\n2. Test Boxcar(String c, int u, boolean r)"); + Boxcar car2 = new Boxcar("GadgetS", 7, true); + // Notice that since the boxcar is in repair, the value of numUnits + // gets set to 0. Also, the cargo should get saved in all lower case + // as "gadgets", not "GadgetS". + testBoxcar(car2, "gadgets", 0, true, "0 gadgets\tin repair"); + + //************************************************************************* + // 3. Test callForRepair() + //************************************************************************* + System.out.println("\n3. Test callForRepair()"); + // car1 is not burnt out. Lets call callForRepair on car1 and make sure it + // gets marked for repair and set to 0 units. + car1.callForRepair(); + testBoxcar(car1, "gizmos", 0, true, "0 gizmos\tin repair"); + + //************************************************************************* + // 4. Test loadCargo() + //************************************************************************* + System.out.println("\n4. Test loadCargo()"); + Boxcar car3 = new Boxcar(); + // car3 holds 2 gizmos. Let's load some more cargo. + System.out.println("car3 holds 5 units."); + testBoxcar(car3, "gizmos", 5, false, "5 gizmos\tin service"); + car3.loadCargo(); + System.out.println("now car3 should hold 6 units."); + testBoxcar(car3, "gizmos", 6, false, "6 gizmos\tin service"); + car3.loadCargo(); + car3.loadCargo(); + car3.loadCargo(); + car3.loadCargo(); + car3.loadCargo(); + System.out.println("now car3 should hold 10 units."); + testBoxcar(car3, "gizmos", 10, false, "10 gizmos\tin service"); + // Try to load cargo into car1 on - this should fail since it is in repair. + System.out.println("car1 is in repair, so we can't load cargo"); + car1.loadCargo(); + testBoxcar(car1, "gizmos", 0, true, "0 gizmos\tin repair"); + + //************************************************************************* + // 5. Test isFull() + //************************************************************************* + System.out.println("\n5. Test isFull()"); + // We know car1 is empty, and car3 is full. Verify that the method isFull reports this correctly. + if (!car1.isFull()) + { + System.out.println("*** PASS: isFull() working properly"); + } + else + { + System.out.println("*** FAIL: isFull() not working properly"); + } + if (car3.isFull()) + { + System.out.println("*** PASS: isFull() working properly"); + } + else + { + System.out.println("*** FAIL: isFull() not working properly"); + } + + //************************************************************************* + // 6. Test getCargo() + //************************************************************************* + System.out.println("\n6. Test getCargo()"); + if (car2.getCargo().equals("gadgets")) + { + System.out.println("*** PASS: getCargo() working properly"); + } + else + { + System.out.println("*** FAIL: problem with getCargo()"); + } + + //************************************************************************* + // 7. Test setCargo(String) + //************************************************************************* + System.out.println("\n7. Test setCargo(String)"); + car1.setCargo("gadgets"); + System.out.println("*** " + testBoxcarCargo(car1, "gadgets")); + car1.setCargo("WIDGETS"); // should set cargo to widgets + System.out.println("*** " + testBoxcarCargo(car1, "widgets")); + car1.setCargo("wAdgEts"); // should set cargo to wadgets + System.out.println("*** " + testBoxcarCargo(car1, "wadgets")); + car1.setCargo("onions"); // onions is not allowed, should set cargo to gizmos. + System.out.println("*** " + testBoxcarCargo(car1, "gizmos")); + } + + // Private helper methods + + private static void testBoxcar(Boxcar car, String c, int u, boolean r, + String string) + { + System.out.println("*** " + testBoxcarCargo(car, c)); + System.out.println("*** " + testBoxcarUnits(car, u)); + System.out.println("*** " + testBoxcarRepair(car, r)); + System.out.println("*** " + testBoxcarToString(car, string)); + } + + private static String testBoxcarUnits(Boxcar car, int u) + { + if (car.numUnits != u) + { + return "FAIL: numUnits is not set correctly. numUnits should be set to " + + u + ", but it is set to " + car.numUnits + "."; + } + else + { + return "PASS: numUnits is set correctly (" + car.numUnits + ")"; + } + } + + private static String testBoxcarRepair(Boxcar car, boolean r) + { + if ((car.repair && !r) || (!car.repair && r)) + { + return "FAIL: repair is not set correctly (repair should be set to " + + r + ", but it is set to " + car.repair + ")"; + } + else + { + return "PASS: repair is set correctly (" + car.repair + ")"; + } + } + + private static String testBoxcarCargo(Boxcar car, String c) + { + if (!car.cargo.equals(c)) + { + return "FAIL: cargo is not set correctly (cargo should be set to " + + c + ", but it is set to " + car.cargo + ")"; + } + else + { + return "PASS: cargo is set correctly (" + car.cargo + ")"; + } + } + + private static String testBoxcarToString(Boxcar car, String string) + { + String output; + + if (car.toString().equals(string)) + { + output = "PASS: toString produced the correct output"; + } + else + { + output = "FAIL: toString does not work as expected"; + } + return output + " (" + car.toString() + ")"; + } +} \ No newline at end of file diff --git a/Term2/Assignment/FreightTrain.java b/Term2/Assignment/FreightTrain.java new file mode 100644 index 0000000..a1902bd --- /dev/null +++ b/Term2/Assignment/FreightTrain.java @@ -0,0 +1,287 @@ +package Assignment; +/* + * AP CS MOOC + * Term 2 - Assignment 2, Part 2: FreightTrain + * A class which represents a freight train with multiple boxcars. + */ + + +/* +For this assignment, you will be writing a class called FreightTrain that represents a train containing multiple cargo-carrying boxcars. The boxcars in the train are instances of the Boxcar class that you created in Assignment 2: Part 1 - Boxcar. To get started, download the template file FreightTrain.java (Links to an external site.)Links to an external site. into the same folder that holds your Boxcar.java code from Assignment 2: Part 1 - Boxcar. The FreightTrain class needs the Boxcar class to work properly. + +As in Part 1 of this assignment, your job is to add code to FreightTrain.java so that your implementation meets the requirements specified below. To complete the assignment, replace all the /* missing code *\/ comments in the file with your own code. You do not need to change any other code in the file. + +In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named FreightTrain. + +When you are done coding and testing, copy and paste your entire FreightTrain class (including the main method) into the Code Runner and press "Submit" in order for your assignment to count as turned in. Do not resubmit your Boxcar class. We will test your FreightTrain class with our own version of the Boxcar class. + +Variables + +ArrayList train - An ArrayList that stores a train with boxcars. +Methods + +FreightTrain() - Default constructor that sets train to an ArrayList holding one boxcar containing 5 gizmos, that is not in repair. +FreightTrain(int n) - A constructor that sets train to an ArrayList of size n, holding n boxcars each containing 5 gizmos and not in repair. If n ≤ 0, then the train should be set to size one, with a single boxcar holding 5 gizmos and not in repair. +String toString() - This method returns a String representation of the Boxcar objects in the train, one per line. For example: +3 gadgets in service +2 wadgets in service +0 gizmos in repair +7 gadgets in service +0 gadgets in repair +void setCargo(String c) - This method sets the cargo type of all the boxcars in the entire train. The cargo variable is set to c only if c is "gizmos", "gadgets", “widgets�, or “wadgets�. It should ignore the case of the value in c. If c holds any value other than "gizmos", "gadgets", “widgets�, or “wadgets�, cargo will be set to "gizmos". +void setMultiCargo() - This method sets the boxcars to the alternating pattern "gizmos", "gadgets", "widgets", "wadgets", "gizmos", "gadgets", "widgets", "wadgets", ... until the end of the train. +void fillTrain() - This method fills all boxcars in the train to the maximum capacity of 10. +void callForRepair(int i) - This method sets the repair variable of the Boxcar at location i to true. +Sample run + +1. Test the default constructor FreightTrain() +*** PASS: FreightTrain() creates a list of size 1 + +2. Test the constructor FreightTrain(n) +*** PASS: FreightTrain(0) creates a list of size 1 +*** PASS: FreightTrain(-7) creates a list of size 1 +*** PASS: FreightTrain(5) creates a list of size 5 +*** PASS: FreightTrain(5) initialized boxcars correctly + +3. Test setCargo(String) +*** PASS: setCargo worked as expected (gadget test) +*** PASS: setCargo worked as expected (onions test) + +5. Test fillTrain() +*** PASS: fillTrain() worked as expected + +6. Test callForRepair(n) +*** PASS: callForRepair(1) works as expected. + */ +import java.util.ArrayList; + +public class FreightTrain +{ + // An ArrayList that stores a train with multiple boxcars + private ArrayList train = new ArrayList(); + + // Default constructor that sets train to an ArrayList holding one + // boxcar containing 5 gizmos, that is not in repair. + public FreightTrain() + { + train.add(new Boxcar()); + } + + // A constructor that sets train to an ArrayList of size n, holding + // n boxcars, that are all hold 5 gizmos and are not in repair. If n <= 0, + // then the train should be set to size one, with a single boxcar containing + // 5 gizmos and not in repair. + public FreightTrain(int n) + { + if(n <= 0) { + train.add(new Boxcar()); + } + else { + for(int i = 1; i <= n; i++) { + train.add(new Boxcar()); + } + } + } + + // This method returns a String representation of the + // Boxcar objects in the ArrayList, one per line. For example, + // here is the String returned when toString is called on a + // FreightTrain with 5 boxcars: + // + // 3 gadgets in service + // 2 wadgets in service + // 0 gizmos in repair + // 7 gadgets in service + // 0 gadgets in repair + // + // Note: there is one space between the number of units and + // the cargo type, and a tab between the cargo type and + // "in repair"/"in service". + public String toString() + { + String print = ""; + int total = train.size(); + int counter = 1; + for(Boxcar b: train) { + if(counter < total) { + print += b.toString() + "\n"; + } + else { + print += b.toString(); + } + } + return print; + } + + // This method sets the cargo type of all the boxcars in the entire train. + public void setCargo(String c) + { + for(Boxcar b: train) { + b.setCargo(c); + } + } + + // This method sets the boxcars to the pattern "gizmos", "gadgets", "widgets", + // "wadgets", "gizmos", "gadgets", "widgets", "wadgets", ... + // until the end of the train. + public void setMultiCargo() + { + String[] cargoTypes = {"gizmos", "gadgets", "widgets", "wadgets"}; + int pos = 0; + for(Boxcar b: train) { + b.setCargo(cargoTypes[pos]); + if(pos < 3) { + pos++; + } + else { + pos = 0; + } + } + } + + // This method fills every boxcar in the train to max capacity of 10. + // Each individual boxcar can only hold cargo if its + // repair variable is false. + public void fillTrain() + { + for(Boxcar b:train) { + boolean isRepair = true; + int textPos = b.toString().indexOf("\t")+1; + if(b.toString().substring(textPos).equals("in service")) { + isRepair = false; + } + if(!isRepair) { + while(!b.isFull()) { + b.loadCargo(); + } + } + } + } + + // This method sets the Boxcar at location i’s repair variable to true. + public void callForRepair(int i) + { + train.get(i).callForRepair(); + } + + public static void main(String[] args) + { + // ************************************************************************* + // 1. Test FreightTrain() + // ************************************************************************* + System.out.println("1. Test the default constructor FreightTrain()"); + FreightTrain train1 = new FreightTrain(); + if (train1.train.size() == 1) + System.out.println("*** PASS: FreightTrain() creates a list of size 1"); + else + System.out.println("*** FAIL: FreightTrain() creates a list of size " + + train1.train.size() + + ", when a list of size 1 is expected."); + + // *********************************** + // 2. Test FreightTrain(n) + // *********************************** + System.out.println("\n2. Test the constructor FreightTrain(n)"); + // Try to create a train with 0 boxcars + FreightTrain emptyTrain = new FreightTrain(0); + if (emptyTrain.train.size() == 1) + System.out.println("*** PASS: FreightTrain(0) creates a list of size 1"); + else + System.out.println("*** FAIL: FreightTrain(0) creates a list of size " + + emptyTrain.train.size() + + ", when a list of size 1 is expected."); + // Try to create a train of boxcars with a negative number + FreightTrain negativeTrain = new FreightTrain(-7); + if (negativeTrain.train.size() == 1) + System.out.println("*** PASS: FreightTrain(-7) creates a list of size 1"); + else + System.out.println("*** FAIL: FreightTrain(-7) creates a list of size " + + negativeTrain.train.size() + + ", when a list of size 1 is expected."); + // Try to create a train with a positive number of boxcars + FreightTrain trainWithFiveCars = new FreightTrain(5); + if (trainWithFiveCars.train.size() == 5) + System.out.println("*** PASS: FreightTrain(5) creates a list of size 5"); + else + System.out.println("*** FAIL: FreightTrain(5) creates a list of size " + + trainWithFiveCars.train.size() + + ", when a list of size 5 is expected."); + // Verify that all the boxcars are initialized properly + boolean success = true; + for (Boxcar car: trainWithFiveCars.train) + { + if (!car.getCargo().equals("gizmos")) + { + success = false; + } + } + if (trainWithFiveCars.train.size() > 0 && success) + { + System.out.println("*** PASS: FreightTrain(5) initialized boxcars correctly"); + } + else + { + System.out.println("*** FAIL: FreightTrain(5) did not initialize boxcars correctly"); + } + + + // *********************************** + // 3. Test setCargo(String) + // *********************************** + System.out.println("\n3. Test setCargo(String)"); + // All of the cars in our trainWithFiveCars carry gizmos. + // Change that to gadgets. + trainWithFiveCars.setCargo("gadgets"); + success = true; + for (Boxcar car: trainWithFiveCars.train) + { + if (!car.getCargo().equals("gadgets")) //FIXME: TYPO, was "gadget" + success = false; + } + if (trainWithFiveCars.train.size() > 0 && success) + System.out.println("*** PASS: setCargo worked as expected (gadget test)"); + else + System.out.println("*** FAIL: setCargo did not work as expected (gadget test)"); + // Now try to set them to a cargo type that is not supported. + // This should cause all the cars to be set back to gizmos. + trainWithFiveCars.setCargo("onions"); + success = true; + for (Boxcar car: trainWithFiveCars.train) + { + if (!car.getCargo().equals("gizmos")) + success = false; + } + if (trainWithFiveCars.train.size() > 0 && success) + System.out.println("*** PASS: setCargo worked as expected (onions test)"); + else + System.out.println("*** FAIL: setCargo did not work as expected (onions test)"); + + // *********************************** + // 4. Test fillTrain() + // *********************************** + System.out.println("\n5. Test fillTrain()"); + train1.fillTrain(); + if (train1.train.size() > 0 && train1.train.get(0).isFull()) + { + System.out.println("*** PASS: fillTrain() worked as expected"); + } + else + { + System.out.println("*** FAIL: fillTrain() did not work as expected"); + } + + // *********************************** + // 5. Test callForRepair(int) + // *********************************** + System.out.println("\n6. Test callForRepair(n)"); + train1.callForRepair(0); + if (train1.toString().equals("0 gizmos\tin repair")) + { + System.out.println("*** PASS: callForRepair(1) works as expected."); + } + else + { + System.out.println("*** FAIL: callForRepair(1) does not work as expected."); + } + } +} diff --git a/Term2/Assignment/GameWheel5/GameWheel.java b/Term2/Assignment/GameWheel5/GameWheel.java new file mode 100644 index 0000000..d9f8f21 --- /dev/null +++ b/Term2/Assignment/GameWheel5/GameWheel.java @@ -0,0 +1,74 @@ +package Assignment.GameWheel5; + +import java.util.*; +import java.lang.*; + +public class GameWheel { + private ArrayList prizeCards; + private int currentPos; + + public GameWheel() { + prizeCards = new ArrayList(); + currentPos = 0; + prizeCards = initGameWheel(); + prizeCards = scramble(); + } + + public ArrayList initGameWheel() { + ArrayList init = new ArrayList(); + for (int i=1; i <= 40; i++) { + if (i%2 == 1) + init.add(new PrizeCard(i, "red", i*10)); + else if (i%10 == 0) + init.add(new PrizeCard(i, "black", i*200)); + else + init.add(new PrizeCard(i, "blue", i*100)); + } + return init; + } + + public ArrayList getPrizeCards() { + return prizeCards; + } + + public ArrayList scramble() { + // This method will scramble the ordering of the Prize Cards in the Game Wheel. Be careful, because + // the pattern of the coloring must be maintained (i.e. the first Prize Card should still be a card + // that is red, but likely a different ID number and prize amount, the second Prize Card should + // still be a card that is blue, the tenth Prize Card should still be black). In other words, once + // a color is assigned to a Prize Card, it does not change; when the wheel is scrambled, it is only + // putting cards that are already red in the places where red cards belong (odd numbered places), + // black cards where black cards belong (multiples of 10), and blue cards where blue cards belong + // (even numberedplaces). + + ArrayList old = this.getPrizeCards(); + ArrayList scrambled = new ArrayList(); + for(int index = 1; index <= old.size(); index++) { + int length = old.size(); + while(true) { + int oldIndex = (int) (Math.random() * length); + PrizeCard card = old.get(oldIndex); + + String targetColor = index%2 == 1 ? "red" : (index%10 == 0 ? "black" : "blue"); + String currentColor = card.getID()%2 == 1 ? "red" : (card.getID()%10 == 0 ? "black" : "blue"); + + if(targetColor.equals(currentColor)) { + old.remove(index); + scrambled.add(card); + break; + } + } + } + return scrambled; + } + + public PrizeCard spinWheel() { + //spin power between range of 1-100 (inclusive) + int power = (int)(Math.random()*100 + 1); + int newPos = (currentPos + power) % prizeCards.size(); + currentPos = newPos; + return prizeCards.get(currentPos); + } + + +} diff --git a/Term2/Assignment/GameWheel5/Main.java b/Term2/Assignment/GameWheel5/Main.java new file mode 100644 index 0000000..5b480f7 --- /dev/null +++ b/Term2/Assignment/GameWheel5/Main.java @@ -0,0 +1,150 @@ +package Assignment.GameWheel5; + +import java.util.*; + +/* +For this assignment, you will simulate spinning a Game Wheel with 40 designated spots, each marked with an ID number, color, and cash prize amount. To help envision this Game Wheel, imagine a circular pie, with 40 evenly cut “slices”. Each “slice” is called a Prize Card (for the purposes of this assignment), and contains an ID number, color, and cash prize amount. + +Click here (Links to an external site.)Links to an external site. to download the starter files for this assignment. The Java class PrizeCard has been completed and provided to you. You do not need to modify PrizeCard.java. + +Class GameWheel + +The first class you will be working on is GameWheel. To help represent this wheel, an ArrayList of PrizeCard objects will be used in the GameWheel class. When initialized, the first PrizeCard in the ArrayList will have an ID #1, the second will have ID #2, and so on. A Prize Card with an odd ID # will be the color red, and a Prize Card with an even ID # will be the color blue, except if the ID # is a multiple of 10, in which case it will be the color black. + +Please download the starting template, GameWheel.java. You will need to implement the following method: + +public ArrayList scramble() - This method will scramble the ordering of the Prize Cards in the Game Wheel. Be careful, because the pattern of the coloring must be maintained (i.e. the “first” Prize Card should still be a card that is red, but likely a different ID number and prize amount, the “second” Prize Card should still be a card that is blue, the “tenth” Prize Card should still be black). In other words, once a color is assigned to a Prize Card, it does not change; when the wheel is scrambled, it is only putting cards that are already red in the places where red cards belong (odd numbered places), black cards where black cards belong (multiples of 10), and blue cards where blue cards belong (even numbered places). +For a simplified example, let’s think about the Prize Cards by just their ID numbers. Let’s say we have a Game Wheel with 10 Prize Cards, initially in the order [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. After calling scramble(), the order could possibly now be [7, 4, 3, 6, 9, 2, 5, 8, 1, 10]. Notice the pattern is still red (odd ID), blue (even ID), red, blue, red, blue, red, blue, red, black (ID is multiple of 10). + +Please refer to the specification above for how the colors were determined. (Hint: Remember that the coloring is determined by some specific characteristic of the Prize Card ID. Also, don’t be afraid to create “temporary” ArrayLists to help complete the work.) The newly scrambled wheel should then be returned. + +Class Main + +The second class you will be working on will be the Main class. Main should have a main method. Here, you will utilize the PrizeCard and GameWheel classes to simulate two players who will spin the wheel. The first player will get to spin 5 consecutive times. Then the second player will get to spin 5 consecutive times. + +If either player’s spin results in a Prize Card they have already landed on, the player will ignore that spin and spin again. Thus, when a player is done spinning, the player should have 5 unique prize cards. + +In order to simulate a spin of the wheel, use GameWheel’s method spinWheel() which is already implemented for you. The method spinWheel() will return a PrizeCard object, the PrizeCard that the spin landed on. + +At the end the total cash prize amount for the first player should be calculated then printed out. Following the total amount, the Prize Cards that the player’s spins landed on should also be printed out using PrizeCard’s toString() method. For example, in the Sample Run below, Player 1’s five spins landed on Prize Cards with ID # 21, 4, 6, 11, 27. + +The same should then be done for the second player. + +At the very end, the players’ total cash prize amounts should be compared to one another, and a statement should be printed out indicating which player won more money, as well as how much more money that player won by. If the result is a tie, the output should simply say "It’s a tie!" + +Final Notes + +Remember, all variables should have an access level of private and all required methods should have an access level of public. + +There is no Student Runner File for this assignment. To test your code, run the Main.java file in DrJava and verify that the class output matches the Sample Run pattern that follows. Since the assignment involves an element of randomized results, your own results will vary from the sample run. However, note that neither player has a repeated spin result. We will use our own runner to grade the program. + +When you are ready, follow the links below to submit your entire GameWheel and Main classes separately. You must submit both, and you must paste your entire class into the appropriate boxes (including all methods that were implemented for you). Each class is worth 5 points, out of a total of 10. + +Sample run #1 of Main.java: + +Player 1 Total: $1590 +ID: 21, Color: red, Prize Amount: $210 +ID: 4, Color: blue, Prize Amount: $400 +ID: 6, Color: blue, Prize Amount: $600 +ID: 11, Color: red, Prize Amount: $110 +ID: 27, Color: red, Prize Amount: $270 + +Player 2 Total: $9390 +ID: 19, Color: red, Prize Amount: $190 +ID: 34, Color: blue, Prize Amount: $3400 +ID: 18, Color: blue, Prize Amount: $1800 +ID: 12, Color: blue, Prize Amount: $1200 +ID: 28, Color: blue, Prize Amount: $2800 + +Player 2 won by $7800! + Sample run #2 of Main.java: + +Player 1 Total: $7170 +ID: 20, Color: black, Prize Amount: $4000 +ID: 26, Color: blue, Prize Amount: $2600 +ID: 37, Color: red, Prize Amount: $370 +ID: 15, Color: red, Prize Amount: $150 +ID: 5, Color: red, Prize Amount: $50 + +Player 2 Total: $1340 +ID: 29, Color: red, Prize Amount: $290 +ID: 23, Color: red, Prize Amount: $230 +ID: 3, Color: red, Prize Amount: $30 +ID: 39, Color: red, Prize Amount: $390 +ID: 4, Color: blue, Prize Amount: $400 + +Player 1 won by $5830! +Submit your GameWheel using the following link. +NOTE: You MUST use the class name "GameWheel" for this submission. + +Assignment 5: Game Wheel - GameWheel Class Submission + +Submit your Main class using the following link. +NOTE: You MUST use the class name "Main" for this submission. + +Assignment 5: Game Wheel - Main Class Submission + */ + +public class Main { + static GameWheel gw = new GameWheel(); + static ArrayList playerOne = new ArrayList(); + static ArrayList playerTwo = new ArrayList(); + + public static void main (String[] args) { + //player one + for(int i = 1; i <= 5; i++) { + PrizeCard spunCard = gw.spinWheel(); + if(check(playerOne, spunCard)) { + playerOne.add(spunCard); + } else { + i--; + } + } + //player two + for(int i = 1; i <= 5; i++) { + PrizeCard spunCard = gw.spinWheel(); + if(check(playerTwo, spunCard)) { + playerTwo.add(spunCard); + } else { + i--; + } + } + + int oneTotal = 0; + int twoTotal = 0; + for(PrizeCard card : playerOne) { + oneTotal += card.getPrizeAmount(); + } + for(PrizeCard card : playerTwo) { + twoTotal += card.getPrizeAmount(); + } + + //print + System.out.println("Player 1 Total: $" + oneTotal); + for(PrizeCard card : playerOne) { + System.out.println(card.toString()); + } + System.out.println(); + System.out.println("Player 2 Total: $" + twoTotal); + for(PrizeCard card : playerTwo) { + System.out.println(card.toString()); + } + System.out.println("\n" + (oneTotal>twoTotal ? "Player 1 won by $" + (oneTotal-twoTotal) + "!" : "Player 2 won by $" + (twoTotal-oneTotal) + "!")); + } + + /** + * checks if card is already in arr + * returns false if already in + * @param arr arr to be checked from + * @param card card to check with + * @return + */ + public static boolean check(ArrayList arr, PrizeCard card) { + for(int i = 0; i < arr.size(); i++) { + if(arr.get(i).equals(card)) { + return false; + } + } + return true; + } +} diff --git a/Term2/Assignment/GameWheel5/PrizeCard.java b/Term2/Assignment/GameWheel5/PrizeCard.java new file mode 100644 index 0000000..20b985f --- /dev/null +++ b/Term2/Assignment/GameWheel5/PrizeCard.java @@ -0,0 +1,33 @@ +package Assignment.GameWheel5; + +public class PrizeCard { + private int id; + private String color; + private int prizeAmount; + + public PrizeCard() { + id = 0; + color = "red"; + prizeAmount = 0; + } + + public PrizeCard(int nID, String nColor, int nPrizeAmount) { + id = nID; + color = nColor; + prizeAmount = nPrizeAmount; + } + + public int getID() { + return id; + } + + public int getPrizeAmount() { + return prizeAmount; + } + + public String toString() { + return "ID: " + id + + ", Color: " + color + + ", Prize Amount: $" + prizeAmount; + } +} \ No newline at end of file diff --git a/Term2/Labs/Magpie1/Activity_2/Magpie2.java b/Term2/Labs/Magpie1/Activity_2/Magpie2.java new file mode 100644 index 0000000..4d30edb --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_2/Magpie2.java @@ -0,0 +1,146 @@ +package Labs.Magpie1.Activity_2; + +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * A program to carry on conversations with a human user. + * This is the initial version that: + *
  • + * Uses indexOf to find strings + *
  • + * Handles responding to simple words and phrases + *
+ * This version uses a nested if to handle default responses. + * @author Laurie White + * @version April 2012 + */ +public class Magpie2 +{ + /** + * Get a default greeting + * @return a greeting + */ + public String getGreeting() + { + return "Hello, let's talk."; + } + + /** + * Gives a response to a user statement + * + * @param statement + * the user statement + * @return a response based on the rules given + */ + public String getResponse(String statement) + { + if(statement.trim().length() != 0) { + String response = ""; + if (statement.indexOf("no") >= 0) + { + response = "Why so negative?"; + } + else if (statement.indexOf("mother") >= 0 + || statement.indexOf("father") >= 0 + || statement.indexOf("sister") >= 0 + || statement.indexOf("brother") >= 0) + { + response = "Tell me more about your family."; + } + else if(statement.toUpperCase().contains("DOG")||statement.toUpperCase().contains("CAT")) { + response = "Tell me more about your pets."; + } + else if(checkTeacher(statement).get(0).equals("t")){ + response = checkTeacher(statement).get(1); + } + else if(statement.contains("you") && statement.contains("?")) { + response = "I don't know."; + } + else if(statement.contains("the time") && statement.contains("?")){ + response = "The time is " + new SimpleDateFormat("HH:mm:ss").format(new Date()); + } + else if((statement.contains("follow") || statement.contains("add")) && + (statement.contains("social media") || statement.contains("instagram") || statement.contains("facebook") || statement.contains("snapchat") || statement.contains("twitter"))) { + response = "Sorry, I don't have any social medias"; + } + else + { + response = getRandomResponse(); + } + return response; + } + return "Say something, please"; + } + + /** + * Pick a default response to use if nothing else fits. + * @return a non-committal string + */ + private String getRandomResponse() + { + final int NUMBER_OF_RESPONSES = 6; + double r = Math.random(); + int whichResponse = (int)(r * NUMBER_OF_RESPONSES); + String response = ""; + + if (whichResponse == 0) + { + response = "Interesting, tell me more."; + } + else if (whichResponse == 1) + { + response = "Hmmm."; + } + else if (whichResponse == 2) + { + response = "Do you really think so?"; + } + else if (whichResponse == 3) + { + response = "You don't say."; + } + else if (whichResponse == 4) { + response = "and?..."; + } + else if(whichResponse == 5) { + response = "Never knew."; + } + + return response; + } + + /** + * Checks if a String contains a teacher's name + * @param statement + * @return an ArrayList {"f" for false or "t" for true, response} + */ + private static ArrayList checkTeacher(String statement) { + //TODO: fix input: "she she she", output: She sounds like a good teacher." + final String[] namePronouns = {"Mr", "Ms", "Mrs", "Miss", "Dr", "Professor"}; + final String[] genderPronouns = {"He", "She", "She", "She", "They", "They"}; + //boolean[] keepChecking = {true, true, true, true, true, true}; + String contains = "f"; //false + String response = null; + for(int i = 0; i < namePronouns.length; i++) { + if(statement.toUpperCase().contains(namePronouns[i].toUpperCase())) { + if(response == null) { + contains = "t"; //true + response = genderPronouns[i] + " sounds like a good teacher."; + + } + else if(response.contains("Both")) { + response = "They all sound like good teachers."; + break; + } + else{ + response = "Both of them sound like good teachers."; + } + } + } + ArrayList list = new ArrayList(); + list.add(contains); + list.add(response); + return list; + } +} diff --git a/Term2/Labs/Magpie1/Activity_2/MagpieRunner2.java b/Term2/Labs/Magpie1/Activity_2/MagpieRunner2.java new file mode 100644 index 0000000..6614425 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_2/MagpieRunner2.java @@ -0,0 +1,30 @@ +package Labs.Magpie1.Activity_2; +import java.util.Scanner; + +/** + * A simple class to run the Magpie class. + * @author Laurie White + * @version April 2012 + */ +public class MagpieRunner2 +{ + + /** + * Create a Magpie, give it user input, and print its replies. + */ + public static void main(String[] args) + { + Magpie2 maggie = new Magpie2(); + + System.out.println (maggie.getGreeting()); + Scanner in = new Scanner (System.in); + String statement = in.nextLine(); + + while (!statement.equals("Bye")) + { + System.out.println (maggie.getResponse(statement)); + statement = in.nextLine(); + } + } + +} diff --git a/Term2/Labs/Magpie1/Activity_3/Magpie3.java b/Term2/Labs/Magpie1/Activity_3/Magpie3.java new file mode 100644 index 0000000..e811fd7 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/Magpie3.java @@ -0,0 +1,231 @@ +package Labs.Magpie1.Activity_3; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +/** + * A program to carry on conversations with a human user. + * This version: + *
  • + * Uses advanced search for keywords + *
+ * + * @author Laurie White + * @version April 2012 + */ +public class Magpie3 +{ + /** + * Get a default greeting + * + * @return a greeting + */ + public String getGreeting() + { + return "Hello, let's talk."; + } + + /** + * Gives a response to a user statement + * + * @param statement + * the user statement + * @return a response based on the rules given + */ + public String getResponse(String statement) + { + String response = ""; + if (statement.length() == 0) + { + response = "Say something, please."; + } + else if (findKeyword(statement, "no") >= 0) + { + response = "Why so negative?"; + } + else if (findKeyword(statement, "mother") >= 0 + || findKeyword(statement, "father") >= 0 + || findKeyword(statement, "sister") >= 0 + || findKeyword(statement, "brother") >= 0) + { + response = "Tell me more about your family."; + } + else if(checkTeacher(statement).get(0).equals("t")){ + response = checkTeacher(statement).get(1); + } + else if(findKeyword(statement, "you")>=0 && findKeyword(statement, "?")>=0) { + response = "I don't know."; + } + else if(findKeyword(statement, "the time")>=0 && findKeyword(statement, "?")>=0){ + response = "The time is " + new SimpleDateFormat("HH:mm:ss").format(new Date()); + } + else if((findKeyword(statement, "follow")>=0 || findKeyword(statement, "add")>=0) && + (statement.contains("social media") || statement.contains("instagram") || statement.contains("facebook") || statement.contains("snapchat") || statement.contains("twitter"))) { + response = "Sorry, I don't have any social medias"; + } + else + { + response = getRandomResponse(); + } + return response; + } + + /** + * Search for one word in phrase. The search is not case + * sensitive. This method will check that the given goal + * is not a substring of a longer string (so, for + * example, "I know" does not contain "no"). + * + * @param statement + * the string to search + * @param goal + * the string to search for + * @param startPos + * the character of the string to begin the + * search at + * @return the index of the first occurrence of goal in + * statement or -1 if it's not found + */ + public int findKeyword(String statement, String goal, + int startPos) + { + String phrase = statement.trim(); + // The only change to incorporate the startPos is in + // the line below + int psn = phrase.toLowerCase().indexOf( + goal.toLowerCase(), startPos); + + // Refinement--make sure the goal isn't part of a + // word + while (psn >= 0) + { + // Find the string of length 1 before and after + // the word + String before = " ", after = " "; + if (psn > 0) + { + before = phrase.substring(psn - 1, psn) + .toLowerCase(); + } + if (psn + goal.length() < phrase.length()) + { + after = phrase.substring( + psn + goal.length(), + psn + goal.length() + 1) + .toLowerCase(); + } + + // If before and after aren't letters, we've + // found the word + if (((before.compareTo("a") < 0) || (before + .compareTo("z") > 0)) // before is not a + // letter + && ((after.compareTo("a") < 0) || (after + .compareTo("z") > 0))) + { + return psn; + } + + // The last position didn't work, so let's find + // the next, if there is one. + psn = phrase.indexOf(goal.toLowerCase(), + psn + 1); + + } + + return -1; + } + + /** + * Search for one word in phrase. The search is not case + * sensitive. This method will check that the given goal + * is not a substring of a longer string (so, for + * example, "I know" does not contain "no"). The search + * begins at the beginning of the string. + * + * @param statement + * the string to search + * @param goal + * the string to search for + * @return the index of the first occurrence of goal in + * statement or -1 if it's not found + */ + public int findKeyword(String statement, String goal) + { + return findKeyword(statement, goal, 0); + } + + /** + * Pick a default response to use if nothing else fits. + * + * @return a non-committal string + */ + private String getRandomResponse() + { + final int NUMBER_OF_RESPONSES = 6; + double r = Math.random(); + int whichResponse = (int) (r * NUMBER_OF_RESPONSES); + String response = ""; + + if (whichResponse == 0) + { + response = "Interesting, tell me more."; + } + else if (whichResponse == 1) + { + response = "Hmmm."; + } + else if (whichResponse == 2) + { + response = "Do you really think so?"; + } + else if (whichResponse == 3) + { + response = "You don't say."; + } + else if (whichResponse == 4) { + response = "and?..."; + } + else if(whichResponse == 5) { + response = "Never knew."; + } + + return response; + } + + /** + * Checks if a String contains a teacher's name + * @param statement + * @return an ArrayList {"f" for false or "t" for true, response} + */ + private ArrayList checkTeacher(String statement) { + //TODO: fix input: "she she she", output: She sounds like a good teacher." + final String[] namePronouns = {"Mr", "Ms", "Mrs", "Miss", "Dr", "Professor"}; + final String[] genderPronouns = {"He", "She", "She", "She", "They", "They"}; + //boolean[] keepChecking = {true, true, true, true, true, true}; + String contains = "f"; //false + String response = null; + for(int i = 0; i < namePronouns.length; i++) { + if(findKeyword(statement, namePronouns[i])>=0) { + if(response == null) { + contains = "t"; //true + response = genderPronouns[i] + " sounds like a good teacher."; + + } + else if(findKeyword(statement, "Both")>=0) { + response = "They all sound like good teachers."; + break; + } + else{ + response = "Both of them sound like good teachers."; + } + } + } + ArrayList list = new ArrayList(); + list.add(contains); + list.add(response); + return list; + } + +} diff --git a/Term2/Labs/Magpie1/Activity_3/MagpieRunner3.java b/Term2/Labs/Magpie1/Activity_3/MagpieRunner3.java new file mode 100644 index 0000000..b0bc733 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/MagpieRunner3.java @@ -0,0 +1,30 @@ +package Labs.Magpie1.Activity_3; +import java.util.Scanner; + +/** + * A simple class to run the Magpie class. + * @author Laurie White + * @version April 2012 + */ +public class MagpieRunner3 +{ + + /** + * Create a Magpie, give it user input, and print its replies. + */ + public static void main(String[] args) + { + Magpie3 maggie = new Magpie3(); + + System.out.println (maggie.getGreeting()); + Scanner in = new Scanner (System.in); + String statement = in.nextLine(); + + while (!statement.equals("Bye")) + { + System.out.println (maggie.getResponse(statement)); + statement = in.nextLine(); + } + } + +} diff --git a/Term2/Labs/Magpie1/Activity_3/StringExplorer3.java b/Term2/Labs/Magpie1/Activity_3/StringExplorer3.java new file mode 100644 index 0000000..6c6d094 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/StringExplorer3.java @@ -0,0 +1,28 @@ +package Labs.Magpie1.Activity_3; +/** + * A program to allow students to try out different + * String methods. + * @author Laurie White + * @version April 2012 + */ +public class StringExplorer3 +{ + + public static void main(String[] args) + { + String sample = "The quick brown fox jumped over the lazy dog."; + + // Demonstrate the indexOf method. + int position = sample.indexOf("quick"); + System.out.println ("sample.indexOf(\"quick\") = " + position); + + // Demonstrate the toLowerCase method. + String lowerCase = sample.toLowerCase(); + System.out.println ("sample.toLowerCase() = " + lowerCase); + System.out.println ("After toLowerCase(), sample = " + sample); + + // Try other methods here: + + } + +} diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/Magpie3.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/Magpie3.html new file mode 100644 index 0000000..283b2f9 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/Magpie3.html @@ -0,0 +1,372 @@ + + + + + +Magpie3 + + + + + + + + + + + + +
+
Magpie.Activity_3
+

Class Magpie3

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • Magpie.Activity_3.Magpie3
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Magpie3
    +extends java.lang.Object
    +
    A program to carry on conversations with a human user. + This version: +
    • + Uses advanced search for keywords +
    +
    +
    Version:
    +
    April 2012
    +
    Author:
    +
    Laurie White
    +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Magpie3() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      intfindKeyword(java.lang.String statement, + java.lang.String goal) +
      Search for one word in phrase.
      +
      intfindKeyword(java.lang.String statement, + java.lang.String goal, + int startPos) +
      Search for one word in phrase.
      +
      java.lang.StringgetGreeting() +
      Get a default greeting
      +
      java.lang.StringgetResponse(java.lang.String statement) +
      Gives a response to a user statement
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Magpie3

        +
        public Magpie3()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        getGreeting

        +
        public java.lang.String getGreeting()
        +
        Get a default greeting
        +
        +
        Returns:
        +
        a greeting
        +
        +
      • +
      + + + +
        +
      • +

        getResponse

        +
        public java.lang.String getResponse(java.lang.String statement)
        +
        Gives a response to a user statement
        +
        +
        Parameters:
        +
        statement - the user statement
        +
        Returns:
        +
        a response based on the rules given
        +
        +
      • +
      + + + +
        +
      • +

        findKeyword

        +
        public int findKeyword(java.lang.String statement,
        +                       java.lang.String goal,
        +                       int startPos)
        +
        Search for one word in phrase. The search is not case + sensitive. This method will check that the given goal + is not a substring of a longer string (so, for + example, "I know" does not contain "no").
        +
        +
        Parameters:
        +
        statement - the string to search
        +
        goal - the string to search for
        +
        startPos - the character of the string to begin the + search at
        +
        Returns:
        +
        the index of the first occurrence of goal in + statement or -1 if it's not found
        +
        +
      • +
      + + + +
        +
      • +

        findKeyword

        +
        public int findKeyword(java.lang.String statement,
        +                       java.lang.String goal)
        +
        Search for one word in phrase. The search is not case + sensitive. This method will check that the given goal + is not a substring of a longer string (so, for + example, "I know" does not contain "no"). The search + begins at the beginning of the string.
        +
        +
        Parameters:
        +
        statement - the string to search
        +
        goal - the string to search for
        +
        Returns:
        +
        the index of the first occurrence of goal in + statement or -1 if it's not found
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/class-use/Magpie3.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/class-use/Magpie3.html new file mode 100644 index 0000000..39c7981 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/class-use/Magpie3.html @@ -0,0 +1,122 @@ + + + + + +Uses of Class Magpie.Activity_3.Magpie3 + + + + + + + + + + + +
+

Uses of Class
Magpie.Activity_3.Magpie3

+
+
No usage of Magpie.Activity_3.Magpie3
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-frame.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-frame.html new file mode 100644 index 0000000..fc9f59b --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-frame.html @@ -0,0 +1,20 @@ + + + + + +Magpie.Activity_3 + + + + + +

Magpie.Activity_3

+
+

Classes

+ +
+ + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-summary.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-summary.html new file mode 100644 index 0000000..ef79070 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-summary.html @@ -0,0 +1,142 @@ + + + + + +Magpie.Activity_3 + + + + + + + + + + + +
+

Package Magpie.Activity_3

+
+
+
    +
  • + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    Magpie3 +
    A program to carry on conversations with a human user.
    +
    +
  • +
+
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-tree.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-tree.html new file mode 100644 index 0000000..e991ef2 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-tree.html @@ -0,0 +1,131 @@ + + + + + +Magpie.Activity_3 Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package Magpie.Activity_3

+
+
+

Class Hierarchy

+
    +
  • java.lang.Object + +
  • +
+
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-use.html b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-use.html new file mode 100644 index 0000000..b295fc7 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/Magpie/Activity_3/package-use.html @@ -0,0 +1,122 @@ + + + + + +Uses of Package Magpie.Activity_3 + + + + + + + + + + + +
+

Uses of Package
Magpie.Activity_3

+
+
No usage of Magpie.Activity_3
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/allclasses-frame.html b/Term2/Labs/Magpie1/Activity_3/doc/allclasses-frame.html new file mode 100644 index 0000000..2f35a29 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/allclasses-frame.html @@ -0,0 +1,19 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/allclasses-noframe.html b/Term2/Labs/Magpie1/Activity_3/doc/allclasses-noframe.html new file mode 100644 index 0000000..528fa90 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/allclasses-noframe.html @@ -0,0 +1,19 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/constant-values.html b/Term2/Labs/Magpie1/Activity_3/doc/constant-values.html new file mode 100644 index 0000000..a7e0719 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/constant-values.html @@ -0,0 +1,122 @@ + + + + + +Constant Field Values + + + + + + + + + + + +
+

Constant Field Values

+

Contents

+
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/deprecated-list.html b/Term2/Labs/Magpie1/Activity_3/doc/deprecated-list.html new file mode 100644 index 0000000..f2191df --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/deprecated-list.html @@ -0,0 +1,122 @@ + + + + + +Deprecated List + + + + + + + + +
+ + + + + + + +
+ + +
+

Deprecated API

+

Contents

+
+ +
+ + + + + + + +
+ + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/help-doc.html b/Term2/Labs/Magpie1/Activity_3/doc/help-doc.html new file mode 100644 index 0000000..61189e5 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/help-doc.html @@ -0,0 +1,223 @@ + + + + + +API Help + + + + + + + + + + + +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+
    +
  • +

    Package

    +

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    +
      +
    • Interfaces (italic)
    • +
    • Classes
    • +
    • Enums
    • +
    • Exceptions
    • +
    • Errors
    • +
    • Annotation Types
    • +
    +
  • +
  • +

    Class/Interface

    +

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    +
      +
    • Class inheritance diagram
    • +
    • Direct Subclasses
    • +
    • All Known Subinterfaces
    • +
    • All Known Implementing Classes
    • +
    • Class/interface declaration
    • +
    • Class/interface description
    • +
    +
      +
    • Nested Class Summary
    • +
    • Field Summary
    • +
    • Constructor Summary
    • +
    • Method Summary
    • +
    +
      +
    • Field Detail
    • +
    • Constructor Detail
    • +
    • Method Detail
    • +
    +

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    +
  • +
  • +

    Annotation Type

    +

    Each annotation type has its own separate page with the following sections:

    +
      +
    • Annotation Type declaration
    • +
    • Annotation Type description
    • +
    • Required Element Summary
    • +
    • Optional Element Summary
    • +
    • Element Detail
    • +
    +
  • +
  • +

    Enum

    +

    Each enum has its own separate page with the following sections:

    +
      +
    • Enum declaration
    • +
    • Enum description
    • +
    • Enum Constant Summary
    • +
    • Enum Constant Detail
    • +
    +
  • +
  • +

    Use

    +

    Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.

    +
  • +
  • +

    Tree (Class Hierarchy)

    +

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    +
      +
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • +
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • +
    +
  • +
  • +

    Deprecated API

    +

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    +
  • +
  • +

    Index

    +

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    +
  • +
  • +

    Prev/Next

    +

    These links take you to the next or previous class, interface, package, or related page.

    +
  • +
  • +

    Frames/No Frames

    +

    These links show and hide the HTML frames. All pages are available with or without frames.

    +
  • +
  • +

    All Classes

    +

    The All Classes link shows all classes and interfaces except non-static nested types.

    +
  • +
  • +

    Serialized Form

    +

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    +
  • +
  • +

    Constant Field Values

    +

    The Constant Field Values page lists the static final fields and their values.

    +
  • +
+This help file applies to API documentation generated using the standard doclet.
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-1.html b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-1.html new file mode 100644 index 0000000..ae1e0bc --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-1.html @@ -0,0 +1,133 @@ + + + + + +F-Index + + + + + + + + +
+ + + + + + + +
+ + +
F G M  + + +

F

+
+
findKeyword(String, String, int) - Method in class Magpie.Activity_3.Magpie3
+
+
Search for one word in phrase.
+
+
findKeyword(String, String) - Method in class Magpie.Activity_3.Magpie3
+
+
Search for one word in phrase.
+
+
+F G M 
+ +
+ + + + + + + +
+ + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-2.html b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-2.html new file mode 100644 index 0000000..2cd7e77 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-2.html @@ -0,0 +1,133 @@ + + + + + +G-Index + + + + + + + + +
+ + + + + + + +
+ + +
F G M  + + +

G

+
+
getGreeting() - Method in class Magpie.Activity_3.Magpie3
+
+
Get a default greeting
+
+
getResponse(String) - Method in class Magpie.Activity_3.Magpie3
+
+
Gives a response to a user statement
+
+
+F G M 
+ +
+ + + + + + + +
+ + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-3.html b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-3.html new file mode 100644 index 0000000..4cf05a4 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/index-files/index-3.html @@ -0,0 +1,133 @@ + + + + + +M-Index + + + + + + + + +
+ + + + + + + +
+ + +
F G M  + + +

M

+
+
Magpie.Activity_3 - package Magpie.Activity_3
+
 
+
Magpie3 - Class in Magpie.Activity_3
+
+
A program to carry on conversations with a human user.
+
+
Magpie3() - Constructor for class Magpie.Activity_3.Magpie3
+
 
+
+F G M 
+ +
+ + + + + + + +
+ + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/index.html b/Term2/Labs/Magpie1/Activity_3/doc/index.html new file mode 100644 index 0000000..05bd9d2 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/index.html @@ -0,0 +1,72 @@ + + + + + +Generated Documentation (Untitled) + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="Magpie/Activity_3/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/overview-tree.html b/Term2/Labs/Magpie1/Activity_3/doc/overview-tree.html new file mode 100644 index 0000000..642bc83 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/overview-tree.html @@ -0,0 +1,135 @@ + + + + + +Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object + +
  • +
+
+ + + + + + diff --git a/Term2/Labs/Magpie1/Activity_3/doc/package-list b/Term2/Labs/Magpie1/Activity_3/doc/package-list new file mode 100644 index 0000000..e5b2717 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/package-list @@ -0,0 +1 @@ +Magpie.Activity_3 diff --git a/Term2/Labs/Magpie1/Activity_3/doc/script.js b/Term2/Labs/Magpie1/Activity_3/doc/script.js new file mode 100644 index 0000000..c3a1cae --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/Term2/Labs/Magpie1/Activity_3/doc/stylesheet.css b/Term2/Labs/Magpie1/Activity_3/doc/stylesheet.css new file mode 100644 index 0000000..b8dad08 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_3/doc/stylesheet.css @@ -0,0 +1,574 @@ +/* Javadoc style sheet */ +/* +Overall document style +*/ + +@import url('resources/fonts/dejavu.css'); + +body { + background-color:#ffffff; + color:#353833; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4A6782; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4A6782; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; +} +h1 { + font-size:20px; +} +h2 { + font-size:18px; +} +h3 { + font-size:16px; + font-style:italic; +} +h4 { + font-size:13px; +} +h5 { + font-size:12px; +} +h6 { + font-size:11px; +} +ul { + list-style-type:disc; +} +code, tt { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; +} +dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; +} +table tr td dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + vertical-align:top; + padding-top:4px; +} +sup { + font-size:8px; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:11px; + z-index:200; + margin-top:-9px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-color:#4D7A97; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:11px; + margin:0; +} +.topNav { + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.bottomNav { + margin-top:10px; + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.subNav { + background-color:#dee3e9; + float:left; + width:100%; + overflow:hidden; + font-size:12px; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; + text-transform:uppercase; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding: 5px 6px; + text-transform:uppercase; +} +ul.subNavList li{ + list-style:none; + float:left; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; + text-transform:uppercase; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; + text-transform:uppercase; +} +.navBarCell1Rev { + background-color:#F8981D; + color:#253441; + margin: auto 5px; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader span{ + margin-right:15px; +} +.indexHeader h1 { + font-size:13px; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 15px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:13px; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:12px; +} +.indexContainer h2 { + font-size:13px; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; + padding-top:2px; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:12px; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:15px; + line-height:1.4; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #ededed; + background-color:#f8f8f8; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { + width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; +} +.overviewSummary, .memberSummary { + padding:0px; +} +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#253441; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + padding-top:10px; + padding-left:1px; + margin:0px; + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; + float:left; + background-color:#F8981D; + border: none; + height:16px; +} +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#F8981D; + height:16px; +} +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; +} +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + +} +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { + text-align:left; + padding:0px 0px 12px 10px; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; +} +th.colFirst, th.colLast, th.colOne, .constantsSummary th { + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} +td.colFirst, th.colFirst { + white-space:nowrap; + font-size:13px; +} +td.colLast, th.colLast { + font-size:13px; +} +td.colOne, th.colOne { + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +.tableSubHeadingColor { + background-color:#EEEEFF; +} +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:10px; +} +.block { + display:block; + margin:3px 10px 2px 0px; + color:#474747; +} +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { + font-weight:bold; +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +} diff --git a/Term2/Labs/Magpie1/Activity_4/Magpie4.java b/Term2/Labs/Magpie1/Activity_4/Magpie4.java new file mode 100644 index 0000000..8f6b3da --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_4/Magpie4.java @@ -0,0 +1,226 @@ +package Labs.Magpie1.Activity_4; +/** + * A program to carry on conversations with a human user. + * This version: + *
  • + * Uses advanced search for keywords + *
  • + * Will transform statements as well as react to keywords + *
+ * @author Laurie White + * @version April 2012 + * + */ +public class Magpie4 +{ + /** + * Get a default greeting + * @return a greeting + */ + public String getGreeting() + { + return "Hello, let's talk."; + } + + /** + * Gives a response to a user statement + * + * @param statement + * the user statement + * @return a response based on the rules given + */ + public String getResponse(String statement) + { + String response = ""; + if (statement.length() == 0) + { + response = "Say something, please."; + } + + else if (findKeyword(statement, "no") >= 0) + { + response = "Why so negative?"; + } + else if (findKeyword(statement, "mother") >= 0 + || findKeyword(statement, "father") >= 0 + || findKeyword(statement, "sister") >= 0 + || findKeyword(statement, "brother") >= 0) + { + response = "Tell me more about your family."; + } + + // Responses which require transformations + else if (findKeyword(statement, "I want", 0) >= 0) + { + response = transformIWantStatement(statement); + } + else if(findKeyword(statement, "I") < findKeyword(statement, "you")) { + int psnI = findKeyword(statement, "I") + 2; + int psnYou = findKeyword(statement, "you") -1; + + String something = statement.substring(psnI, psnYou).trim(); + response = "Why do you " + something + " me?"; + } + else + { + // Look for a two word (you me) + // pattern + int psn = findKeyword(statement, "you", 0); + + if (psn >= 0 + && findKeyword(statement, "me", psn) >= 0) + { + response = transformYouMeStatement(statement); + } + else + { + response = getRandomResponse(); + } + } + return response; + } + + /** + * Take a statement with "I want to ." and transform it into + * "What would it mean to ?" + * @param statement the user statement, assumed to contain "I want to" + * @return the transformed statement + */ + private String transformIWantStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + int psn = findKeyword (statement, "I want", 0); + String restOfStatement = statement.substring(psn + 6).trim(); + return "Would you really be happy if you had " + restOfStatement + "?"; + } + + + + /** + * Take a statement with "you me" and transform it into + * "What makes you think that I you?" + * @param statement the user statement, assumed to contain "you" followed by "me" + * @return the transformed statement + */ + private String transformYouMeStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + + int psnOfYou = findKeyword (statement, "you", 0); + int psnOfMe = findKeyword (statement, "me", psnOfYou + 3); + + String restOfStatement = statement.substring(psnOfYou + 3, psnOfMe).trim(); + return "What makes you think that I " + restOfStatement + " you?"; + } + + + + + + /** + * Search for one word in phrase. The search is not case sensitive. + * This method will check that the given goal is not a substring of a longer string + * (so, for example, "I know" does not contain "no"). + * @param statement the string to search + * @param goal the string to search for + * @param startPos the character of the string to begin the search at + * @return the index of the first occurrence of goal in statement or -1 if it's not found + */ + private int findKeyword(String statement, String goal, int startPos) + { + String phrase = statement.trim(); + // The only change to incorporate the startPos is in the line below + int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); + + // Refinement--make sure the goal isn't part of a word + while (psn >= 0) + { + // Find the string of length 1 before and after the word + String before = " ", after = " "; + if (psn > 0) + { + before = phrase.substring (psn - 1, psn).toLowerCase(); + } + if (psn + goal.length() < phrase.length()) + { + after = phrase.substring(psn + goal.length(), psn + goal.length() + 1).toLowerCase(); + } + + // If before and after aren't letters, we've found the word + if (((before.compareTo ("a") < 0 ) || (before.compareTo("z") > 0)) // before is not a letter + && ((after.compareTo ("a") < 0 ) || (after.compareTo("z") > 0))) + { + return psn; + } + + // The last position didn't work, so let's find the next, if there is one. + psn = phrase.indexOf(goal.toLowerCase(), psn + 1); + + } + + return -1; + } + + /** + * Search for one word in phrase. The search is not case sensitive. + * This method will check that the given goal is not a substring of a longer string + * (so, for example, "I know" does not contain "no"). The search begins at the beginning of the string. + * @param statement the string to search + * @param goal the string to search for + * @return the index of the first occurrence of goal in statement or -1 if it's not found + */ + private int findKeyword(String statement, String goal) + { + return findKeyword (statement, goal, 0); + } + + + + /** + * Pick a default response to use if nothing else fits. + * @return a non-committal string + */ + private String getRandomResponse() + { + final int NUMBER_OF_RESPONSES = 4; + double r = Math.random(); + int whichResponse = (int)(r * NUMBER_OF_RESPONSES); + String response = ""; + + if (whichResponse == 0) + { + response = "Interesting, tell me more."; + } + else if (whichResponse == 1) + { + response = "Hmmm."; + } + else if (whichResponse == 2) + { + response = "Do you really think so?"; + } + else if (whichResponse == 3) + { + response = "You don't say."; + } + + return response; + } + +} diff --git a/Term2/Labs/Magpie1/Activity_4/MagpieRunner4.java b/Term2/Labs/Magpie1/Activity_4/MagpieRunner4.java new file mode 100644 index 0000000..d06ccda --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_4/MagpieRunner4.java @@ -0,0 +1,30 @@ +package Labs.Magpie1.Activity_4; +import java.util.Scanner; + +/** + * A simple class to run the Magpie class. + * @author Laurie White + * @version April 2012 + */ +public class MagpieRunner4 +{ + + /** + * Create a Magpie, give it user input, and print its replies. + */ + public static void main(String[] args) + { + Magpie4 maggie = new Magpie4(); + + System.out.println (maggie.getGreeting()); + Scanner in = new Scanner (System.in); + String statement = in.nextLine(); + + while (!statement.equals("Bye")) + { + System.out.println (maggie.getResponse(statement)); + statement = in.nextLine(); + } + } + +} diff --git a/Term2/Labs/Magpie1/Activity_5/Magpie5.java b/Term2/Labs/Magpie1/Activity_5/Magpie5.java new file mode 100644 index 0000000..36f7d99 --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_5/Magpie5.java @@ -0,0 +1,273 @@ +package Labs.Magpie1.Activity_5; +import java.util.Random; + +/** + * A program to carry on conversations with a human user. + * This version: + *
  • + * Uses advanced search for keywords + *
  • + * Will transform statements as well as react to keywords + *
+ * This version uses an array to hold the default responses. + * @author Laurie White + * @version April 2012 + */ +public class Magpie5 +{ + /** + * Get a default greeting + * @return a greeting + */ + public String getGreeting() + { + return "Hello, let's talk."; + } + + /** + * Gives a response to a user statement + * + * @param statement + * the user statement + * @return a response based on the rules given + */ + public String getResponse(String statement) + { + String response = ""; + if (statement.length() == 0) + { + response = "Say something, please."; + } + + else if (findKeyword(statement, "no") >= 0) + { + response = "Why so negative?"; + } + else if (findKeyword(statement, "mother") >= 0 + || findKeyword(statement, "father") >= 0 + || findKeyword(statement, "sister") >= 0 + || findKeyword(statement, "brother") >= 0) + { + response = "Tell me more about your family."; + } + + // Responses which require transformations + else if (findKeyword(statement, "I want to", 0) >= 0) + { + response = transformIWantToStatement(statement); + } + // Part of student solution + else if (findKeyword(statement, "I want", 0) >= 0) + { + response = transformIWantStatement(statement); + } + + else + { + + // Look for a two word (you me) + // pattern + int psn = findKeyword(statement, "you", 0); + + if (psn >= 0 + && findKeyword(statement, "me", psn) >= 0) + { + response = transformYouMeStatement(statement); + } + else + { + // Part of student solution + // Look for a two word (I you) + // pattern + psn = findKeyword(statement, "i", 0); + + if (psn >= 0 + && findKeyword(statement, "you", psn) >= 0) + { + response = transformIYouStatement(statement); + } + else + { + response = getRandomResponse(); + } + } + } + return response; + } + + /** + * Take a statement with "I want to ." and transform it into + * "What would it mean to ?" + * @param statement the user statement, assumed to contain "I want to" + * @return the transformed statement + */ + private String transformIWantToStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + int psn = findKeyword (statement, "I want to", 0); + String restOfStatement = statement.substring(psn + 9).trim(); + return "What would it mean to " + restOfStatement + "?"; + } + + + /** + * Take a statement with "I want ." and transform it into + * "Would you really be happy if you had ?" + * @param statement the user statement, assumed to contain "I want" + * @return the transformed statement + */ + private String transformIWantStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + int psn = findKeyword (statement, "I want", 0); + String restOfStatement = statement.substring(psn + 6).trim(); + return "Would you really be happy if you had " + restOfStatement + "?"; + } + + /** + * Take a statement with "you me" and transform it into + * "What makes you think that I you?" + * @param statement the user statement, assumed to contain "you" followed by "me" + * @return the transformed statement + */ + private String transformYouMeStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + + int psnOfYou = findKeyword (statement, "you", 0); + int psnOfMe = findKeyword (statement, "me", psnOfYou + 3); + + String restOfStatement = statement.substring(psnOfYou + 3, psnOfMe).trim(); + return "What makes you think that I " + restOfStatement + " you?"; + } + + /** + * Take a statement with "I you" and transform it into + * "Why do you me?" + * @param statement the user statement, assumed to contain "I" followed by "you" + * @return the transformed statement + */ + private String transformIYouStatement(String statement) + { + // Remove the final period, if there is one + statement = statement.trim(); + String lastChar = statement.substring(statement + .length() - 1); + if (lastChar.equals(".")) + { + statement = statement.substring(0, statement + .length() - 1); + } + + int psnOfI = findKeyword (statement, "I", 0); + int psnOfYou = findKeyword (statement, "you", psnOfI); + + String restOfStatement = statement.substring(psnOfI + 1, psnOfYou).trim(); + return "Why do you " + restOfStatement + " me?"; + } + + + + + /** + * Search for one word in phrase. The search is not case sensitive. + * This method will check that the given goal is not a substring of a longer string + * (so, for example, "I know" does not contain "no"). + * @param statement the string to search + * @param goal the string to search for + * @param startPos the character of the string to begin the search at + * @return the index of the first occurrence of goal in statement or -1 if it's not found + */ + private int findKeyword(String statement, String goal, int startPos) + { + String phrase = statement.trim(); + // The only change to incorporate the startPos is in the line below + int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); + + // Refinement--make sure the goal isn't part of a word + while (psn >= 0) + { + // Find the string of length 1 before and after the word + String before = " ", after = " "; + if (psn > 0) + { + before = phrase.substring (psn - 1, psn).toLowerCase(); + } + if (psn + goal.length() < phrase.length()) + { + after = phrase.substring(psn + goal.length(), psn + goal.length() + 1).toLowerCase(); + } + + // If before and after aren't letters, we've found the word + if (((before.compareTo ("a") < 0 ) || (before.compareTo("z") > 0)) // before is not a letter + && ((after.compareTo ("a") < 0 ) || (after.compareTo("z") > 0))) + { + return psn; + } + + // The last position didn't work, so let's find the next, if there is one. + psn = phrase.indexOf(goal.toLowerCase(), psn + 1); + + } + + return -1; + } + + /** + * Search for one word in phrase. The search is not case sensitive. + * This method will check that the given goal is not a substring of a longer string + * (so, for example, "I know" does not contain "no"). The search begins at the beginning of the string. + * @param statement the string to search + * @param goal the string to search for + * @return the index of the first occurrence of goal in statement or -1 if it's not found + */ + private int findKeyword(String statement, String goal) + { + return findKeyword (statement, goal, 0); + } + + + + /** + * Pick a default response to use if nothing else fits. + * @return a non-committal string + */ + private String getRandomResponse () + { + Random r = new Random (); + return randomResponses [r.nextInt(randomResponses.length)]; + } + + private String [] randomResponses = {"Interesting, tell me more", + "Hmmm.", + "Do you really think so?", + "You don't say.", + "Really?", + "Oh" + }; + +} diff --git a/Term2/Labs/Magpie1/Activity_5/MagpieRunner5.java b/Term2/Labs/Magpie1/Activity_5/MagpieRunner5.java new file mode 100644 index 0000000..9060a2f --- /dev/null +++ b/Term2/Labs/Magpie1/Activity_5/MagpieRunner5.java @@ -0,0 +1,30 @@ +package Labs.Magpie1.Activity_5; +import java.util.Scanner; + +/** + * A simple class to run the Magpie class. + * @author Laurie White + * @version April 2012 + */ +public class MagpieRunner5 +{ + + /** + * Create a Magpie, give it user input, and print its replies. + */ + public static void main(String[] args) + { + Magpie5 maggie = new Magpie5(); + + System.out.println (maggie.getGreeting()); + Scanner in = new Scanner (System.in); + String statement = in.nextLine(); + + while (!statement.equals("Bye")) + { + System.out.println (maggie.getResponse(statement)); + statement = in.nextLine(); + } + } + +} diff --git a/Term2/Labs/Magpie1/Magpie Lab Worksheets.docx b/Term2/Labs/Magpie1/Magpie Lab Worksheets.docx new file mode 100644 index 0000000..2457d03 Binary files /dev/null and b/Term2/Labs/Magpie1/Magpie Lab Worksheets.docx differ diff --git a/Term2/Labs/Magpie1/MagpieActivityWorksheets.pdf b/Term2/Labs/Magpie1/MagpieActivityWorksheets.pdf new file mode 100644 index 0000000..b6e58be Binary files /dev/null and b/Term2/Labs/Magpie1/MagpieActivityWorksheets.pdf differ diff --git a/Term2/Labs/Magpie1/MagpieLabStudentGuide_updated_2014_Final.pdf b/Term2/Labs/Magpie1/MagpieLabStudentGuide_updated_2014_Final.pdf new file mode 100644 index 0000000..c58d8f4 Binary files /dev/null and b/Term2/Labs/Magpie1/MagpieLabStudentGuide_updated_2014_Final.pdf differ diff --git a/Term2/Lesson1/Main.java b/Term2/Lesson1/Main.java new file mode 100644 index 0000000..205b6f4 --- /dev/null +++ b/Term2/Lesson1/Main.java @@ -0,0 +1,62 @@ +package Lesson1; +/* +Write a Java program that allows a user to input words at the command line. Your program should stop accepting words when the user enters "STOP". Store the words in an ArrayList. The word STOP should not be stored in the list. + +Next, print the size of the list, followed by the contents of the list. + +Then, remove the first and last words stored in the list, but only if the list has a length greater than two. Finally, reprint the contents of the list. + +Sample Run: + +Please enter words, enter STOP to stop the loop. +cup +spoon +fork +bowl +plate +knife +STOP + +6 +[cup, spoon, fork, bowl, plate, knife] +[spoon, fork, bowl, plate] +*/ + +import java.util.ArrayList; +import java.util.Scanner; +import java.lang.Math; + +class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + String input = null; + ArrayList list = new ArrayList(); + + System.out.println("Please enter words, enter STOP to stop the loop."); + + //input = scan.nextLine(); + while(true) { + input = scan.nextLine(); + if(input.equals("STOP")) { + break; + } + else { + list.add(input); + } + } + + System.out.println("\n" + list.size()); + + ArrayList newList = new ArrayList(list); + if(list.size()>2) { + newList.remove(newList.size()-1); + newList.remove(0); + } + + System.out.println(list); + System.out.println(newList); + + scan.close(); + + } +} \ No newline at end of file diff --git a/Term2/Lesson1/T2_L1_Template.java b/Term2/Lesson1/T2_L1_Template.java new file mode 100644 index 0000000..ea9fc5a --- /dev/null +++ b/Term2/Lesson1/T2_L1_Template.java @@ -0,0 +1,31 @@ +package Lesson1; + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.ArrayList; + + + +class t2_lesson1_template{ +//Term 2 Lesson 1: ArrayList + + public static void main (String str[]) throws IOException { + + ArrayList list = new ArrayList (); + + + list.add("I Wanna Dance With Somebody"); + list.add("I Will Always Love You"); + list.add("Didn't We Almost Have it All"); + + System.out.println(list); + + } + +} + + diff --git a/Term2/Lesson10/T2_L10_Is_a_has_a_Relationship.pdf b/Term2/Lesson10/T2_L10_Is_a_has_a_Relationship.pdf new file mode 100644 index 0000000..c1f9faf Binary files /dev/null and b/Term2/Lesson10/T2_L10_Is_a_has_a_Relationship.pdf differ diff --git a/Term2/Lesson11/Book.java b/Term2/Lesson11/Book.java new file mode 100644 index 0000000..4c3b9c9 --- /dev/null +++ b/Term2/Lesson11/Book.java @@ -0,0 +1,48 @@ +package Lesson11; + +public class Book + +{ + private String title; + private String author; + + private int year; + + public Book() + { + this("none", "unknown", 1450); + } + + public Book(String t) + { + this(t, "unknown", 1450); + } + + public Book(String t, String a, int y) + { + setTitle(t); + setAuthor(a); + setYear(y); + } + + public String toString() + { + return title + "\n\t" + author + "\n\t" + year; + } + + public void setTitle(String t) + { + title = t; + } + + public void setAuthor(String a) + { + author = a; + } + + public void setYear(int y) + { + year = y; + } + +} diff --git a/Term2/Lesson11/Quadrilateral.java b/Term2/Lesson11/Quadrilateral.java new file mode 100644 index 0000000..c3c20d1 --- /dev/null +++ b/Term2/Lesson11/Quadrilateral.java @@ -0,0 +1,43 @@ +package Lesson11; + +public class Quadrilateral + +{ + private int side1; + private int side2; + private int side3; + private int side4; + + public Quadrilateral(int a, int b, int c, int d) + { + side1=a; + side2=b; + side3=c; + side4=d; + } + + public int getPerimeter() + { + return side1 + side2 + side3 + side4; + } + + public int getSide1() + { + return side1; + } + + public int getSide2() + { + return side2; + } + + public int getSide3() + { + return side3; + } + + public int getSide4() + { + return side4; + } +} \ No newline at end of file diff --git a/Term2/Lesson11/Rectangle.java b/Term2/Lesson11/Rectangle.java new file mode 100644 index 0000000..6a80a38 --- /dev/null +++ b/Term2/Lesson11/Rectangle.java @@ -0,0 +1,15 @@ +package Lesson11; + +public class Rectangle extends Quadrilateral +{ + public Rectangle(int a, int b) + { + super(a,b,a,b); + } + + public int getPerimeter() + { + return 2*getSide1() + 2*getSide2(); + } + +} \ No newline at end of file diff --git a/Term2/Lesson11/T2_L11_Template_1.java b/Term2/Lesson11/T2_L11_Template_1.java new file mode 100644 index 0000000..90d959d --- /dev/null +++ b/Term2/Lesson11/T2_L11_Template_1.java @@ -0,0 +1,26 @@ +package Lesson11; + + +/* + * Lesson 11 - Unit 6 - Interfaces + */ + + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t2_lesson11_template_1{ + + + public static void main (String str[]) throws IOException { + String s1 = "apple"; + String s2 = "banana"; + + System.out.println(s1.compareTo(s2)); + } + +} + + diff --git a/Term2/Lesson11/T2_L11_Template_2.java b/Term2/Lesson11/T2_L11_Template_2.java new file mode 100644 index 0000000..b2d3f63 --- /dev/null +++ b/Term2/Lesson11/T2_L11_Template_2.java @@ -0,0 +1,26 @@ +package Lesson11; + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.*; + +class t2_lesson11_template_2{ + + + public static void main (String str[]) throws IOException { + + ArrayList bookshelf = new ArrayList (); + bookshelf.add( new Book ("James and the Giant Peach", "Roald Dahl", 1961)); + bookshelf.add( new Book ("Matilda", "Roald Dahl", 1988)); + + for (Book b : bookshelf) + { + System.out.println(b); + } + + } +} diff --git a/Term2/Lesson12/Lesson_12_FastStart.java b/Term2/Lesson12/Lesson_12_FastStart.java new file mode 100644 index 0000000..761cbb1 --- /dev/null +++ b/Term2/Lesson12/Lesson_12_FastStart.java @@ -0,0 +1,36 @@ +package Lesson12; + +import java.util.ArrayList; + +/* +Write a program to initialize an ArrayList of Strings and insert ten words. +Then, using Math.random, print two different Strings from the list. +Paste your program into the code-runner box below and press run. +For this activity, the words you use do not matter, but the values in the ArrayList should not contain any whitespace. +Every time you call main, it should print a different pair of values from the list. +Write your code in a class named Lesson_12_FastStart + */ + +public class Lesson_12_FastStart { + + public static void main(String[] args) { + ArrayList list = new ArrayList(); + list.add("Write"); + list.add("a"); + list.add("program"); + list.add("to"); + list.add("initialize"); + list.add("an"); + list.add("ArrayList"); + list.add("of"); + list.add("Strings"); + list.add("and"); + + int ran1, ran2; + ran1 = (int) ((Math.random()*3)+1); + ran2 = (int) ((Math.random()*3)+1); + + System.out.println("Your two random words are: " + list.get(ran1) + " and " + list.get(ran2)); + } + +} diff --git a/Term2/Lesson12/T2_L12_Template.java b/Term2/Lesson12/T2_L12_Template.java new file mode 100644 index 0000000..c1719d9 --- /dev/null +++ b/Term2/Lesson12/T2_L12_Template.java @@ -0,0 +1,26 @@ +package Lesson12; + + +/* + * Lesson 12 - Unit 6 - Wrapper Classes + */ + + +import java.io.*; +import static java.lang.System.*; +import java.util.*; +import java.util.Scanner; + +class t2_lesson12_template{ + + + public static void main (String str[]) throws IOException { + + int[] list = {18, 37, 137, 77, 9, 79, 27, 87, 9, 135, 111, 66, 68, 106, 139, 128, 111, 6, 76, 139, 79, 109, 35, 129, 138, 91, 51, 54, 64, 114, 42, 138, 38, 124, 131, 22, 110, 36, 44, 55}; + //find the smallest element + + } + +} + + diff --git a/Term2/Lesson13/T2_L13_Algorithms.pdf b/Term2/Lesson13/T2_L13_Algorithms.pdf new file mode 100644 index 0000000..370bc1c Binary files /dev/null and b/Term2/Lesson13/T2_L13_Algorithms.pdf differ diff --git a/Term2/Lesson14/Main.java b/Term2/Lesson14/Main.java new file mode 100644 index 0000000..452d872 --- /dev/null +++ b/Term2/Lesson14/Main.java @@ -0,0 +1,70 @@ +package Lesson14; + + +/* + * Amplify AP CS MOOC - Term 2, Lesson 14 + * Rebecca Dovi + */ +import java.io.*; +import java.util.*; + +class Main +{ + + /* + * Returns the number of Strings in the input list that start with the given + * letter. Implementation should use linear search, and ignore the case of + * the input letter. + */ + public static int countLetter(ArrayList list, String letter) + { + int num = 0; + char let = letter.toLowerCase().toCharArray()[0]; + for(int i = 0; i < list.size(); i++) { + if(list.get(i).toLowerCase().charAt(0) == let) { + num++; + } + } + return num; + } + + public static void main(String str[]) throws IOException + { + /* + * Initialize an ArrayList of animals called zoo. + */ + ArrayList zoo = new ArrayList(); + zoo.add("Zebra"); + zoo.add("Ardvark"); + zoo.add("Emu"); + zoo.add("Hippo"); + zoo.add("Aligator"); + zoo.add("Lion"); + zoo.add("Giraffe"); + zoo.add("Seal"); + zoo.add("Tiger"); + zoo.add("Elephant"); + + /* + * Print the contents of the zoo. + */ + System.out.println(zoo); + + /* + * Print the output from calling countLetter with various letters. For + * example, countLetter (zoo, "e") should return 2 while + * countLetter(zoo, "W") should return 0. + */ + System.out.println("A: " + countLetter(zoo, "A")); + System.out.println("B: " + countLetter(zoo, "B")); + System.out.println("C: " + countLetter(zoo, "C")); + System.out.println("L: " + countLetter(zoo, "L")); + System.out.println("T: " + countLetter(zoo, "T")); + + System.out.println("a: " + countLetter(zoo, "a")); + System.out.println("b: " + countLetter(zoo, "b")); + System.out.println("c: " + countLetter(zoo, "c")); + System.out.println("l: " + countLetter(zoo, "l")); + System.out.println("t: " + countLetter(zoo, "t")); + } +} diff --git a/Term2/Lesson15/Lesson_15_Activity.java b/Term2/Lesson15/Lesson_15_Activity.java new file mode 100644 index 0000000..4c590e7 --- /dev/null +++ b/Term2/Lesson15/Lesson_15_Activity.java @@ -0,0 +1,42 @@ +package Lesson15; + +import java.util.Arrays; + +/* +Write a method, void sortAndPrint(String [] list), which implements a selection sort on the array list and prints the sorted values in order. Make sure to use the String.compareTo() method when sorting to decide the correct order of the Strings. For example, consider the following code: + +String [] list = { "against" , "forms" , "belief" , "government" , "democratic" , "movement" , "understanding"}; +sortAndPrint(list); + +The should print the following: + +against belief democratic forms government movement understanding +For this activity, include your method in a class called Lesson_15_Activity. Copy the entire class into the coderunner box and press run. + */ + +public class Lesson_15_Activity { + + public static void main(String[] args) { + String [] list = { "against" , "forms" , "belief" , "government" , "democratic" , "movement" , "understanding"}; + + sortAndPrint(list); + } + public static void sortAndPrint(String [] list) { + for(int i = 0; i < list.length; i++) { + int smallest = i; + for(int k = i; k < list.length; k++) { + if(list[smallest].compareTo(list[k])>0) { + smallest = k; + } + } + String temp = list[smallest]; + list[smallest] = list[i]; + list[i] = temp; + } + //System.out.println(Arrays.toString(list)); + for(int i = 0; i < list.length; i++) { + System.out.println(list[i] + " "); + } + } + +} diff --git a/Term2/Lesson16/Insertion_sort.java b/Term2/Lesson16/Insertion_sort.java new file mode 100644 index 0000000..5884ddd --- /dev/null +++ b/Term2/Lesson16/Insertion_sort.java @@ -0,0 +1,41 @@ +package Lesson16; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * THIS DOESN'T REALLY WORK, FIRST INDEX IS SIMIPLILY MOVED TO THE LAST INDEX, NOT SORTED. everything else words + * @author gt + * + */ +public class Insertion_sort { + public static void main(String[] args) { + /*ArrayList list = new ArrayList(); + for(int i = 0; i < 200; i++) { + list.add(Math.random() * 100000 - 50000); + } + double[] arr = new double[list.size()]; + for(int i = 0; i < list.size(); i++) { + arr[i] = list.get(i); + }*/ + + double[] arr2 = new double[] {100, 2, 3, 4, 5, 4, 3, 2, 1, 0, -2, 9}; + + insertionSort(arr2); + System.out.println(Arrays.toString(arr2)); + } + public static void insertionSort(double[] arr) { + for(int i = 1; i < arr.length; i++) { + double temp = arr[i]; + for(int k = i; k >= 0 ; k--) { + if(arr[k] < arr[i] || k == 0) { + for(int j = i; j > k; j--) { + arr[j] = arr[j-1]; + } + arr[k] = temp; + break; + } + } + } + } +} diff --git a/Term2/Lesson17/Lesson_17_Activity.java b/Term2/Lesson17/Lesson_17_Activity.java new file mode 100644 index 0000000..413264b --- /dev/null +++ b/Term2/Lesson17/Lesson_17_Activity.java @@ -0,0 +1,69 @@ +package Lesson17; + +/* +For this activity, write a class called Lesson_17_Activity which includes the following methods: + +public static boolean isSorted(int [] a) - returns true if the array a is in ascending order and false otherwise. +public static int binarySearch(int [] a, int b) - performs a binary search to determine if the value b is stored in a. If b is found, return the index of b. Otherwise, return -1. +Include both methods in a class called Lesson_17_Activity and paste the entire class into the code runner box below. + */ + +public class Lesson_17_Activity { + + public static void main(String[] args) { + int[] a = new int[] {1, 5, 2, 57, 23, 5, 68, 23, 7, 2, 5, -347}; + int[] b = new int[] {-246, 1, 4, 6, 8, 10, 346}; + System.out.println(binarySearch(b, 8)); + } + + public static boolean isSorted(int [] a) { + for(int i = 1; i < a.length; i++) { + if(a[i] < a[i-1]) { + return false; + } + } + return true; + } + + public static int binarySearch(int [] a, int b) { + int mid; + int low = 0; + int high = a.length-1; + while(high >= low) { + mid = low + (high-low) / 2; + if(a[mid] == b) { + return mid; + } else if(a[mid] < b) { + low = mid+1; + } else { + high = mid-1; + } + } + return -1; + } + + /*int binarySearch2(int arr[], int x) + { + int low = 0, high = arr.length - 1; + while (low <= high) + { + int mid = low + (high-low)/2; + + // Check if x is present at mid + if (arr[mid] == x) + return mid; + + // If x greater, ignore left half + if (arr[mid] < x) + low = mid + 1; + + // If x is smaller, ignore right half + else + high = mid - 1; + } + + // if we reach here, then element was + // not present + return -1; + }*/ +} diff --git a/Term2/Lesson18/T2_L18_Merge_Sort.pdf b/Term2/Lesson18/T2_L18_Merge_Sort.pdf new file mode 100644 index 0000000..c97461d Binary files /dev/null and b/Term2/Lesson18/T2_L18_Merge_Sort.pdf differ diff --git a/Term2/Lesson19/T2_Lesson19_Template.java b/Term2/Lesson19/T2_Lesson19_Template.java new file mode 100644 index 0000000..d948f4e --- /dev/null +++ b/Term2/Lesson19/T2_Lesson19_Template.java @@ -0,0 +1,23 @@ +package Lesson19; + +/* + * Lesson 19 - Unit 8 - 2-D Array + */ +import java.io.*; +import static java.lang.System.*; + +import java.util.Arrays; +import java.util.Scanner; + +public class T2_Lesson19_Template{ + public static void main (String args[]) { + + int[][] grid = new int[3][4]; //3 ros, 4 columns + int[] test = new int[5]; + grid[1][2] = 5; //row 1, column 2 = 5 + + for(int i = 0; i < grid.length; i++) { + System.out.println(Arrays.toString(grid[i])); + } + } +} \ No newline at end of file diff --git a/Term2/Lesson2/Main.java b/Term2/Lesson2/Main.java new file mode 100644 index 0000000..7eeefad --- /dev/null +++ b/Term2/Lesson2/Main.java @@ -0,0 +1,52 @@ +package Lesson2; +/* +Write a program that allows a user to input words at the command line. Your program should stop accepting words when the user enters "STOP". Store the words in an ArrayList. The word STOP should not be stored in the list. + +Next, your program should loop through the list and print out only the words that contain the letter "a". + +Sample Run: + +Please enter words, enter STOP to stop the loop. +dog +zebra +cat +fish +STOP + +zebra +cat +Note: For this activity, you must use the class name, Main and the method, main. +*/ + +import java.util.ArrayList; +import java.util.Scanner; +import java.lang.Math; + +class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + String input = null; + ArrayList list = new ArrayList(); + + System.out.println("Please enter words, enter STOP to stop the loop."); + + //input = scan.nextLine(); + while(true) { + input = scan.nextLine(); + if(input.equals("STOP")) { + System.out.println(""); + break; + } + else { + list.add(input); + } + } + + for(String item : list) { + if(item.contains("a")) { + System.out.print(item); + } + } + + } +} \ No newline at end of file diff --git a/Term2/Lesson2/T2_L2_Template.java b/Term2/Lesson2/T2_L2_Template.java new file mode 100644 index 0000000..2d5bb51 --- /dev/null +++ b/Term2/Lesson2/T2_L2_Template.java @@ -0,0 +1,32 @@ +package Lesson2; +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.*; + +class t2_lesson02_template{ + + + public static void main (String str[]) throws IOException { + + ArrayList books = new ArrayList(); + + //add book titles + books.add("The Secret of the Old Clock"); + books.add("Mystery of Crocodile Island"); + books.add("The Hidden Staircase"); + books.add("The Bungalow Mystery"); + books.add("The Quest of the Missing Map"); + books.add("The Clue in the Crossword Cipher"); + + System.out.println( books); + + + } + +} + + diff --git a/Term2/Lesson20/Lesson20Template.java b/Term2/Lesson20/Lesson20Template.java new file mode 100644 index 0000000..e34e1d5 --- /dev/null +++ b/Term2/Lesson20/Lesson20Template.java @@ -0,0 +1,39 @@ +package Lesson20; + +import java.util.Arrays; + +public class Lesson20Template { + + final static int numStudents = 10; + final static int numTests = 5; + + public static void main(String[] args) { + double[][] scores = new double[numStudents][numTests]; + double[] testAvg = new double[numTests]; + + random(scores); + for(int i = 0; i < scores.length; i++) { + System.out.println(Arrays.toString(scores[i])); + } + + calcTestAvg(scores, testAvg); + System.out.println("\nClass Avg: " + Arrays.toString(testAvg)); + } + public static void random(double[][] s) { + for(int i = 0; i < s.length; i++) { + for(int k = 0; k < s[i].length; k++) { + s[i][k] = (int)((Math.random()*100)+1); + } + } + } + public static void calcTestAvg(double[][] s, double[] a) { + for(int i = 0; i < s[0].length; i++) { + double sum = 0; + for(int k = 0; k < s.length; k++) { + sum += s[k][i]; + } + a[i] = sum/s.length; + } + } + +} diff --git a/Term2/Lesson20/T2_L20_2-D_Arrays_and_Algorithms.pdf b/Term2/Lesson20/T2_L20_2-D_Arrays_and_Algorithms.pdf new file mode 100644 index 0000000..a49406b Binary files /dev/null and b/Term2/Lesson20/T2_L20_2-D_Arrays_and_Algorithms.pdf differ diff --git a/Term2/Lesson21/ap10_frq_computer_science_a.pdf b/Term2/Lesson21/ap10_frq_computer_science_a.pdf new file mode 100644 index 0000000..883661c Binary files /dev/null and b/Term2/Lesson21/ap10_frq_computer_science_a.pdf differ diff --git a/Term2/Lesson3/T2_L3_Template.java b/Term2/Lesson3/T2_L3_Template.java new file mode 100644 index 0000000..0d742ba --- /dev/null +++ b/Term2/Lesson3/T2_L3_Template.java @@ -0,0 +1,39 @@ +package Lesson3; + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.*; + +class t2_lesson03_template{ + + + public static void main (String str[]) throws IOException { + + + + } +} +class Coin{ + private int side; + public Coin(int headsOrTails) { + side = headsOrTails; + } + public String toString() { + if(side == 1) { + return "heads"; + + } + else { + return "tails"; + } + } + +} + + + + diff --git a/Term2/Lesson4/Book.java b/Term2/Lesson4/Book.java new file mode 100644 index 0000000..4e35e2a --- /dev/null +++ b/Term2/Lesson4/Book.java @@ -0,0 +1,47 @@ +package Lesson4; +public class Book + +{ + private String title; + private String author; + + private int year; + + public Book() + { + this("none", "unknown", 1450); + } + + public Book(String t) + { + this(t, "unknown", 1450); + } + + public Book(String t, String a, int y) + { + setTitle(t); + setAuthor(a); + setYear(y); + } + + public String toString() + { + return title + "\n\t" + author + "\n\t" + year; + } + + public void setTitle(String t) + { + title = t; + } + + public void setAuthor(String a) + { + author = a; + } + + public void setYear(int y) + { + year = y; + } + +} diff --git a/Term2/Lesson4/Main.java b/Term2/Lesson4/Main.java new file mode 100644 index 0000000..aff6a64 --- /dev/null +++ b/Term2/Lesson4/Main.java @@ -0,0 +1,121 @@ +package Lesson4; +/* +Vehicle class + +Create a class called Vehicle that simulates a car moving along a 40 block stretch of road. + +Your class will build a vehicle and keep track of its location on the road. Location values may range from -20 to 20. A location value of 0 represents block 0, a location value of 1 represents block 1, a location value of 2 represents block 2, etc. If the user tries to move the vehicle beyond block +20 or -20, set the location to +/- 20 respectively. + +In previous exercises, we had a requirement that you name your class Main. In this exercise, you must name your class Vehicle. + +To test your code before submission, download the file student_runner_Vehicle.java (Links to an external site.)Links to an external site. to the same folder that holds your Vehicle.java implementation. Run the main method in the student_runner_Vehicle class and verify that the printed output matches the sample run output below. Please feel free to change the runner to test different values to make sure your program fits the requirements. We will use a similar runner class to grade the program. + +When you are done coding and testing, copy and paste your entire Vehicle class into the Code Runner and press "Run" to submit the exercise. Use the "Check Answer" button to get additional feedback on your work. + +Variables + +int location - An integer that holds the current block location of the car on the road, with possible values ranging from -20 to 20. +Methods + +Vehicle() - Set location to 0. +Vehicle(int loc) - If loc is between -20 and 20 inclusive, set location to loc. Otherwise, set location to 0. +void forward() - Increments the Vehicle forward one block. Do not let the user move past block 20. +void backward() - Increments the vehicle backward one block. Do not let the user move past block -20. +int getLocation() - Should return an integer representing the block location of the car. +String toString() - Returns a String representation of the car's location. It should print out spaces for all of the blocks from -20 to the car's current location, then print the '@' character. For example if the car is at block -10, the method will return the following String: " @" (10 spaces then the '@'). +Sample Run + + @ + @ + @ + @ + @ +20 + @ + @ + @ + @ + @ + @ + @ + @ + @ +0 + @ +-19 +-20 +-20 +-20 +*/ + +import java.lang.Math; + +class Vehicle { + //Constants + /** + * 20 + */ + private final int BLOCKS_TIL_CENTER = 20; + /** + * @ + */ + private final String VEHICLE_SYMBOL = "@"; + //Vars + private int location; + + //Methods + public Vehicle() { + location = 0; + } + public Vehicle(int loc) { + setLocation(loc); + } + public void setLocation(int loc) { + if(loc>20||loc<-20) { + location = 0; + } + else{ + location = loc; + } + + } + public void forward() { + if(location < 20) { + location += 1; + } + } + public void backward() { + if(location > -20) { + location -= 1; + } + } + public int getLocation() { + return location; + } + + //Print + public String toString() { + int loc = getLocation(); + int blocks = 0; + + blocks = BLOCKS_TIL_CENTER + loc; + /*if(loc < 0) { //if negative + blocks = BLOCKS_TIL_CENTER + loc; + } + else if(loc > 0) { //if positive + blocks = BLOCKS_TIL_CENTER + Math.abs(loc); + } + else { //zero + blocks = BLOCKS_TIL_CENTER; + }*/ + + + String spaces = ""; + for(int i = 1; i <= blocks; i++) { + spaces += " "; + } + + String print = spaces + VEHICLE_SYMBOL; + return print; + } +} \ No newline at end of file diff --git a/Term2/Lesson4/student_runner_Vehicle.java b/Term2/Lesson4/student_runner_Vehicle.java new file mode 100644 index 0000000..d6bab97 --- /dev/null +++ b/Term2/Lesson4/student_runner_Vehicle.java @@ -0,0 +1,50 @@ +package Lesson4; + +import java.io.*; +import static java.lang.System.*; +import java.util.Scanner; + +public class student_runner_Vehicle { + public static void main (String str[]) throws IOException { + defaultTest(); + } + private static void defaultTest() { + Vehicle v1 = new Vehicle (17); + + System.out.println(v1); + + for (int i = 1; i < 5; i ++) + { + v1.forward(); + System.out.println(v1); + } + System.out.println(v1.getLocation()); + + /*for (int i = 1 ; i < 10; i ++) + { + int d = (int)(Math.random() *2); + if (d ==0) + v1.forward(); + else + v1.backward(); + System.out.println(v1); + + + }*/ + + Vehicle v2 = new Vehicle (87); + System.out.println(v2.getLocation()); + + Vehicle v3 = new Vehicle(-18); + System.out.println(v3); + v3.backward(); + System.out.println(v3.getLocation()); + v3.backward(); + System.out.println(v3.getLocation()); + v3.backward(); + System.out.println(v3.getLocation()); + v3.backward(); + System.out.println(v3.getLocation()); + } + +} \ No newline at end of file diff --git a/Term2/Lesson4/t2_lesson4_template.java b/Term2/Lesson4/t2_lesson4_template.java new file mode 100644 index 0000000..517fa0b --- /dev/null +++ b/Term2/Lesson4/t2_lesson4_template.java @@ -0,0 +1,19 @@ +package Lesson4; +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.*; + +class t2_lesson04_template{ + + + public static void main (String str[]) throws IOException { + + Book b = new Book ("James and the Giant Peach", "Roald Dahl", 1961); + + + } +} diff --git a/Term2/Lesson5/Book.java b/Term2/Lesson5/Book.java new file mode 100644 index 0000000..3345773 --- /dev/null +++ b/Term2/Lesson5/Book.java @@ -0,0 +1,51 @@ +package Lesson5; + +public class Book + +{ + private String title; + private String author; + + private int year; + + public Book() + { + this("none", "unknown", 1450); + } + + public Book(String t) + { + this(t, "unknown", 1450); + } + + public Book(String t, String a, int y) + { + setTitle(t); + setAuthor(a); + setYear(y); + } + + public String toString() + { + return title + "\n\t" + author + "\n\t" + year; + } + + public void setTitle(String t) + { + title = t; + } + + public void setAuthor(String a) + { + author = a; + } + + public void setYear(int y) + { + if (y >= 1450) + year = y; + else + year = 2000; + } + +} diff --git a/Term2/Lesson5/Student.java b/Term2/Lesson5/Student.java new file mode 100644 index 0000000..adcd116 --- /dev/null +++ b/Term2/Lesson5/Student.java @@ -0,0 +1,67 @@ +package Lesson5; + +/* + * For this exercise, you will create a Student class to hold student data. In previous exercises, we had a requirement that you name your class Main. In this exercise, you must name your class Student. + +Your Student class should include the following information: first name, last name, grade level, GPA, and a student id. Grade level is an integer value ranging from 0 to 12, with 0 representing kindergarten. GPA is a decimal value ranging from 0 to 4.5. Student id is an integer value. The first student id is 1, the second student id is 2, the next is 3, and so on. When a new Student is created, your code should automatically initialize student id to the next integer value. For example, if the last created Student's student id is 17, the next student id generated should be 18. + +Your student class should include the following methods: + +Student() - Constructs a new student with first name and last name set to "None", grade level set to 0 and GPA set to 0.0. The student id should automatically be set to the next integer. +Student(String firstName, String lastName, int gradeLevel, double gpa) - Constructs a new student with variables initialized to the values specified. The grade level should only be allowed to range between 0 and 12 inclusive, 0 represents kindergarten. Otherwise, set the grade level to 0. The GPA should only be allowed to range from 0.0 to 4.5, inclusive. Otherwise, set the GPA to 0.0. The student id should automatically be set to the next integer. +String toString() - Returns the student information as a String in the following format (notice line breaks after the first name and GPA): +Dovi, Mrs +GPA: 4.0 +Grade Level: 7 id # 4 +To test your code prior to submission, download the runner class student_runner_Student.java (Links to an external site.)Links to an external site. to the same folder that holds your Student.java implementation. Run student_runner_Student.main class and verify that the output matches the sample run below. Please feel free to change the runner to test different values to make sure your program fits the requirements. We will use a similar runner class to grade the program. + +Sample Run + +None, None +GPA: 0.0 +Grade Level: 0 id # 1 +None, None +GPA: 0.0 +Grade Level: 0 id # 2 +None, None +GPA: 0.0 +Grade Level: 0 id # 3 +Dovi, Mrs. +GPA: 3.4 +Grade Level: 7 id # 4 +When you are done coding and testing, copy and paste your entire Student class into the Code Runner and press "Run" to submit the exercise. Use the "Check Answer" button to get additional feedback on your work. + */ + +public class Student { + static int totalStudents = 0; + + static String FirstName = null; + static String LastName = null; + static int GradeLevel = 0; + static double Gpa = 0.0; + static int StudentID = 0; + + public Student() { + this("None", "None", 0, 0.0); + } + public Student(String firstName, String lastName, int gradeLevel, double gpa) { + totalStudents++; + StudentID = totalStudents; + + if(gradeLevel > 12 || gradeLevel < 0) { + gradeLevel = 0; + } + if(gpa > 4.5 || gpa < 0) { + gpa = 0; + } + + FirstName = firstName; + LastName = lastName; + GradeLevel = gradeLevel; + Gpa = gpa; + } + public String toString() { + String output = LastName + ", " + FirstName + "\nGPA: " + Gpa + "\nGrade Level: " + GradeLevel + " id # " + StudentID; + return output; + } +} diff --git a/Term2/Lesson5/student_runner_Student.java b/Term2/Lesson5/student_runner_Student.java new file mode 100644 index 0000000..1466bb2 --- /dev/null +++ b/Term2/Lesson5/student_runner_Student.java @@ -0,0 +1,26 @@ +package Lesson5; + +/* + * AP CS MOOC + * + */ +import java.io.IOException; + +public class student_runner_Student +{ + public static void main(String str[]) throws IOException + { + Student s1 = new Student(); + System.out.println(s1); + + Student s2 = new Student(); + System.out.println(s2); + + Student s3 = new Student(); + System.out.println(s3); + + Student s4 = new Student("Mrs.", "Dovi", 7, 3.4); + System.out.println(s4); + } + +} \ No newline at end of file diff --git a/Term2/Lesson5/t2_lesson05_template.java b/Term2/Lesson5/t2_lesson05_template.java new file mode 100644 index 0000000..e30ec64 --- /dev/null +++ b/Term2/Lesson5/t2_lesson05_template.java @@ -0,0 +1,36 @@ +package Lesson5; + +/* + * Lesson 5 - Unit 5 - Classes - Static vs Instance + */ + + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; +import java.lang.Math; + +import java.util.*; + + +class t2_lesson05_template{ + + + public static void main (String str[]) throws IOException { + + ArrayList bookshelf = new ArrayList (); + + bookshelf.add (new Book ("James and the Giant Peach", "Roald Dahl", 1961)); + + + for (Book b: bookshelf) + { + System.out.println(b); + } + + + } +} + + diff --git a/Term2/Lesson6/T2_L6_AP_Exam_Review.pdf b/Term2/Lesson6/T2_L6_AP_Exam_Review.pdf new file mode 100644 index 0000000..a9f241f Binary files /dev/null and b/Term2/Lesson6/T2_L6_AP_Exam_Review.pdf differ diff --git a/Term2/Lesson6/ap10_frq_computer_science_a.pdf b/Term2/Lesson6/ap10_frq_computer_science_a.pdf new file mode 100644 index 0000000..883661c Binary files /dev/null and b/Term2/Lesson6/ap10_frq_computer_science_a.pdf differ diff --git a/Term2/Lesson7/T2_L7_Template.java b/Term2/Lesson7/T2_L7_Template.java new file mode 100644 index 0000000..745f48e --- /dev/null +++ b/Term2/Lesson7/T2_L7_Template.java @@ -0,0 +1,23 @@ +package Lesson7; +/* + * Lesson 7 - Unit 6 - Inheritance + */ + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +import Lesson5.Book; + +class t2_lesson07_template extends Book{ + private String illustrator; + + public t2_lesson07_template() { + this("none", "unknown", "unknown", 1900); + } + public t2_lesson07_template (String t, String a, String i, int y) { + super(t, a, y); + illustrator = i; + } +} diff --git a/Term2/Lesson8/Quadrilateral.java b/Term2/Lesson8/Quadrilateral.java new file mode 100644 index 0000000..9d42e0b --- /dev/null +++ b/Term2/Lesson8/Quadrilateral.java @@ -0,0 +1,43 @@ +package Lesson8; +public class Quadrilateral + +{ + private int side1; + private int side2; + private int side3; + private int side4; + + public Quadrilateral (int a, int b, int c, int d) + { + side1 = a; + side2 = b; + side3 = c; + side4 = d; + } + + public int getSide1() + { + return side1; + } + + public int getSide2() + { + return side2; + } + + public int getSide3() + { + return side3; + } + + public int getSide4() + { + return side4; + } + + public int getPerimeter() + { + return side1 + side2 + side3 + side4; + } + +} diff --git a/Term2/Lesson8/T2_L8_Template.java b/Term2/Lesson8/T2_L8_Template.java new file mode 100644 index 0000000..32eedab --- /dev/null +++ b/Term2/Lesson8/T2_L8_Template.java @@ -0,0 +1,23 @@ +package Lesson8; +/* + * Lesson 8 - Unit 5 - Advanced Classes - Inheritance Overriding Methods + */ + + +import java.io.*; +import static java.lang.System.*; + +import java.util.Scanner; + +class t2_lesson08_template{ + + + public static void main (String str[]) throws IOException { + Quadrilateral q = new Quadrilateral (3, 7, 6, 7); + + System.out.println("Perimeter: \t" + q.getPerimeter()); + } + +} + + diff --git a/Term2/Lesson9/Quadrilateral.java b/Term2/Lesson9/Quadrilateral.java new file mode 100644 index 0000000..ba68184 --- /dev/null +++ b/Term2/Lesson9/Quadrilateral.java @@ -0,0 +1,43 @@ +package Lesson9; + +public class Quadrilateral + +{ + private int side1; + private int side2; + private int side3; + private int side4; + + public Quadrilateral(int a, int b, int c, int d) + { + side1=a; + side2=b; + side3=c; + side4=d; + } + + public int getPerimeter() + { + return side1 + side2 + side3 + side4; + } + + public int getSide1() + { + return side1; + } + + public int getSide2() + { + return side2; + } + + public int getSide3() + { + return side3; + } + + public int getSide4() + { + return side4; + } +} \ No newline at end of file diff --git a/Term2/Lesson9/Rectangle.java b/Term2/Lesson9/Rectangle.java new file mode 100644 index 0000000..bb19c62 --- /dev/null +++ b/Term2/Lesson9/Rectangle.java @@ -0,0 +1,15 @@ +package Lesson9; + +public class Rectangle extends Quadrilateral +{ + public Rectangle(int a, int b) + { + super(a,b,a,b); + } + + public int getPerimeter() + { + return 2*getSide1() + 2*getSide2(); + } + +} \ No newline at end of file diff --git a/Term2/Lesson9/T2_L9_Template.java b/Term2/Lesson9/T2_L9_Template.java new file mode 100644 index 0000000..cb12e85 --- /dev/null +++ b/Term2/Lesson9/T2_L9_Template.java @@ -0,0 +1,26 @@ +package Lesson9; + +/* + * Lesson 9 - Unit 5 - Advanced Classes - Abstract classes + */ + + + + +import java.util.Scanner; +import java.lang.Math; +import java.util.*; +import java.io.*; + +class t2_lesson9_template{ + + + public static void main (String str[]) throws IOException { + + + + } + +} + + diff --git a/Term2/Term 2 Review Questions #1.pdf b/Term2/Term 2 Review Questions #1.pdf new file mode 100644 index 0000000..3cd8625 Binary files /dev/null and b/Term2/Term 2 Review Questions #1.pdf differ diff --git a/Term2/Ultimate_Frisbee/About.java b/Term2/Ultimate_Frisbee/About.java new file mode 100644 index 0000000..d85c2ed --- /dev/null +++ b/Term2/Ultimate_Frisbee/About.java @@ -0,0 +1,187 @@ +package Ultimate_Frisbee; + +/* + +Assignment 3: Ultimate Frisbee +For this assignment, you will create a hierarchy of five classes to describe various elements of a an ultimate frisbee (Links to an external site.)Links to an external site. team. Ultimate frisbee is a non-contact sport with players at a position of “cutter” or “handler”. A team usually also has a head coach and possibly one or more assistant coaches. An ultimate team has seven players on the field, with four players at the position of cutter and three at the position of handler. Check out the below video to learn more about this great sport! + +https://www.youtube.com/watch?v=OqBo-CCf5Gw&feature=youtu.be (Links to an external site.)Links to an external site. + + +The classes you will write are: Person, UltimatePlayer, Captain, Coach, and UltimateTeam. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task for this assignment. + +Person + +Variables + +String firstName - Holds the person's first name. +String lastName - Holds the person's last name. +Methods + +Person(String firstName, String lastName) - Constructor that takes in String parameters representing the first and last names. +String toString() - Returns a String with the following format: lastName, firstName +UltimatePlayer extends Person + +Variables + +int jerseyNumber - Using a static variable to keep track of ultimate player jersey numbers, every player should be assigned a unique value for their own jersey number. +String position - Represents a player’s position. Possible values are “handler” and “cutter”. +Methods + +UltimatePlayer(String firstName, String lastName, String position) - Constructor that accepts the first name, last name and the position of a player. The first and last names should be set by calling the constructor of the parent class. Position should be set to “handler” if the input string is not “handler” or “cutter”. The UltimatePlayer constructor also sets the jersey number to the next available positive integer. The first UltimatePlayer created should have a jersey number of 1, the second will have a jersey number of 2, third of 3, etc. +String getPosition() - Returns the UltimatePlayer's position. +String toString() - Returns a three-line String with UltimatePlayer information formatted as follows: +Smith, Mary + Jersey #: 1 + Position: cutter +Note: there are three spaces before "Jersey #: ..." and "Position: ...". + +Captain extends UltimatePlayer + +Variables + +boolean type - Captains on an Ultimate team are usually responsible for either offense or defense. This variable is a boolean representing the type of captain, true for offense, false for defense. +Methods + +Captain(String firstName, String lastName, String position, boolean type) - The first and last names and the position should be set by calling the constructor of the parent class. +String toString() - Returns a four-line String with Captain info formatted as follows: +Lee, Sarah + Jersey #: 2 + Position: handler + Captain: offense +Note: there are three spaces before "Jersey #: ...", "Position: ..." and "Captain: ...". + +Coach extends Person + +Variables + +String role - Role of coach on the team. This is a flexible description; there are no required values for this variable. For example, “Head Coach” or “Assistant Coach”. +Methods + +Coach(String firstName, String lastName, String role) - The first and last names should be set by calling the constructor of the parent class. +String toString() - Returns a two-line String with Coach info formatted as follows: +Wagner, Rebecca + Role: Head Coach +Note: there are three spaces before "Role: ...". + +UltimateTeam + +Variables + +ArrayList players - The list of ultimate players on the team. +ArrayList coaches - A list of the team’s coaches. +Methods + +UltimateTeam(ArrayList players, ArrayList coaches) - A constructor that specifies the coaches and players of the team. +String getCutters() - Returns a String listing all the UltimateTeams's UltimatePlayers that have the position of “cutter”. Returns an empty String if the UltimateTeam does not have a player with position of “cutter”. See the Sample Run below for the format of the returned String. +String getHandlers() - Returns a String listing all the UltimateTeams's UltimatePlayers that have the position of “handler”. Returns an empty String if the UltimateTeam does not have a player with position of “handler”. See the Sample Run below for the format of the returned String. +String toString() - Returns a multiline String listing the Coaches and UltimatePlayers on the UltimateTeam. The String is formatted as follows: +COACHES +{listing of faculty} + +PLAYERS +{listing of UltimatePlayers} +See the Sample Run below for an example. + +Final Notes + +Remember, all variables should have an access level of private and all required methods should have an access level of public. Wherever possible, the child class should use a call to the parent's toString and/or constructor methods. + +Make sure that all files in your solution are in the same directory. Please download the runner class, Student_Runner_Ultimate.java (Links to an external site.)Links to an external site. into that directory, run the file in DrJava, and verify that the class output matches the Sample Run that follows. We will use a different runner to grade the program. Remember to change the runner to test different values to make sure your program fits the requirements. + +Sample Run of Student_Runner_Ultimate.java (Links to an external site.)Links to an external site.: + +Printing person: + Doe, John + +Printing player: +Smith, Mary + Jersey #: 1 + Position: cutter + +Printing captain: +Tully, Henry + Jersey #: 2 + Position: handler + Captain: offense + +Printing coach: +Lee, Sara + Role: Head coach + +Printing team: +COACHES +Mathour, Maryam + Role: Head Coach +Van Loben Sels, Soren + Role: Assistant Coach + +PLAYERS +Trong, Sammy + Jersey #: 3 + Position: handler +Patel, Jayant + Jersey #: 4 + Position: handler +Ozaeta, Myra + Jersey #: 5 + Position: cutter +Holbrook, Lisa + Jersey #: 6 + Position: cutter +Kvale, Lisbeth + Jersey #: 7 + Position: cutter +Henry, Malik + Jersey #: 8 + Position: handler + Captain: offense +Pak, Joseph + Jersey #: 9 + Position: cutter + Captain: defense + + +Printing cutters: +Ozaeta, Myra + Jersey #: 5 + Position: cutter +Holbrook, Lisa + Jersey #: 6 + Position: cutter +Kvale, Lisbeth + Jersey #: 7 + Position: cutter +Pak, Joseph + Jersey #: 9 + Position: cutter + Captain: defense + + +Printing handlers: +Trong, Sammy + Jersey #: 3 + Position: handler +Patel, Jayant + Jersey #: 4 + Position: handler +Henry, Malik + Jersey #: 8 + Position: handler + Captain: offense +Submitting your code + +Below are the submission links for each class. You will have to submit each class separately by following the proper link below. Each of the 5 classes in this assignment is worth 2 points, for a total of 10. + +Assignment 3: Ultimate Frisbee - Person Class Submission + +Assignment 3: Ultimate Frisbee - UltimatePlayer Class Submission + +Assignment 3: Ultimate Frisbee - Captain Class Submission + +Assignment 3: Ultimate Frisbee - Coach Class Submission + +Assignment 3: Ultimate Frisbee - UltimateTeam Class Submission + + +*/ diff --git a/Term2/Ultimate_Frisbee/Captain.java b/Term2/Ultimate_Frisbee/Captain.java new file mode 100644 index 0000000..a50d9da --- /dev/null +++ b/Term2/Ultimate_Frisbee/Captain.java @@ -0,0 +1,13 @@ +package Ultimate_Frisbee; + +public class Captain extends UltimatePlayer{ + private boolean roleType; //true=offense, false=defense + + public Captain(String firstName, String lastName, String position, boolean type) { + super(firstName, lastName, position); + roleType = type; + } + public String toString() { + return super.toString() + "\n Captain: " + (roleType ? "offense" : "defense"); + } +} diff --git a/Term2/Ultimate_Frisbee/Coach.java b/Term2/Ultimate_Frisbee/Coach.java new file mode 100644 index 0000000..cc49a07 --- /dev/null +++ b/Term2/Ultimate_Frisbee/Coach.java @@ -0,0 +1,12 @@ +package Ultimate_Frisbee; + +public class Coach extends Person{ + String teamRole; + public Coach(String firstName, String lastName, String role) { + super(firstName, lastName); + teamRole = role; + } + public String toString() { + return super.toString() + "\n Role: " + teamRole; + } +} diff --git a/Term2/Ultimate_Frisbee/Person.java b/Term2/Ultimate_Frisbee/Person.java new file mode 100644 index 0000000..7136941 --- /dev/null +++ b/Term2/Ultimate_Frisbee/Person.java @@ -0,0 +1,16 @@ +package Ultimate_Frisbee; + +public class Person { + + private String fName = ""; + private String lName = ""; + + public Person() {}; + public Person(String firstName, String lastName) { + fName = firstName; + lName = lastName; + } + public String toString() { + return lName + ", " + fName; + } +} diff --git a/Term2/Ultimate_Frisbee/Student_Runner_Ultimate.java b/Term2/Ultimate_Frisbee/Student_Runner_Ultimate.java new file mode 100644 index 0000000..c673093 --- /dev/null +++ b/Term2/Ultimate_Frisbee/Student_Runner_Ultimate.java @@ -0,0 +1,40 @@ +package Ultimate_Frisbee; + +import java.util.ArrayList; + + +public class Student_Runner_Ultimate { + + public static void main(String[] args) { + Person person = new Person("John", "Doe"); + System.out.println("Printing person:\n" + person + "\n"); + + UltimatePlayer player = new UltimatePlayer("Mary", "Smith", "cutter"); + System.out.println("Printing player:\n" + player + "\n"); + + Captain captain = new Captain("Henry", "Tully", "handler", true); + System.out.println("Printing captain:\n" + captain + "\n"); + + Coach coach = new Coach("Sara", "Lee", "Head coach"); + System.out.println("Printing coach:\n" + coach + "\n"); + + ArrayList players = new ArrayList(); + players.add(new UltimatePlayer("Sammy", "Trong", "handler")); + players.add(new UltimatePlayer("Jayant", "Patel", "handler")); + players.add(new UltimatePlayer("Myra", "Ozaeta", "cutter")); + players.add(new UltimatePlayer("Lisa", "Holbrook", "cutter")); + players.add(new UltimatePlayer("Lisbeth", "Kvale", "cutter")); + players.add(new Captain("Malik", "Henry", "handler", true)); + players.add(new Captain("Joseph", "Pak", "cutter", false)); + + ArrayList coaches = new ArrayList(); + coaches.add(new Coach("Maryam", "Mathour", "Head Coach")); + coaches.add(new Coach("Soren", "Van Loben Sels", "Assistant Coach")); + + UltimateTeam team = new UltimateTeam(players, coaches); + System.out.println("Printing team:\n" + team.toString() + "\n"); + System.out.println("Printing cutters:\n" + team.getCutters() + "\n"); + System.out.println("Printing handlers:\n" + team.getHandlers() + "\n"); + + } +} diff --git a/Term2/Ultimate_Frisbee/UltimatePlayer.java b/Term2/Ultimate_Frisbee/UltimatePlayer.java new file mode 100644 index 0000000..af9beb0 --- /dev/null +++ b/Term2/Ultimate_Frisbee/UltimatePlayer.java @@ -0,0 +1,27 @@ +package Ultimate_Frisbee; + +public class UltimatePlayer extends Person { + + static int jerseyNumber = 0; + private int myJerseyNum; + private String pos; + + + public UltimatePlayer(String firstName, String lastName, String position) { + super(firstName, lastName); + jerseyNumber++; + myJerseyNum = jerseyNumber; + if(position.equals("handler") || position.equals("cutter")) { + pos = position; + } else{ + pos = "handler"; + } + + } + public String getPosition() { + return pos; + } + public String toString() { + return (super.toString() + "\n Jersey #: " + myJerseyNum + "\n Position: " + pos); + } +} diff --git a/Term2/Ultimate_Frisbee/UltimateTeam.java b/Term2/Ultimate_Frisbee/UltimateTeam.java new file mode 100644 index 0000000..7d05b7a --- /dev/null +++ b/Term2/Ultimate_Frisbee/UltimateTeam.java @@ -0,0 +1,43 @@ +package Ultimate_Frisbee; + +import java.util.ArrayList; + +public class UltimateTeam { + ArrayList playersList = new ArrayList(); + ArrayList coachesList = new ArrayList(); + public UltimateTeam(ArrayList players, ArrayList coaches) { + playersList = (ArrayList) players.clone(); + coachesList = (ArrayList) coaches.clone(); + } + public String getCutters() { + String output = ""; + for(UltimatePlayer p : playersList) { + if(p.getPosition().equals("cutter")) { + output += p.toString() + "\n"; + } + } + return output; + } + public String getHandlers() { + String output = ""; + for(UltimatePlayer p : playersList) { + if(p.getPosition().equals("handler")) { + output += p.toString() + "\n"; + } + } + return output; + } + public String toString() { + String output = ""; + output += "COACHES\n"; + for(Coach c : coachesList) { + output += c.toString() + "\n"; + } + + output += "\nPLAYERS\n"; + for(UltimatePlayer p : playersList) { + output += p.toString() + "\n"; + } + return output; + } +} diff --git a/Term2/_Classwork/Feb_1_2018_Warmup.java b/Term2/_Classwork/Feb_1_2018_Warmup.java new file mode 100644 index 0000000..512588c --- /dev/null +++ b/Term2/_Classwork/Feb_1_2018_Warmup.java @@ -0,0 +1,33 @@ +package _Classwork; + +public class Feb_1_2018_Warmup { + public static void main(String[] args) { + + } + // Question 1: + public int numCount(int[] array, int num) { + int counter = 0; + for(int item : array) { + if(item == num) { + counter++; + } + } + return counter; + } + + /* Question 2: + Output: 52 + */ + + /* Question 1: + a. always true + */ + + /* Question 2: + d. r = d * 5.0 + 0.5 + */ + + /* Question 3: + e. I, II, III + */ +} diff --git a/Term2/_Classwork/Search_and_Sort/GaryTou-SearchAndSort.zip b/Term2/_Classwork/Search_and_Sort/GaryTou-SearchAndSort.zip new file mode 100644 index 0000000..73e5ab0 Binary files /dev/null and b/Term2/_Classwork/Search_and_Sort/GaryTou-SearchAndSort.zip differ diff --git a/Term2/_Classwork/Search_and_Sort/Labs Search and Sort #1.doc b/Term2/_Classwork/Search_and_Sort/Labs Search and Sort #1.doc new file mode 100644 index 0000000..d25d484 Binary files /dev/null and b/Term2/_Classwork/Search_and_Sort/Labs Search and Sort #1.doc differ diff --git a/Term2/_Classwork/Search_and_Sort/NumberSearch.java b/Term2/_Classwork/Search_and_Sort/NumberSearch.java new file mode 100644 index 0000000..479c6fc --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/NumberSearch.java @@ -0,0 +1,21 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import static java.lang.System.*; + +public class NumberSearch +{ + public static int getNextLargest(int[] numArray, int searchNum) + { + int closest = Integer.MAX_VALUE; + for(int i = 0; i < numArray.length; i++) { + if(numArray[i] > searchNum && (numArray[i]-searchNum < closest-searchNum)) { + closest = numArray[i]; + } + } + return closest; + } +} \ No newline at end of file diff --git a/Term2/_Classwork/Search_and_Sort/NumberSearchRunner.java b/Term2/_Classwork/Search_and_Sort/NumberSearchRunner.java new file mode 100644 index 0000000..42c19d2 --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/NumberSearchRunner.java @@ -0,0 +1,23 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import static java.lang.System.*; + +public class NumberSearchRunner +{ + public static void main( String args[] ) throws IOException + { + int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1}; + int find = 5; + NumberSearch.getNextLargest(array, find); + System.out.println("The next largest value after " + find + " is " + NumberSearch.getNextLargest(array, find) + "\n"); + + //add more case + } +} + + + diff --git a/Term2/_Classwork/Search_and_Sort/NumberShifter.java b/Term2/_Classwork/Search_and_Sort/NumberShifter.java new file mode 100644 index 0000000..91b8748 --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/NumberShifter.java @@ -0,0 +1,30 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import static java.lang.System.*; + +public class NumberShifter +{ + final static int NUM = 7; + public static int[] makeLucky7Array( int size){ + int[] array= new int[size]; + for(int i = 0; i < array.length; i++) { + array[i] = (int) (Math.random()*10 + 1); + } + return array; + } + public static void shiftEm(int[] array){ + int numOf7s = 0; + int temp; + for(int i = 0; i < array.length; i++) { + if(array[i] == NUM) { + array[i] = array[numOf7s]; + array[numOf7s] = NUM; + numOf7s++; + } + } + } +} \ No newline at end of file diff --git a/Term2/_Classwork/Search_and_Sort/NumberShifterRunner.java b/Term2/_Classwork/Search_and_Sort/NumberShifterRunner.java new file mode 100644 index 0000000..ec561a4 --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/NumberShifterRunner.java @@ -0,0 +1,20 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import static java.lang.System.*; + +public class NumberShifterRunner +{ + public static void main( String args[] ) throws IOException + { + int[] arr = NumberShifter.makeLucky7Array(100); + NumberShifter.shiftEm(arr); + System.out.println(Arrays.toString(arr)); + } +} + + + diff --git a/Term2/_Classwork/Search_and_Sort/Sort_Search.pptx b/Term2/_Classwork/Search_and_Sort/Sort_Search.pptx new file mode 100644 index 0000000..4d5bc4e Binary files /dev/null and b/Term2/_Classwork/Search_and_Sort/Sort_Search.pptx differ diff --git a/Term2/_Classwork/Search_and_Sort/WordSort.java b/Term2/_Classwork/Search_and_Sort/WordSort.java new file mode 100644 index 0000000..51d9ec5 --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/WordSort.java @@ -0,0 +1,32 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import static java.lang.System.*; + +public class WordSort +{ + private String[] wordRay; + + public WordSort(String line) + { + setList(line); + } + + public void setList(String line) + { + wordRay = line.split(" "); + } + + public void sort() { + Arrays.sort(wordRay); + } + + public String toString( ) + { + String output = ""; + for(int i = 0; i < wordRay.length; i++) { + output += "word "+i+" :: " + wordRay[i]+"\n"; + } + return output+"\n\n"; + } +} \ No newline at end of file diff --git a/Term2/_Classwork/Search_and_Sort/WordSortRunner.java b/Term2/_Classwork/Search_and_Sort/WordSortRunner.java new file mode 100644 index 0000000..2bed209 --- /dev/null +++ b/Term2/_Classwork/Search_and_Sort/WordSortRunner.java @@ -0,0 +1,15 @@ +package _Classwork.Search_and_Sort; + +import java.util.Arrays; +import static java.lang.System.*; + +public class WordSortRunner +{ + public static void main(String args[]) + { + WordSort sort = new WordSort("test tests"); + sort.setList("123 ABC abc 034 dog cat sally sue bob 2a2"); + sort.sort(); + System.out.println(sort.toString()); + } +} \ No newline at end of file diff --git a/src/interfaces/IArray.java b/src/interfaces/IArray.java new file mode 100644 index 0000000..718de11 --- /dev/null +++ b/src/interfaces/IArray.java @@ -0,0 +1,11 @@ +package interfaces; + +import java.util.*; + +public interface IArray { + public static void add(ArrayList arrayList, Object... object) { + for(int i = 0; i < object.length; i++) { + arrayList.add(object[i]); + } + } +} diff --git a/src/interfaces/IDebug.java b/src/interfaces/IDebug.java new file mode 100644 index 0000000..6078237 --- /dev/null +++ b/src/interfaces/IDebug.java @@ -0,0 +1,43 @@ +package interfaces; + +import java.util.*; + +public interface IDebug { + /** + * println a String + * @param string String to be printed + */ + public static void pl(Object object) { + p(object); + System.out.println(); + } + + /** + * println a String + * @param string String to be printed + */ + public static void p(Object object) { + if(object.getClass().isArray()) { + ArrayException.Error(); + } + else { + System.out.print("*** " + object); + } + } +} +class ArrayException extends Exception{ + ArrayException() {} + ArrayException(String str) + { + super(str); + } + static void Error() { + try { + throw new ArrayException("Can not debug array, please use a for loop to print."); + } + catch (ArrayException e) { + e.printStackTrace(); + System.exit(0); + } + } +} diff --git a/src/interfaces/IGeneral.java b/src/interfaces/IGeneral.java new file mode 100644 index 0000000..5525ed3 --- /dev/null +++ b/src/interfaces/IGeneral.java @@ -0,0 +1,68 @@ +package interfaces; + +import java.util.Scanner; + +public interface IGeneral { + + //COLOR - doesn't work + /*public static final String ANSI_RESET = "\u001B[0m"; + public static final String ANSI_BLACK = "\u001B[30m"; + public static final String ANSI_RED = "\u001B[31m"; + public static final String ANSI_GREEN = "\u001B[32m"; + public static final String ANSI_YELLOW = "\u001B[33m"; + public static final String ANSI_BLUE = "\u001B[34m"; + public static final String ANSI_PURPLE = "\u001B[35m"; + public static final String ANSI_CYAN = "\u001B[36m"; + public static final String ANSI_WHITE = "\u001B[37m";*/ + + public static void main(String[] args) { + System.out.println("Asfasdf"); + } + + //Scanner declare + Scanner scan = new Scanner (System.in); + + + //System.out.print + public static void Print(Object input) { + System.out.print(input); + + } + + //System.out.println + public static void Println(String input) { + System.out.println(input); + + } + + //Scan + public static Object Scan(String dataType) { + if(dataType.compareTo("int")==0) { + int output = scan.nextInt(); + return output; + } + if(dataType.compareTo("String")==0) { + String output = scan.nextLine(); + return output; + } + if(dataType.compareTo("double")==0) { + Double output = scan.nextDouble(); + return output; + } + if(dataType.compareTo("float")==0) { + float output = scan.nextFloat(); + return output; + } + else { + return "ERROR, invalid data type"; + } + } + + + public static void DebugPrint(Object var) { + System.out.println("\t\t" + var); + } + + + +} diff --git a/src/test/java_test.java b/src/test/java_test.java new file mode 100644 index 0000000..28aecc7 --- /dev/null +++ b/src/test/java_test.java @@ -0,0 +1,39 @@ +package test; +import java.util.ArrayList; + +import interfaces.IGeneral; + +public class java_test { + + public static void main(String[] args) { + int[] a = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + int[] a2 = new int[] {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + System.out.println(mystery(a)); + } + + //Lesson 15 Quick Start, Question 2 + //Wrong answer + public static boolean mystery(int[] a) { + boolean flag = false; + for (int i = 1; i < a.length; i++) { + if (a[i] < a[i - 1]) { + flag = true; + break; + } + } + return flag; + } + /* + Nothing, the loop does not access all elements of the array. + Tests if the array is in ascending order. //Edhesive says this is correct + Nothing, the loop does not finish running. + Tests if all values in the array are equal. + Tests if the array is in descending order. + */ + + + + + //quiz 3 toobox quesitons + +} \ No newline at end of file