diff --git a/other/Maps/.gitignore b/other/Maps/.gitignore new file mode 100644 index 0000000..b1001a6 --- /dev/null +++ b/other/Maps/.gitignore @@ -0,0 +1 @@ +.idea/** diff --git a/other/Maps/Maps.iml b/other/Maps/Maps.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/other/Maps/Maps.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/other/Maps/out/production/Maps/Maps.iml b/other/Maps/out/production/Maps/Maps.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/other/Maps/out/production/Maps/Maps.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/other/Maps/out/production/Maps/interpret.dat b/other/Maps/out/production/Maps/interpret.dat new file mode 100644 index 0000000..398706f --- /dev/null +++ b/other/Maps/out/production/Maps/interpret.dat @@ -0,0 +1,15 @@ +function alpha +print (MISSISSIPPI...) +end +function beta +print (TWO) +call alpha +print (THREE) +call alpha +end +function start +print (ONE) +call alpha +call beta +print (GO!) +end \ No newline at end of file diff --git a/other/Maps/out/production/Maps/lab08a.dat b/other/Maps/out/production/Maps/lab08a.dat new file mode 100644 index 0000000..d2da67d --- /dev/null +++ b/other/Maps/out/production/Maps/lab08a.dat @@ -0,0 +1,52 @@ +46 +rearrancar reboot +pantalla screen +texto text +virus virus +tinta ink +mitad half +interno internal +memoria memory +papel paper +energia power +fallo bug +pelo hair +el the +dos two +todas all +en in +de of +los the +comprar buy +tarde afternoon +quieres want +muchachos boys +tienen have +ordenador computer +con with +antes before +vacio empty +tu you +hambre hunger +contaminado corrupt +a to +una a +la the +cafe brown +su your +es is +quiero want +vamos go +mi my +barco ship +nosotros we +casa house +yo i +borrar delete +necesita necessary +despues after +yo quiero una ordenador virus +todas de los muchachos tienen interno memoria +mi pelo es cafe +tu quieres tinta con su papel +rearrancar el ordenador a vacio el pantalla diff --git a/other/Maps/out/production/Maps/lab08b.dat b/other/Maps/out/production/Maps/lab08b.dat new file mode 100644 index 0000000..6d68250 --- /dev/null +++ b/other/Maps/out/production/Maps/lab08b.dat @@ -0,0 +1,5 @@ +a b c d e f g h i a c d e g h i h k +1 2 3 4 5 6 1 2 3 4 5 1 3 1 2 3 4 +Y U I O Q W E R T Y +4 T # @ ^ # # # +c d s r e q w a z d x c d s e e w q s w s w s c x d c x d c x d d d s a a z s s q s q s e e e d d x s z x s x d c d s e e s d s e s e d s x d s e d s r s e d e s d f d e r e s \ No newline at end of file diff --git a/other/Maps/out/production/Maps/lab08c.dat b/other/Maps/out/production/Maps/lab08c.dat new file mode 100644 index 0000000..ed9d1d5 --- /dev/null +++ b/other/Maps/out/production/Maps/lab08c.dat @@ -0,0 +1,16 @@ +14 +Jim Sally +Fred Alice +Jim Tom +Jim Tammy +Bob John +Dot Fred +Dot Tom +Dot Chuck +Bob Tom +Fred James +Timmy Amanda +Almas Brian +Elton Linh +Dot Jason +Dot diff --git a/other/Maps/out/production/Maps/lab08d.dat b/other/Maps/out/production/Maps/lab08d.dat new file mode 100644 index 0000000..ee1e718 --- /dev/null +++ b/other/Maps/out/production/Maps/lab08d.dat @@ -0,0 +1,9 @@ +Water Pump 19934 Ford Taurus 1999 +Air Filter 98765 Chevy Silverado 2002 +Radiator 23102 Dodge Dakota 2001 +Fuel Filter 19967 Ford Taurus 1999 +Wiper Blades 12321 Chevy Camaro 2002 +Water Pump 19912 Ford Expedition 1997 +Water Pump 19934 Ford Taurus 1999 +Air Filter 98765 Chevy Silverado 2002 + diff --git a/other/Maps/out/production/Maps/lab08e.dat b/other/Maps/out/production/Maps/lab08e.dat new file mode 100644 index 0000000..d603c96 --- /dev/null +++ b/other/Maps/out/production/Maps/lab08e.dat @@ -0,0 +1,12 @@ +8 +TSO - Texas State Optical +PDA - Personal Display of Affection +RBI - Runs Batted In +SO - Strike Out +FG - Field Goal +CPU - Central Processing Unit +HD - Hard Drive +PU - Pick Up +I drove my PU to TSO to get a HD. My CPU has a virus. +I sometimes SO when trying to kick a FG. I had 2 RBI +at the game. I saw 2 PDA infractions in the hall. diff --git a/other/Maps/questions/lab08a.doc b/other/Maps/questions/lab08a.doc new file mode 100644 index 0000000..4c397e8 Binary files /dev/null and b/other/Maps/questions/lab08a.doc differ diff --git a/other/Maps/questions/lab08b.doc b/other/Maps/questions/lab08b.doc new file mode 100644 index 0000000..49362fa Binary files /dev/null and b/other/Maps/questions/lab08b.doc differ diff --git a/other/Maps/questions/lab08c.doc b/other/Maps/questions/lab08c.doc new file mode 100644 index 0000000..c320dc2 Binary files /dev/null and b/other/Maps/questions/lab08c.doc differ diff --git a/other/Maps/questions/lab08d.doc b/other/Maps/questions/lab08d.doc new file mode 100644 index 0000000..fe5d413 Binary files /dev/null and b/other/Maps/questions/lab08d.doc differ diff --git a/other/Maps/questions/lab08e.doc b/other/Maps/questions/lab08e.doc new file mode 100644 index 0000000..3e283c5 Binary files /dev/null and b/other/Maps/questions/lab08e.doc differ diff --git a/other/Maps/src/Acronyms.java b/other/Maps/src/Acronyms.java new file mode 100644 index 0000000..ef8c6eb --- /dev/null +++ b/other/Maps/src/Acronyms.java @@ -0,0 +1,54 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAp +//Lab - Maps 08e (Acronyms) + +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static java.lang.System.*; + +public class Acronyms +{ + private Map acronymTable; + + public Acronyms() + { + this.acronymTable = new TreeMap<>(); + } + + public void putEntry(String entry) + { + String[] set = entry.split("\s*-\s*", 2); + this.acronymTable.put(set[0], set[1]); + } + + public String getTranslation(String word) + { + // Compile and execute RegEx pattern + Pattern pattern = Pattern.compile("([.!?;,'\"]*)(\\w+)([.!?;,'\"]*)"); + Matcher match = pattern.matcher(word); + match.find(); + + // Combine original punctuation with translated acronym (or original word, if none found) + return match.group(1) + acronymTable.getOrDefault(match.group(2), match.group(2)) + match.group(3); + } + + public String convert(String sent) + { + return Arrays + .stream(sent.split("\\s+")) + .map(this::getTranslation) + .collect(Collectors.joining(" ")); + } + + public String toString() + { + return this.acronymTable.toString().replace(",", "\n"); + } +} \ No newline at end of file diff --git a/other/Maps/src/Histogram.java b/other/Maps/src/Histogram.java new file mode 100644 index 0000000..08a5b0a --- /dev/null +++ b/other/Maps/src/Histogram.java @@ -0,0 +1,83 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08b (Histogram) + +import java.util.Collections; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + +public class Histogram +{ + private Map histogram; + private int minSpacing; + + public Histogram() + { + histogram = new TreeMap<>(); + } + + public Histogram(String sent, int minSpacing) + { + this(); + this.loadSentence(sent); + this.minSpacing = minSpacing; + } + + public Histogram(String sent) + { + this(sent, 4); + } + + + public void loadSentence(String sent) + { + Scanner scanner = new Scanner(sent); + while (scanner.hasNext()) { + String next = scanner.next(); + // Start with 0 if not found, increment + histogram.put(next, histogram.getOrDefault(next, 0) + 1); + } + } + + public String toString() + { + StringBuilder output = new StringBuilder(); + output + .append("char") + .append(" ".repeat(this.minSpacing)); + + // Get the length of the star header, in 5 char sections + int n = (int) Math.ceil(Collections.max(this.histogram.values()) / 5.0); + n = Math.max(n, 3); // Min 1-15 value markers + + // Base line header + output.append("-".repeat(n * 5)); + + // Place markers + for(int i = 0; i < n; i++) { + int value = Math.max(i * 5, 1); + int index = 4 + this.minSpacing + value - 1; + output.replace(index, index + 2, String.valueOf(value)); + } + + // Trim end line down to last value marker + while(output.charAt(output.length() - 1) == '-') + output.deleteCharAt(output.length() - 1); + + output.append("\n"); + + // For each key in the set, add a line describing the number of stars + for (String key : histogram.keySet()) + output + .append(key) // Character in question + .append(" ".repeat((4 + this.minSpacing) - key.length())) // Minimum spacing + .append("*".repeat(Math.min(histogram.get(key), 100))) // Number of occurrences, max 100 + .append("\n"); + + // Remove trailing newline + return output.substring(0, output.length() - 1); + } +} \ No newline at end of file diff --git a/other/Maps/src/Lab08a.java b/other/Maps/src/Lab08a.java new file mode 100644 index 0000000..3674e46 --- /dev/null +++ b/other/Maps/src/Lab08a.java @@ -0,0 +1,35 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 1st, 2020 +//Class - Computer Science II AP +//Lab - Maps 08a + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +import static java.lang.System.*; + +public class Lab08a +{ + public static void main(String[] args) throws IOException + { + Scanner file = new Scanner(new File("./src/lab08a.dat")); + int lines = file.nextInt(); // Number of entries (before text to translate) + file.nextLine(); + + // Put all spanish/english words inside Map + SpanishToEnglish test = new SpanishToEnglish(); + for (int i = 0; i < lines; i++) + test.putEntry(file.nextLine()); + + + out.println("\n====\tMAP CONTENTS\t====\n\n"); + // Print custom Map wrapper contents + out.println(test + "\n\n"); + + // Translate text + while(file.hasNextLine()) + out.println(test.translate(file.nextLine())); + } +} \ No newline at end of file diff --git a/other/Maps/src/Lab08b.java b/other/Maps/src/Lab08b.java new file mode 100644 index 0000000..120ac1e --- /dev/null +++ b/other/Maps/src/Lab08b.java @@ -0,0 +1,31 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 1st, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08b + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; +import static java.lang.System.out; + +public class Lab08b +{ + public static void main(String[] args) throws IOException + { + Scanner scanner = new Scanner(new File("./src/lab08b.dat")); + + // Read all test cases + while(scanner.hasNextLine()) { + String line = scanner.nextLine(); + + // Process and print histogram + Histogram histogram = new Histogram(line); + out.println(histogram); + + // Print extra two lines between Histograms + if(scanner.hasNextLine()) + out.print("\n\n"); + } + } +} \ No newline at end of file diff --git a/other/Maps/src/Lab08c.java b/other/Maps/src/Lab08c.java new file mode 100644 index 0000000..46996e8 --- /dev/null +++ b/other/Maps/src/Lab08c.java @@ -0,0 +1,33 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08c + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +import static java.lang.System.out; + +public class Lab08c +{ + public static void main(String args[]) throws IOException + { + Scanner scanner = new Scanner(new File("./src/lab08c.dat")); + int lines = scanner.nextInt(); // Number of inputs + scanner.nextLine(); // Flush to next line + + Relatives relatives = new Relatives(); + + // Input all relationships into Relatives object + for (int i = 0; i < lines; i++) + relatives.put(scanner.nextLine()); + + // Print out all relationships asked + while (scanner.hasNextLine()) + out.println(relatives.get(scanner.nextLine())); + + // out.println("\n\n" + relatives); + } +} \ No newline at end of file diff --git a/other/Maps/src/Lab08d.java b/other/Maps/src/Lab08d.java new file mode 100644 index 0000000..0a649e9 --- /dev/null +++ b/other/Maps/src/Lab08d.java @@ -0,0 +1,16 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08d + +import static java.lang.System.out; + +public class Lab08d +{ + public static void main(String[] args) + { + PartList prog = new PartList("lab08d.dat"); + out.println(prog); + } +} diff --git a/other/Maps/src/Lab08e.java b/other/Maps/src/Lab08e.java new file mode 100644 index 0000000..b62e492 --- /dev/null +++ b/other/Maps/src/Lab08e.java @@ -0,0 +1,37 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08e + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +import static java.lang.System.*; + +public class Lab08e +{ + public static void main(String[] args) throws IOException + { + Scanner scanner = new Scanner(new File("./src/lab08e.dat")); + int lines = scanner.nextInt(); // # of input lines + scanner.nextLine(); // Flush input + + // Insert acronym inputs + Acronyms acronyms = new Acronyms(); + for (int i = 0; i < lines; i++) + acronyms.putEntry(scanner.nextLine()); + + + // Print current acronym object state + out.println("==== MAP CONTENTS ====\n\n"); + out.println(acronyms + "\n\n"); + + + // Translate the rest of the input + out.println("==== READ LINES ====\n\n"); + while (scanner.hasNextLine()) + out.println(acronyms.convert(scanner.nextLine())); + } +} \ No newline at end of file diff --git a/other/Maps/src/Maps.iml b/other/Maps/src/Maps.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/other/Maps/src/Maps.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/other/Maps/src/Part.java b/other/Maps/src/Part.java new file mode 100644 index 0000000..4376fbf --- /dev/null +++ b/other/Maps/src/Part.java @@ -0,0 +1,36 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08c (Part) + +public class Part implements Comparable +{ + private String make, mode, rest; + private int year; + + public Part(String line) + { + String[] list = line.split(" "); + + + + + } + + //have to have compareTo if implements Comparable + public int compareTo( Part rhs ) + { + + + + + + return 0; + } + + public String toString() + { + return ""; + } +} \ No newline at end of file diff --git a/other/Maps/src/PartList.java b/other/Maps/src/PartList.java new file mode 100644 index 0000000..1e27135 --- /dev/null +++ b/other/Maps/src/PartList.java @@ -0,0 +1,37 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08c (PartList) + +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.TreeMap; +import java.util.Scanner; +import static java.lang.System.*; + +public class PartList +{ + private Map partsMap; + + public PartList() + { + this.partsMap = new TreeMap<>(); + } + + public PartList(String fileName) + { + this(); + } + + public String toString() + { + String output=""; + + + + + return output; + } +} \ No newline at end of file diff --git a/other/Maps/src/Relatives.java b/other/Maps/src/Relatives.java new file mode 100644 index 0000000..9daa162 --- /dev/null +++ b/other/Maps/src/Relatives.java @@ -0,0 +1,55 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 2nd, 2020 +//Class - Computer Science II PreAP +//Lab - Maps 08c (Relatives) + +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.stream.Collectors; + +public class Relatives +{ + private Map> map; + + public Relatives() + { + this.map = new TreeMap<>(); + } + + public void put(String line) + { + String[] relation = line.split(" "); + + // Ensure Set exists for parent relative + if (!this.map.containsKey(relation[0])) + this.map.put(relation[0], new TreeSet<>()); + + // Add relationship + this.map.get(relation[0]).add(relation[1]); + } + + + public String get(String person) + { + return String.format( + "%s is related to %s", + person, + String.join(" ", this.map.get(person)) + ); + } + + + // Using all keys within the map, turn it into a stream which is mapped to the + // getRelatives function, and join into a String by line breaks + public String toString() + { + return this.map + .keySet() + .stream() + .map(this::get) + .collect(Collectors.joining("\n")); + } +} \ No newline at end of file diff --git a/other/Maps/src/SpanishToEnglish.java b/other/Maps/src/SpanishToEnglish.java new file mode 100644 index 0000000..a3a6b6c --- /dev/null +++ b/other/Maps/src/SpanishToEnglish.java @@ -0,0 +1,46 @@ +//© A+ Computer Science - www.apluscompsci.com +//Name - Ryan Walters +//Date - October 1st, 2020 +//Class - Computer Science II AP +//Lab - Maps 08a (SpanishToEnglish) + +import java.util.*; + +public class SpanishToEnglish +{ + private Map pairs; + + public SpanishToEnglish() + { + pairs = new TreeMap<>(); + } + + public void putEntry(String entry) + { + // Split and place inside Map + String[] list = entry.split("\\w+"); + pairs.put(list[0], list[1]); + } + + public String translate(String sent) + { + ArrayList words = new ArrayList<>(); + Scanner chop = new Scanner(sent); + + // Translate each word in the dictionary, + // otherwise default to the original word if not present. + while (chop.hasNext()) { + String next = chop.next(); + words.add(pairs.getOrDefault(next, next)); + } + + // Join all owrds into single string with single space + return String.join(" ", words); + } + + public String toString() + { + // Use Maps .toString, but replace commas with newlines + return pairs.toString().replaceAll(",", "\n"); + } +} \ No newline at end of file diff --git a/other/Maps/src/interpret.dat b/other/Maps/src/interpret.dat new file mode 100644 index 0000000..398706f --- /dev/null +++ b/other/Maps/src/interpret.dat @@ -0,0 +1,15 @@ +function alpha +print (MISSISSIPPI...) +end +function beta +print (TWO) +call alpha +print (THREE) +call alpha +end +function start +print (ONE) +call alpha +call beta +print (GO!) +end \ No newline at end of file diff --git a/other/Maps/src/lab08a.dat b/other/Maps/src/lab08a.dat new file mode 100644 index 0000000..d2da67d --- /dev/null +++ b/other/Maps/src/lab08a.dat @@ -0,0 +1,52 @@ +46 +rearrancar reboot +pantalla screen +texto text +virus virus +tinta ink +mitad half +interno internal +memoria memory +papel paper +energia power +fallo bug +pelo hair +el the +dos two +todas all +en in +de of +los the +comprar buy +tarde afternoon +quieres want +muchachos boys +tienen have +ordenador computer +con with +antes before +vacio empty +tu you +hambre hunger +contaminado corrupt +a to +una a +la the +cafe brown +su your +es is +quiero want +vamos go +mi my +barco ship +nosotros we +casa house +yo i +borrar delete +necesita necessary +despues after +yo quiero una ordenador virus +todas de los muchachos tienen interno memoria +mi pelo es cafe +tu quieres tinta con su papel +rearrancar el ordenador a vacio el pantalla diff --git a/other/Maps/src/lab08b.dat b/other/Maps/src/lab08b.dat new file mode 100644 index 0000000..6d68250 --- /dev/null +++ b/other/Maps/src/lab08b.dat @@ -0,0 +1,5 @@ +a b c d e f g h i a c d e g h i h k +1 2 3 4 5 6 1 2 3 4 5 1 3 1 2 3 4 +Y U I O Q W E R T Y +4 T # @ ^ # # # +c d s r e q w a z d x c d s e e w q s w s w s c x d c x d c x d d d s a a z s s q s q s e e e d d x s z x s x d c d s e e s d s e s e d s x d s e d s r s e d e s d f d e r e s \ No newline at end of file diff --git a/other/Maps/src/lab08c.dat b/other/Maps/src/lab08c.dat new file mode 100644 index 0000000..ed9d1d5 --- /dev/null +++ b/other/Maps/src/lab08c.dat @@ -0,0 +1,16 @@ +14 +Jim Sally +Fred Alice +Jim Tom +Jim Tammy +Bob John +Dot Fred +Dot Tom +Dot Chuck +Bob Tom +Fred James +Timmy Amanda +Almas Brian +Elton Linh +Dot Jason +Dot diff --git a/other/Maps/src/lab08d.dat b/other/Maps/src/lab08d.dat new file mode 100644 index 0000000..ee1e718 --- /dev/null +++ b/other/Maps/src/lab08d.dat @@ -0,0 +1,9 @@ +Water Pump 19934 Ford Taurus 1999 +Air Filter 98765 Chevy Silverado 2002 +Radiator 23102 Dodge Dakota 2001 +Fuel Filter 19967 Ford Taurus 1999 +Wiper Blades 12321 Chevy Camaro 2002 +Water Pump 19912 Ford Expedition 1997 +Water Pump 19934 Ford Taurus 1999 +Air Filter 98765 Chevy Silverado 2002 + diff --git a/other/Maps/src/lab08e.dat b/other/Maps/src/lab08e.dat new file mode 100644 index 0000000..d603c96 --- /dev/null +++ b/other/Maps/src/lab08e.dat @@ -0,0 +1,12 @@ +8 +TSO - Texas State Optical +PDA - Personal Display of Affection +RBI - Runs Batted In +SO - Strike Out +FG - Field Goal +CPU - Central Processing Unit +HD - Hard Drive +PU - Pick Up +I drove my PU to TSO to get a HD. My CPU has a virus. +I sometimes SO when trying to kick a FG. I had 2 RBI +at the game. I saw 2 PDA infractions in the hall.