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 4/.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 4\.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>

6
Source Code/Assignment 4/.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 4.iml" filepath="$PROJECT_DIR$/Assignment 4.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>

Binary file not shown.

View File

@ -0,0 +1,10 @@
CN Railway
5
P714 2012 85 true
F019 2018 75000
F221 2016 105000
T102 2017 35000 true
P904 2018 78 false
T102
F220
P714

View File

@ -0,0 +1,13 @@
CN Railway
7
P714 2012 85 true
F019 2018 75000
F221 2016 105000
F222 2016 1050000
T102 2017 35000 true
P904 2018 78 false
P905 2018 75 false
T102
F220
P714
P905

View File

@ -0,0 +1,9 @@
CN Railway
3
P714 2012 85 true
T102 2017 35000 true
P904 2018 78 false
T102
F220
P714
P906

View File

@ -0,0 +1,63 @@
/**
* Driver
* @author Isaac Shoebottom (3429069)
*/
import java.util.Scanner;
public class Driver {
/**
* Main method
* @param args program arguments
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String companyName = scan.nextLine();
int trainsLength = Integer.parseInt(scan.nextLine());
TrainCar[] tempArr = new TrainCar[trainsLength];
Sorter<TrainCar> sorter = new Sorter<>();
for(int i = 0; i < trainsLength; i++) {
String code = scan.next();
int inspectionYear = Integer.parseInt(scan.next());
if (code.charAt(0) == 'F') {
double weight = Double.parseDouble(scan.next());
tempArr[i] = new FreightTrain(code, inspectionYear, weight);
}
if (code.charAt(0) == 'P') {
int ticketsSold = Integer.parseInt(scan.next());
boolean isServiceTrain = Boolean.parseBoolean(scan.next());
tempArr[i] = new PassengerTrain(code, inspectionYear, ticketsSold, isServiceTrain);
}
if (code.charAt(0) == 'T') {
double litres = Double.parseDouble(scan.next());
boolean isHazardous = Boolean.parseBoolean(scan.next());
tempArr[i] = new TankTrain(code, inspectionYear, litres, isHazardous);
}
}
Train train = new Train(companyName, tempArr);
System.out.print(train.toString());
TrainCar[] tempArrSorted = train.getTrains();
sorter.selectionSort(tempArrSorted);
System.out.print("Sorted Data:\n");
for (TrainCar trainCar: tempArrSorted) {
System.out.println(trainCar.getCode() + "\t$" + trainCar.calculateIncome());
}
System.out.print("Search Results:\n");
String code;
while (scan.hasNext()) {
code = scan.next();
if (train.searchForTrain(code) != null) {
System.out.print("Train Car " + code + " found\n");
}
else if (train.searchForTrain(code) == null){
System.out.print("Train Car " + code + " NOT found\n");
}
}
}
}

View File

@ -0,0 +1,33 @@
/**
* FreightTrain class
* @author Isaac Shoebottom (3429069)
*/
public class FreightTrain extends TrainCar {
double weight;
/**
* The constructor for a freight train
* @param code The unique code of this train
* @param inspectionYr The year this train was last inspected
* @param weight The weight of the mass the train is carrying
*/
FreightTrain(String code, int inspectionYr, double weight) {
super(code, inspectionYr);
this.weight = weight;
}
/**
* The income calculator specific to freight train
* @return The income of that train
*/
@Override
double calculateIncome() {
if (weight < 100000) {
return 11500;
}
else {
return 25000;
}
}
}

View File

@ -0,0 +1,31 @@
/**
* PassengerTrain class
* @author Isaac Shoebottom (3429069)
*/
public class PassengerTrain extends TrainCar {
int ticketsSold;
boolean hasFoodService;
/**
* Constructor for a passenger train
* @param code The trains unique code
* @param inspectionYr The year the train was last inspected
* @param ticketsSold The number of tickets the train has sold
* @param hasFoodService If the train car has food service
*/
PassengerTrain(String code, int inspectionYr, int ticketsSold, boolean hasFoodService) {
super(code, inspectionYr);
this.ticketsSold = ticketsSold;
this.hasFoodService = hasFoodService;
}
/**
* The income calculator specific to passenger train
* @return The income of that train
*/
@Override
double calculateIncome() {
return (hasFoodService) ? ticketsSold*150 : ticketsSold*120;
}
}

View File

@ -0,0 +1,29 @@
/**
Sorter class provides methods for sorting lists.
Adapted from Java Software Solutions 9th Ed, Lewis & Loftus
*/
public class Sorter<T extends Comparable<T>>{
/**
Sorts the specified array using selection sort algorithm.
@param list The array of objects to sort.
*/
public void selectionSort(T[] list){
int min;
T temp;
for(int index = 0; index < list.length-1; index++){
min = index;
for(int scan = index+1; scan < list.length; scan++)
if(list[scan].compareTo(list[min]) < 0)
min = scan;
temp = list[min];
list[min] = list[index];
list[index] = temp;
}
}
}

View File

@ -0,0 +1,31 @@
/**
* TankTrain class
* @author Isaac Shoebottom (3429069)
*/
public class TankTrain extends TrainCar {
double litres;
boolean hazardous;
/**
* The constructor for the tank train
* @param code The unique code for the tank train
* @param inspectionYr The year the train was last inspected
* @param litres The litres the train is carrying
* @param hazardous If the train is carrying hazardous materials
*/
TankTrain(String code, int inspectionYr, double litres, boolean hazardous) {
super(code, inspectionYr);
this.litres = litres;
this.hazardous = hazardous;
}
/**
* The income calculator specific to tank train
* @return The income of that train
*/
@Override
double calculateIncome() {
return (hazardous) ? litres*17 : litres*9.5;
}
}

View File

@ -0,0 +1,53 @@
/**
* Train class
* @author Isaac Shoebottom (3429069)
*/
public class Train {
String trainOwnerCompany;
TrainCar[] trains;
/**
* Train constructor
* @param trainOwnerCompany The owner of the train
* @param trains The train cars the train has
*/
Train(String trainOwnerCompany, TrainCar[] trains) {
this.trainOwnerCompany = trainOwnerCompany;
this.trains = trains;
}
/**
* Searches for the the train based on the code
* @param code The code that is being searched for
* @return The train object that is returned if it is found
*/
public TrainCar searchForTrain(String code) {
for(TrainCar train: trains) {
if(train.getCode().compareToIgnoreCase(code) == 0) {
return train;
}
}
return null;
}
/**
* Get a copy of the train car array
* @return A copy of the train car array
*/
public TrainCar[] getTrains() {
return trains.clone();
}
/**
* Textual representation of the the array
* @return A string containing a textual representation of the array
*/
public String toString() {
String str = trainOwnerCompany + "\n";
for(TrainCar train : trains) {
str += train.toString();
}
return str;
}
}

View File

@ -0,0 +1,81 @@
/**
* TrainCar class
* @author Isaac Shoebottom (3429069)
*/
import java.text.NumberFormat;
public abstract class TrainCar implements Comparable<TrainCar> {
private final String code;
private final int inspectionYr;
/**
* Calculates income
* @return The income of that car
*/
abstract double calculateIncome();
/**
* TrainCar constructor
* @param code The unique identifier for the train car
* @param inspectionYr The year the train was last inspected
*/
TrainCar(String code, int inspectionYr) {
this.code = code;
this.inspectionYr = inspectionYr;
}
/**
* Method to compare to train cars to determine the natural order
* @param other The train car to be compared against
* @return -1, 0, 1 based on if the object is greater than the object being compared against
*/
public int compareTo(TrainCar other) {
String obj1 = String.valueOf(code.charAt(0)).toUpperCase();
String obj2 = String.valueOf(other.getCode().charAt(0)).toUpperCase();
if (obj1.compareTo(obj2) > 0) {
return 1;
}
else if (obj1.compareTo(obj2) < 0) {
return -1;
}
else {
int obj1Int = Integer.parseInt(String.valueOf(code.charAt(1) + code.charAt(2) + code.charAt(3)));
int obj2Int = Integer.parseInt(String.valueOf(other.getCode().charAt(1) + other.getCode().charAt(2) + other.getCode().charAt(3)));
if (obj1Int < obj2Int) {
return 1;
}
else if (obj1Int > obj2Int) {
return -1;
}
return 0;
}
}
/**
* Gets the train cars unique code
* @return The unique code
*/
public String getCode() {
return code;
}
/**
* Gets the inspection year
* @return The inspection year
*/
public int getInspectionYr() {
return inspectionYr;
}
/**
* String representing the train car
* @return A string representing the attributes of a train car
*/
public String toString(){
NumberFormat cf = NumberFormat.getCurrencyInstance();
String income = cf.format(calculateIncome());
return "[Code: " + code + "\tInspection Year: "+ inspectionYr + "\tIncome: "+ income + "]\n";
}
}

View File

@ -0,0 +1,10 @@
CN Railway
5
P714 2012 85 true
F019 2018 75000
F221 2016 105000
T102 2017 35000 true
P904 2018 78 false
T102
F220
P714

View File

@ -0,0 +1,13 @@
CN Railway
7
P714 2012 85 true
F019 2018 75000
F221 2016 105000
F222 2016 1050000
T102 2017 35000 true
P904 2018 78 false
P905 2018 75 false
T102
F220
P714
P905

View File

@ -0,0 +1,9 @@
CN Railway
3
P714 2012 85 true
T102 2017 35000 true
P904 2018 78 false
T102
F220
P714
P906