Initial Commit

This commit is contained in:
2022-10-07 00:44:12 -03:00
commit 8ff85da81c
308 changed files with 10106 additions and 0 deletions

8
Source Code/Assignment 11/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 11\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 11.iml" filepath="$PROJECT_DIR$/Assignment 11.iml" />
</modules>
</component>
</project>

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,6 @@
Elizabeth Anne Flynn
Sarah Blair
Abe Corey
Blair Elliot
COREY FLYNN
anne blair

View File

@ -0,0 +1 @@
Elizabeth

View File

@ -0,0 +1,10 @@
Elizabeth Anne Flynn
Sarah Blair
Abe Corey
Blair Elliot
COREY FLYNN
anne blair
isaac ray avery
spencer adam
genna
Abcde

View File

@ -0,0 +1,23 @@
import java.io.*;
public class NameCountDriver{
public static void main(String[] args){
if(args.length < 1){
System.out.println("Usage: java CharCountDriver file");
return;
}
try{
NameCountTree tree = new NameCountTree();
tree.readText(args[0]);
tree.print();
System.out.println("Minimum entry in tree: ");
tree.printMin();
}
catch(IOException e){
System.out.println("Unable to read file");
}
}
}

View File

@ -0,0 +1,159 @@
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
/**
* Class that represents a binary tree of names sorted alphabetically
* @author Isaac Shoebottom (3429069)
*/
public class NameCountTree {
/**
* Root node, one at the top of the binary tree
*/
private Node root;
/**
* Public method for initiating addition to the tree
* @param valueIn String which represents the name
*/
public void add(String valueIn) {
if (root == null) {
root = new Node(new Pair(valueIn));
}
else {
add(valueIn, root);
}
}
/**
* Private method that recursively adds to the tree
* @param valueIn String that represents the name
* @param root The node that should be the new root for searching where to add the new node
*/
private void add(String valueIn, Node root) {
if (valueIn.equalsIgnoreCase(root.info.name)) {
root.info.count++;
}
else if (valueIn.compareToIgnoreCase(root.info.name) < 0) {
if (root.left == null) {
root.left = new Node(new Pair(valueIn));
}
else {
add(valueIn, root.left);
}
}
else {
if (root.right == null) {
root.right = new Node(new Pair(valueIn));
}
else {
add(valueIn, root.right);
}
}
}
/**
* Method for reading the input from a file
* @param filename String The name of the file to be read
* @throws IOException If the file does not exist
*/
public void readText(String filename) throws IOException {
Scanner sc = new Scanner(new File(filename));
while (sc.hasNext()) {
add(sc.next().toLowerCase());
}
}
/**
* Method to initiate a print of the tree
*/
public void print() {
print(root);
}
/**
* Private method that recursively prints the tree. Relies on that the tree is sorted alphabetically already
* @param root The node that is to be treated as root
*/
private void print(Node root) {
if (root != null) {
print(root.left);
System.out.println(root.info.toString());
print(root.right);
}
}
/**
* Method to print the smallest node alphabetically
*/
public void printMin() {
//in case of empty file
if (root != null) {
Node temp = root;
while (temp.left != null) {
temp = temp.left;
}
System.out.print(temp.info.toString());
}
}
/**
* Node class represents a node containing the left right and pair of information
*/
static class Node {
/**
* The left node to current node
*/
private Node left;
/**
* The right node to current node
*/
private Node right;
/**
* The info in the current node
*/
private final Pair info;
/**
* The constructor for a node
* @param info Takes in a pair and constructs a node out of it
*/
Node (Pair info) {
this.info = info;
}
}
/**
* Class that represents a pair of data, the name and count of how many of that name in the tree
*/
static private class Pair {
/**
* The name in the pair
*/
private final String name;
/**
* The count of how many of that name are in the tree
*/
private int count = 1;
/**
* The constructor for the pair
* @param name String of the name of the pair
*/
Pair(String name) {
this.name = name;
}
/**
* Reimplementation of toString to not reference the memory pointer but the contents of the class
* @return The string containing the name and count
*/
public String toString(){
return "(" + name + ", " + count + ")";
}
}
}