diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fad32f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.class diff --git a/lab-9/triangle-area/Triangle.class b/lab-9/triangle-area/Triangle.class deleted file mode 100644 index 47e42e2..0000000 Binary files a/lab-9/triangle-area/Triangle.class and /dev/null differ diff --git a/lab_txt_msg_expander/txt_msg_expander.java b/lab_txt_msg_expander/txt_msg_expander.java new file mode 100644 index 0000000..298edb6 --- /dev/null +++ b/lab_txt_msg_expander/txt_msg_expander.java @@ -0,0 +1,44 @@ +import java.util.Scanner; + +public class txt_msg_expander { + + public static String replaceText(String input, + String replaceThis, + String withThis) { + System.out.println("Replaced \"" +replaceThis + "\" with \"" + + withThis + "\""); + return input.replace(replaceThis, withThis); + } + + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + System.out.println("Enter text:"); + String usr_input = scnr.nextLine(); + System.out.println("You entered: " + usr_input+"\n"); + + if (usr_input.contains("BFF")){ + usr_input = replaceText(usr_input, "BFF", "best friend forever"); + } + + if (usr_input.contains("IDK")){ + usr_input = replaceText(usr_input, "IDK", "I don't know"); + } + + if (usr_input.contains("JK")){ + usr_input = replaceText(usr_input, "JK", "just kidding"); + } + + if (usr_input.contains("TMI")){ + usr_input = replaceText(usr_input, "TMI", "too much information"); + } + + if (usr_input.contains("TTYL")){ + usr_input = replaceText(usr_input, "TTYL", "talk to you later"); + } + + System.out.println("\nExpanded: " + usr_input); + + scnr.close(); + } +} diff --git a/Week-11-final-start/part-1/ItemToPurchase.java b/old/java1/Week-11-final-start/part-1/ItemToPurchase.java similarity index 100% rename from Week-11-final-start/part-1/ItemToPurchase.java rename to old/java1/Week-11-final-start/part-1/ItemToPurchase.java diff --git a/Week-11-final-start/part-1/ShoppingCartPrinter.java b/old/java1/Week-11-final-start/part-1/ShoppingCartPrinter.java similarity index 100% rename from Week-11-final-start/part-1/ShoppingCartPrinter.java rename to old/java1/Week-11-final-start/part-1/ShoppingCartPrinter.java diff --git a/Week-11-final-start/part-2/ItemToPurchase.java b/old/java1/Week-11-final-start/part-2/ItemToPurchase.java similarity index 100% rename from Week-11-final-start/part-2/ItemToPurchase.java rename to old/java1/Week-11-final-start/part-2/ItemToPurchase.java diff --git a/Week-11-final-start/part-2/ShoppingCart.java b/old/java1/Week-11-final-start/part-2/ShoppingCart.java similarity index 100% rename from Week-11-final-start/part-2/ShoppingCart.java rename to old/java1/Week-11-final-start/part-2/ShoppingCart.java diff --git a/Week-11-final-start/part-2/ShoppingCartManager.java b/old/java1/Week-11-final-start/part-2/ShoppingCartManager.java similarity index 100% rename from Week-11-final-start/part-2/ShoppingCartManager.java rename to old/java1/Week-11-final-start/part-2/ShoppingCartManager.java diff --git a/brute-force/main.java b/old/java1/brute-force/main.java similarity index 100% rename from brute-force/main.java rename to old/java1/brute-force/main.java diff --git a/brute-force/test.java b/old/java1/brute-force/test.java similarity index 100% rename from brute-force/test.java rename to old/java1/brute-force/test.java diff --git a/contians-character/LabProgram.java b/old/java1/contians-character/LabProgram.java similarity index 100% rename from contians-character/LabProgram.java rename to old/java1/contians-character/LabProgram.java diff --git a/contians-character/confused.java b/old/java1/contians-character/confused.java similarity index 100% rename from contians-character/confused.java rename to old/java1/contians-character/confused.java diff --git a/elements-in-range/LabProgram.java b/old/java1/elements-in-range/LabProgram.java similarity index 100% rename from elements-in-range/LabProgram.java rename to old/java1/elements-in-range/LabProgram.java diff --git a/old/java1/exam/another_wut.java b/old/java1/exam/another_wut.java new file mode 100644 index 0000000..ae8bca5 --- /dev/null +++ b/old/java1/exam/another_wut.java @@ -0,0 +1,16 @@ +public class Widget { + private int inStock; + public Widget() { + inStock = 10; + } + public void addInventory(int amt) { + inStock = inStock + amt; + } + public static void main(String [] args){ + Widget blueWidget = new Widget(); + Widget greenWidget = new Widget(); + blueWidget.addInventory(15); + greenWidget.addInventory(5); + } +} + diff --git a/old/java1/exam/wut.java b/old/java1/exam/wut.java new file mode 100644 index 0000000..6c3eb61 --- /dev/null +++ b/old/java1/exam/wut.java @@ -0,0 +1,20 @@ +public class Student { + private double myGPA; + private int myCredits; + + public void increaseCredits(int amount) { + myCredits = myCredits + amount; + } + public void setCredits(int credits) { + myCredits = credits; + } + public int getCredits() { + return myCredits; + } + public static void main(String [] args) { + Student s = new Student(); + s.setCredits(6); + s.increaseCredits(12); + System.out.println(s.getCredits()); + } +} diff --git a/lab-10/10.13.1-Nutritional-Information/FoodItem.java b/old/java1/lab-10/10.13.1-Nutritional-Information/FoodItem.java similarity index 100% rename from lab-10/10.13.1-Nutritional-Information/FoodItem.java rename to old/java1/lab-10/10.13.1-Nutritional-Information/FoodItem.java diff --git a/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java b/old/java1/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java similarity index 100% rename from lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java rename to old/java1/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java diff --git a/old/java1/lab-12/12.6-eception/NameAgeChecker.java b/old/java1/lab-12/12.6-eception/NameAgeChecker.java new file mode 100644 index 0000000..59340e3 --- /dev/null +++ b/old/java1/lab-12/12.6-eception/NameAgeChecker.java @@ -0,0 +1,27 @@ +import java.util.Scanner; +import java.util.InputMismatchException; + +public class NameAgeChecker { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + String inputName; + int age; + + inputName = scnr.next(); + while (!inputName.equals("-1")) { + // FIXME: The following line will throw an InputMismatchException. + // Insert a try/catch statement to catch the exception. + try { + age = scnr.nextInt(); + } + catch (InputMismatchException e){ + age = -1; + scnr.nextLine(); + } + System.out.println(inputName + " " + (age + 1)); + + inputName = scnr.next(); + } + } +} diff --git a/lab-8/8.33.1-turn-exp/LabProgram.java b/old/java1/lab-8/8.33.1-turn-exp/LabProgram.java similarity index 100% rename from lab-8/8.33.1-turn-exp/LabProgram.java rename to old/java1/lab-8/8.33.1-turn-exp/LabProgram.java diff --git a/lab-8/8.37-even-odd-in-array/LabProgram.java b/old/java1/lab-8/8.37-even-odd-in-array/LabProgram.java similarity index 100% rename from lab-8/8.37-even-odd-in-array/LabProgram.java rename to old/java1/lab-8/8.37-even-odd-in-array/LabProgram.java diff --git a/lab-8/8.39.1-sort-an-array/LabProgram.java b/old/java1/lab-8/8.39.1-sort-an-array/LabProgram.java similarity index 100% rename from lab-8/8.39.1-sort-an-array/LabProgram.java rename to old/java1/lab-8/8.39.1-sort-an-array/LabProgram.java diff --git a/lab-8/8.42.1-WordFrequencies/LabProgram.java b/old/java1/lab-8/8.42.1-WordFrequencies/LabProgram.java similarity index 100% rename from lab-8/8.42.1-WordFrequencies/LabProgram.java rename to old/java1/lab-8/8.42.1-WordFrequencies/LabProgram.java diff --git a/lab-9/fallingCarValue/Car.java b/old/java1/lab-9/fallingCarValue/Car.java similarity index 100% rename from lab-9/fallingCarValue/Car.java rename to old/java1/lab-9/fallingCarValue/Car.java diff --git a/lab-9/fallingCarValue/CarValue.java b/old/java1/lab-9/fallingCarValue/CarValue.java similarity index 100% rename from lab-9/fallingCarValue/CarValue.java rename to old/java1/lab-9/fallingCarValue/CarValue.java diff --git a/lab-9/stupid-teams/Team.java b/old/java1/lab-9/stupid-teams/Team.java similarity index 100% rename from lab-9/stupid-teams/Team.java rename to old/java1/lab-9/stupid-teams/Team.java diff --git a/lab-9/stupid-teams/WinningTeam.java b/old/java1/lab-9/stupid-teams/WinningTeam.java similarity index 100% rename from lab-9/stupid-teams/WinningTeam.java rename to old/java1/lab-9/stupid-teams/WinningTeam.java diff --git a/lab-9/triangle-area/Triangle.java b/old/java1/lab-9/triangle-area/Triangle.java similarity index 100% rename from lab-9/triangle-area/Triangle.java rename to old/java1/lab-9/triangle-area/Triangle.java diff --git a/lab-9/triangle-area/TriangleArea.java b/old/java1/lab-9/triangle-area/TriangleArea.java similarity index 100% rename from lab-9/triangle-area/TriangleArea.java rename to old/java1/lab-9/triangle-area/TriangleArea.java diff --git a/output-numbers-in-reverse/main.java b/old/java1/output-numbers-in-reverse/main.java similarity index 100% rename from output-numbers-in-reverse/main.java rename to old/java1/output-numbers-in-reverse/main.java diff --git a/word-frequencies/LabProgram.java b/old/java1/word-frequencies/LabProgram.java similarity index 100% rename from word-frequencies/LabProgram.java rename to old/java1/word-frequencies/LabProgram.java diff --git a/painting-a-wall/painting_a_wall.java b/painting-a-wall/painting_a_wall.java new file mode 100644 index 0000000..7e61fa2 --- /dev/null +++ b/painting-a-wall/painting_a_wall.java @@ -0,0 +1,29 @@ +import java.util.Scanner; + +public class painting_a_wall { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + double height, width; + final double square_feet_per_gallon = 350; + + System.out.println("Enter wall height (feet):"); + height = scnr.nextDouble(); + + System.out.println("Enter wall width (feet):"); + width = scnr.nextDouble(); + + System.out.println("Wall area: " + height*width + + " square feet"); + + System.out.println("Paint needed: " + + (height*width)/square_feet_per_gallon + + " gallons"); + + System.out.println("Cans needed: " + + (int)Math.ceil((height*width)/square_feet_per_gallon)+ + " can(s)"); + + scnr.close(); + } +} diff --git a/palindrome/palindrome.java b/palindrome/palindrome.java new file mode 100644 index 0000000..710390a --- /dev/null +++ b/palindrome/palindrome.java @@ -0,0 +1,26 @@ +import java.util.Scanner; +import java.lang.StringBuffer; + +public class palindrome { + + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + System.out.println("Enter text:"); + String usrInput = scnr.nextLine(); + System.out.println(); + String reverseUsrInput; + + usrInput = usrInput.replace(" ", ""); + reverseUsrInput = new StringBuffer(usrInput).reverse().toString(); + + if (usrInput.equals(reverseUsrInput)){ + System.out.println(usrInput + " is a palindrome"); + } + else { + System.out.println(usrInput + " is not a palindrome"); + } + + scnr.close(); + } +} diff --git a/word-freq/wordFreq.java b/word-freq/wordFreq.java new file mode 100644 index 0000000..f8b048c --- /dev/null +++ b/word-freq/wordFreq.java @@ -0,0 +1,44 @@ +import java.util.Scanner; + +/* + * input: 5 hey hi Mark hi mark + * output: + * hey 1 + * hi 2 + * Mark 1 + * hi 2 + * mark 1 + * + * assume input will always be less than 20 words + * hint: Use two arrays, one array for strings + * one array for frequencies + */ + + +public class wordFreq { + + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + String[] words = new String[20]; + int[] frequencies = new int[20]; + + int numberOfWords = scnr.nextInt(); + + for (int i=0; i