Maps questions, data and programs finished

This commit is contained in:
Xevion
2020-11-24 00:23:34 -06:00
parent e0b6224003
commit ac2e42f06f
32 changed files with 715 additions and 0 deletions

1
other/Maps/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea/**

11
other/Maps/Maps.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -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<String, String> 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");
}
}

View File

@@ -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<String, Integer> 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);
}
}

View File

@@ -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()));
}
}

View File

@@ -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");
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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()));
}
}

11
other/Maps/src/Maps.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

36
other/Maps/src/Part.java Normal file
View File

@@ -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<Part>
{
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 "";
}
}

View File

@@ -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<Part, Integer> partsMap;
public PartList()
{
this.partsMap = new TreeMap<>();
}
public PartList(String fileName)
{
this();
}
public String toString()
{
String output="";
return output;
}
}

View File

@@ -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<String, Set<String>> 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"));
}
}

View File

@@ -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<String, String> 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<String> 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");
}
}

View File

@@ -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

52
other/Maps/src/lab08a.dat Normal file
View File

@@ -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

View File

@@ -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

16
other/Maps/src/lab08c.dat Normal file
View File

@@ -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

View File

@@ -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

12
other/Maps/src/lab08e.dat Normal file
View File

@@ -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.