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 6 (Ben)/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../:\User\Isaac\Desktop\Test\.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="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$/Test.iml" filepath="$PROJECT_DIR$/Test.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,11 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
public class CharsetTester {
public static void main(String[] args) {
OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream());
String enc = writer.getEncoding();
System.out.println(enc);
System.out.println(Charset.defaultCharset());
}
}

View File

@ -0,0 +1,128 @@
import java.io.*;
import java.util.Scanner;
import java.util.NoSuchElementException;
/**
Represents a temperature parser object.
@author Ben Fanjoy 3635146
*/
public class TemperatureParser {
/**
Creates a scanner object.
*/
Scanner sc;
/**
The column in which the header is "Date/Time (LST)".
*/
private int dateCol;
/**
The column in which the header is "Temp (°C)".
*/
private int tempCol;
/**
Used to store the date for the line that is currently being parsed.
*/
private String date;
/**
Used to store the tmeperature for the line that is currently being parsed.
*/
private double temp;
/**
Constructs a temperature parser using a specific file as input.
@param filename The name of the input file.
*/
public TemperatureParser (String filename) throws FileNotFoundException{
try {
sc = new Scanner (new File(filename));
}
catch (FileNotFoundException e) {
System.out.println("File not found.");
System.exit(1);
}
sc.useDelimiter(",");
boolean foundDate = false;
boolean foundTemp = false;
String header = sc.next();
int count = 1;
while (sc.hasNext() && (foundDate == false || foundTemp == false)) {
header = sc.next();
if (header.equals("\"Date/Time (LST)\"")) {
dateCol = count;
count++;
foundDate = true;
}
else if (header.equals("\"Temp (°C)\"")) {
tempCol = count;
count++;
foundTemp = true;
}
else {
count++;
}
}
sc.nextLine();
}
/**
Method for parsing the next line in the file.
*/
public void parseLine() throws NoSuchElementException{
String line = sc.nextLine();
Scanner scan = new Scanner (line);
scan.useDelimiter("\",\"");
for (int i = 0; i < dateCol; i++) {
scan.next();
}
date = scan.next();
for (int i = tempCol - dateCol; i > 1; i--) {
scan.next();
}
try {
temp = Double.parseDouble(scan.next());
}
catch (NumberFormatException e) {
System.out.println("Invalid entry at " + date);
}
catch (NoSuchElementException e) {
System.out.println("Invalid entry at " + date);
}
}
/**
Accesses the date for the current line.
@return The date for the current line.
*/
public String getDate () {
return date;
}
/**
Accesses the temperature for the current line.
@return The temperature for the current line.
*/
public double getTemp () {
return temp;
}
/**
Determines whether or not the file has a next line.
@return Whether or not the file has a next line.
*/
public boolean hasNextLine () {
if (sc.hasNextLine() || sc.hasNext()) {
return true;
}
else {
return false;
}
}
}

View File

@ -0,0 +1,52 @@
import java.io.*;
import java.util.Scanner;
public class TemperatureStats {
public static void main(String[] args) throws FileNotFoundException {
double tempMin = 0;
String tempMinDate = "";
double tempMax = 0;
String tempMaxDate = "";
TemperatureParser tp = null;
try {
tp = new TemperatureParser(args[0]);
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("No file name was entered.");
System.exit(1);
}
int counter = 0;
while (tp.hasNextLine()) {
tp.parseLine();
if (counter == 0) {
tempMax = tp.getTemp();
tempMaxDate = tp.getDate();
tempMin = tp.getTemp();
tempMinDate = tp.getDate();
counter++;
}
else if (tp.getTemp() < tempMin) {
tempMin = tp.getTemp();
tempMinDate = tp.getDate();
counter++;
}
else if (tp.getTemp() > tempMax) {
tempMin = tempMax;
tempMax = tp.getTemp();
tempMinDate = tempMaxDate;
tempMaxDate = tp.getDate();
counter++;
}
}
System.out.println("Maximum: " + tempMaxDate + ": " + tempMax);
System.out.println("Minimum: " + tempMinDate + ": " + tempMin);
}
}