From 1c6d704b0c12160b77e5fd230970dd4195630c05 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 20 Jan 2021 06:57:22 -0500 Subject: [PATCH] Update: 2021-Jan-20 --- .gitignore | 2 + lab-9/triangle-area/Triangle.class | Bin 884 -> 0 bytes lab_txt_msg_expander/txt_msg_expander.java | 44 ++++++++++++++++++ .../part-1/ItemToPurchase.java | 0 .../part-1/ShoppingCartPrinter.java | 0 .../part-2/ItemToPurchase.java | 0 .../part-2/ShoppingCart.java | 0 .../part-2/ShoppingCartManager.java | 0 .../java1/brute-force}/main.java | 0 .../java1/brute-force}/test.java | 0 .../java1/contians-character}/LabProgram.java | 0 .../java1/contians-character}/confused.java | 0 .../java1/elements-in-range}/LabProgram.java | 0 old/java1/exam/another_wut.java | 16 +++++++ old/java1/exam/wut.java | 20 ++++++++ .../FoodItem.java | 0 .../NutritionalInfo.java | 0 .../lab-12/12.6-eception/NameAgeChecker.java | 27 +++++++++++ .../lab-8}/8.33.1-turn-exp/LabProgram.java | 0 .../8.37-even-odd-in-array/LabProgram.java | 0 .../8.39.1-sort-an-array/LabProgram.java | 0 .../8.42.1-WordFrequencies/LabProgram.java | 0 .../java1/lab-9}/fallingCarValue/Car.java | 0 .../lab-9}/fallingCarValue/CarValue.java | 0 .../java1/lab-9}/stupid-teams/Team.java | 0 .../lab-9}/stupid-teams/WinningTeam.java | 0 .../java1/lab-9}/triangle-area/Triangle.java | 0 .../lab-9}/triangle-area/TriangleArea.java | 0 .../output-numbers-in-reverse}/main.java | 0 .../java1/word-frequencies}/LabProgram.java | 0 painting-a-wall/painting_a_wall.java | 29 ++++++++++++ palindrome/palindrome.java | 26 +++++++++++ word-freq/wordFreq.java | 44 ++++++++++++++++++ 33 files changed, 208 insertions(+) create mode 100644 .gitignore delete mode 100644 lab-9/triangle-area/Triangle.class create mode 100644 lab_txt_msg_expander/txt_msg_expander.java rename {Week-11-final-start => old/java1/Week-11-final-start}/part-1/ItemToPurchase.java (100%) rename {Week-11-final-start => old/java1/Week-11-final-start}/part-1/ShoppingCartPrinter.java (100%) rename {Week-11-final-start => old/java1/Week-11-final-start}/part-2/ItemToPurchase.java (100%) rename {Week-11-final-start => old/java1/Week-11-final-start}/part-2/ShoppingCart.java (100%) rename {Week-11-final-start => old/java1/Week-11-final-start}/part-2/ShoppingCartManager.java (100%) rename {brute-force => old/java1/brute-force}/main.java (100%) rename {brute-force => old/java1/brute-force}/test.java (100%) rename {contians-character => old/java1/contians-character}/LabProgram.java (100%) rename {contians-character => old/java1/contians-character}/confused.java (100%) rename {elements-in-range => old/java1/elements-in-range}/LabProgram.java (100%) create mode 100644 old/java1/exam/another_wut.java create mode 100644 old/java1/exam/wut.java rename {lab-10 => old/java1/lab-10}/10.13.1-Nutritional-Information/FoodItem.java (100%) rename {lab-10 => old/java1/lab-10}/10.13.1-Nutritional-Information/NutritionalInfo.java (100%) create mode 100644 old/java1/lab-12/12.6-eception/NameAgeChecker.java rename {lab-8 => old/java1/lab-8}/8.33.1-turn-exp/LabProgram.java (100%) rename {lab-8 => old/java1/lab-8}/8.37-even-odd-in-array/LabProgram.java (100%) rename {lab-8 => old/java1/lab-8}/8.39.1-sort-an-array/LabProgram.java (100%) rename {lab-8 => old/java1/lab-8}/8.42.1-WordFrequencies/LabProgram.java (100%) rename {lab-9 => old/java1/lab-9}/fallingCarValue/Car.java (100%) rename {lab-9 => old/java1/lab-9}/fallingCarValue/CarValue.java (100%) rename {lab-9 => old/java1/lab-9}/stupid-teams/Team.java (100%) rename {lab-9 => old/java1/lab-9}/stupid-teams/WinningTeam.java (100%) rename {lab-9 => old/java1/lab-9}/triangle-area/Triangle.java (100%) rename {lab-9 => old/java1/lab-9}/triangle-area/TriangleArea.java (100%) rename {output-numbers-in-reverse => old/java1/output-numbers-in-reverse}/main.java (100%) rename {word-frequencies => old/java1/word-frequencies}/LabProgram.java (100%) create mode 100644 painting-a-wall/painting_a_wall.java create mode 100644 palindrome/palindrome.java create mode 100644 word-freq/wordFreq.java 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 47e42e2edee84ffc7ff26f67de735eab8630f139..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 884 zcmZuvZBNrs7(I6#>&v<^2a0bfg19kpQ+!Jt(WsMPLWE>QWBkz=Vjs=<_#?9 zxNcz)H!PG;Hn3!%Vv%@L$Fe}WrQ6vJxLI{QH+U?dm6u+V^4xz<%H)RY z$yZ^&B?sG1t4Bm1%HUZfPnR2tX%bjZO!STno(`lFxzOGGFmS!#rPuZatfn6hcI29? zTyon3*YP?%S?xOej*TLwY)qnH;|vNqZrP}!CXiK~9?dOQSK5|9L2+w6>S~*HQ>S<_? zJI_A>NbzQV(T)*voq$lWvQG19ma9-`hSU+) zVhg31fKKN5)A`y-zDd4CKC@5!mywSA3)4tfz9O~9qV27hKG8j%D(;ly(egwtjSkU` zIs_-N81Cj!HoVW%oHc)@H0E)z>( F_CElUpuqqD 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