Initial Commit
This commit is contained in:
8
Source Code/Assignment 6 (Ben)/.idea/.gitignore
generated
vendored
Normal file
8
Source Code/Assignment 6 (Ben)/.idea/.gitignore
generated
vendored
Normal 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/
|
7
Source Code/Assignment 6 (Ben)/.idea/codeStyles/Project.xml
generated
Normal file
7
Source Code/Assignment 6 (Ben)/.idea/codeStyles/Project.xml
generated
Normal 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>
|
5
Source Code/Assignment 6 (Ben)/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
Source Code/Assignment 6 (Ben)/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
6
Source Code/Assignment 6 (Ben)/.idea/misc.xml
generated
Normal file
6
Source Code/Assignment 6 (Ben)/.idea/misc.xml
generated
Normal 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>
|
8
Source Code/Assignment 6 (Ben)/.idea/modules.xml
generated
Normal file
8
Source Code/Assignment 6 (Ben)/.idea/modules.xml
generated
Normal 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>
|
11
Source Code/Assignment 6 (Ben)/Test.iml
Normal file
11
Source Code/Assignment 6 (Ben)/Test.iml
Normal 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>
|
BIN
Source Code/Assignment 6 (Ben)/out/production/Test/Main.class
Normal file
BIN
Source Code/Assignment 6 (Ben)/out/production/Test/Main.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
Source Code/Assignment 6 (Ben)/src/CharsetTester.java
Normal file
11
Source Code/Assignment 6 (Ben)/src/CharsetTester.java
Normal 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());
|
||||
}
|
||||
}
|
128
Source Code/Assignment 6 (Ben)/src/TemperatureParser.java
Normal file
128
Source Code/Assignment 6 (Ben)/src/TemperatureParser.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
52
Source Code/Assignment 6 (Ben)/src/TemperatureStats.java
Normal file
52
Source Code/Assignment 6 (Ben)/src/TemperatureStats.java
Normal 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);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user