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 7/.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 7\.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,36 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="return,param" />
</inspection_tool>
</profile>
</component>

6
Source Code/Assignment 7/.idea/misc.xml generated Normal file
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 7.iml" filepath="$PROJECT_DIR$/Assignment 7.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,59 @@
import java.util.ArrayList;
/**
A utility class that provide methods to compute elements of the
recursive sequence.
@author Leah Bidlake, Isaac Shoebottom (3429069)
*/
public class Seq{
/**
Recursively computes seq(n).
@param n Non-negative integer.
@return int Element n in the recursive sequence.
*/
private static ArrayList<Integer> cache;
public static int seqR(int n){
if (n == 0)
return 1;
if (n == 1)
return 5;
return seqR(n-1) + seqR(n-2);
}
/**
* Sequence calculator using an memoization cache
* @param n The digit the sequence is to be calculated to
* @return The number in the sequence n refers to
*/
public static int seqM(int n){
if (cache == null) {
cache = new ArrayList<>();
cache.add(1);
cache.add(5);
}
if (cache.size() <= n)
cache.add(seqM(n-1) + seqM( n-2));
return cache.get(n);
}
/**
* Sequence calculator using an iterative approach
* @param n The digit the sequence is to be calculated to
* @return The number in the sequence n refers to
*/
public static int seqI(int n){
int[] cache = new int[n+2]; //n+2 so seqI(0) is not out of bounds
cache[0] = 1;
cache[1] = 5;
for(int i = 2; i <= n; i++) { //i = 2 because we need to skip the first two array items
cache[i] = cache[i-1] + cache[i-2];
}
return cache[n];
}
}

View File

@ -0,0 +1,59 @@
import java.text.NumberFormat;
import java.util.Scanner;
/**
A simple driver that uses the Seq class to compute the
nth element of the sequence.
@author Isaac Shoebottom (3429069)
*/
public class TestSeq{
public static void main(String[] args){
int n, seqRec, seqMem, seqIter;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a positive integer: ");
n = scan.nextInt();
seqRec = Seq.seqR(n);
seqMem = Seq.seqM(n);
seqIter = Seq.seqI(n);
System.out.println("seqR(" + n + ") is: " + seqRec);
System.out.println("seqM(" + n + ") is: " + seqMem);
System.out.println("seqI(" + n + ") is: " + seqIter);
NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(7);
form.setMinimumFractionDigits(7);
System.out.println();
System.out.println("Execution Times in Milliseconds (ms)");
System.out.println("Seq(n) \tRecursive \tMemoization \tItertive");
long start, end;
int seqA;
double time;
for(int i = 20; i <= 40; i+=10){
start = System.nanoTime();
seqA = Seq.seqR(i);
end = System.nanoTime();
time = (double)(end-start)/1000000;
System.out.print(i + "\t" + form.format(time));
start = System.nanoTime();
seqA = Seq.seqM(i);
end = System.nanoTime();
time = (double)(end-start)/1000000;
System.out.print(i + "\t" + form.format(time));
start = System.nanoTime();
seqA = Seq.seqI(i);
end = System.nanoTime();
time = (double)(end-start)/1000000;
System.out.print(i + "\t" + form.format(time));
System.out.println();
}
}
}