commit 4380dd04e5b0019cb38f3cb480314a82dd23df53 Author: aj Date: Fri Jun 14 12:38:51 2019 +0100 initial commit diff --git a/CS2012 Lab 1/.gitignore b/CS2012 Lab 1/.gitignore new file mode 100644 index 0000000..c2fd6a2 --- /dev/null +++ b/CS2012 Lab 1/.gitignore @@ -0,0 +1,58 @@ +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +.classpath +.project diff --git a/CS2012 Lab 1/src/doublearray/ArrayModifier.java b/CS2012 Lab 1/src/doublearray/ArrayModifier.java new file mode 100755 index 0000000..3730a7e --- /dev/null +++ b/CS2012 Lab 1/src/doublearray/ArrayModifier.java @@ -0,0 +1,97 @@ +package doublearray; + +import java.util.Scanner; + +public class ArrayModifier { + + public static void main(String[] args) { + double[] array = getArray(); + System.out.print("Original Array: "); + printArray(array); + System.out.println(); + + System.out.print("Square Root: "); + sqrtArray(array); + System.out.print("Original Array: "); + printArray(array); + System.out.println(); + + System.out.print("Truncated at 500: "); + truncateArray(array); + printArray(array); + System.out.println(); + + //double[] newArray = new double[array.length]; + double[] newArray = getReciprocalArray(array); + System.out.print("Reciprocal Array: "); + printArray(newArray); + System.out.print("Original Array: "); + printArray(array); + + } + + static double[] getArray() { //Return array of 10 valid doubles + Scanner scan = new Scanner(System.in); + double[] array = new double[10]; + + System.out.println("Enter 10 Doubles, 1 per line: "); + for (int counter = 0; counter < 10; counter++) { + while (!scan.hasNextDouble()) { + scan.nextLine(); + System.out.println("Error: Enter Double"); + } + array[counter] = scan.nextDouble(); + } + scan.close(); + return array; + } + + static void sqrtArray(double[] array) { //Print sqrt of each value + + + for (double i : array) { + System.out.println(Math.sqrt(i)); + } + + + /* + double[] newArray = new double[array.length]; + for (int counter = 0; counter < array.length; counter++) { + + newArray[counter] = Math.sqrt(array[counter]); + } + printArray(newArray); + */ + } + + static void truncateArray(double[] array) { //truncate values of array to 500 + for (int counter = 0; counter < array.length; counter++) { + + if (array[counter] > 500) + array[counter] = 500; + + } + } + + static double[] getReciprocalArray(double[] array) { //returns new array of reciprocals + double[] newArray = new double[array.length]; + for (int counter = 0; counter < array.length; counter++) { + + newArray[counter] = 1 / array[counter]; + } + + return newArray; + } + + static void printArray(double[] array) { //print out array + System.out.print('{'); + for (int counter = 0; counter < array.length; counter++) { + System.out.print(array[counter]); + if (counter != (array.length - 1)) + System.out.print(", "); + + } + System.out.println('}'); + } + +} diff --git a/CS2012 Lab 10/.gitignore b/CS2012 Lab 10/.gitignore new file mode 100644 index 0000000..c2fd6a2 --- /dev/null +++ b/CS2012 Lab 10/.gitignore @@ -0,0 +1,58 @@ +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +.classpath +.project diff --git a/CS2012 Lab 10/Lab10.jar b/CS2012 Lab 10/Lab10.jar new file mode 100755 index 0000000..db18687 Binary files /dev/null and b/CS2012 Lab 10/Lab10.jar differ diff --git a/CS2012 Lab 10/src/fx/MainController.java b/CS2012 Lab 10/src/fx/MainController.java new file mode 100755 index 0000000..b79ef64 --- /dev/null +++ b/CS2012 Lab 10/src/fx/MainController.java @@ -0,0 +1,193 @@ +package fx; + +import java.io.File; +import java.time.LocalDate; +import java.util.ArrayList; + +import io.BinaryMonsterPersister; +import io.MonsterPersister; +import io.TextMonsterPersister; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.DatePicker; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.GridPane; +import javafx.stage.FileChooser; +import model.MonsterAttack; + +public class MainController { + + private ArrayList list; + + public MainController() { + list = new ArrayList(); + } + + @FXML + private void initialize() { + + labelName.getStyleClass().add("headerLabel"); + labelLocation.getStyleClass().add("headerLabel"); + labelReporter.getStyleClass().add("headerLabel"); + labelDate.getStyleClass().add("headerLabel"); + + refresh(); + } + + private Label labelName = new Label("monster name"); + private Label labelLocation = new Label("location"); + private Label labelReporter = new Label("reporter name"); + private Label labelDate = new Label("date"); + + @FXML + private TextField textFieldMonsterName; + @FXML + private TextField textFieldLocation; + @FXML + private TextField textFieldReporter; + @FXML + private DatePicker datePicker; + @FXML + private GridPane gridPane; + + @FXML + protected void handleAdd() { + + String name = textFieldMonsterName.getText(); + String location = textFieldLocation.getText(); + String reporter = textFieldReporter.getText(); + LocalDate date = datePicker.getValue(); + +// System.out.println(name + location + reporter + date.toString()); + + if (name != null && location != null && reporter != null && date != null) { + +// System.out.println(date.toString()); + MonsterAttack attack = new MonsterAttack(date.toString(), name, location, reporter); + + System.out.println(attack); + + list.add(attack); + refresh(); + + } + } + + public void refresh() { + + gridPane.getChildren().clear(); + + gridPane.add(labelName, 0, 0); + gridPane.add(labelLocation, 1, 0); + gridPane.add(labelReporter, 2, 0); + gridPane.add(labelDate, 3, 0); + + int counter; + for (counter = 0; counter < list.size(); counter++) { + final MonsterAttack attack = list.get(counter); + + Label name = new Label(attack.getNameOfMonster()); + name.getStyleClass().add("monsterName"); + + Label location = new Label(attack.getAttackLocation()); + Label reporter = new Label(attack.getReporterName()); + Label date = new Label( + attack.getMonthOfAttack() + "/" + attack.getDayOfAttack() + "/" + attack.getYearOfAttack()); + + Button delete = new Button("delete"); + delete.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { + + @Override + public void handle(Event event) { + + list.remove(attack); + refresh(); + + } + + }); + + gridPane.add(name, 0, counter + 1); + gridPane.add(location, 1, counter + 1); + gridPane.add(reporter, 2, counter + 1); + gridPane.add(date, 3, counter + 1); + gridPane.add(delete, 4, counter + 1); + } + + } + + @FXML + protected void handleSave() { + if (list.size() > 0) { + FileChooser choose = new FileChooser(); + + choose.setTitle("save attack list"); + choose.getExtensionFilters().add(new FileChooser.ExtensionFilter("Text IO", "*.monstertext")); + choose.getExtensionFilters().add(new FileChooser.ExtensionFilter("Binary IO", "*.monsterbinary")); + File file = choose.showSaveDialog(MonsterAttackApplication.getStage()); + + if (file != null) { + + String extension = file.getName().substring(file.getName().lastIndexOf(".") + 1); + System.out.println(extension); + + MonsterPersister persist; + + if (extension.equals("monstertext")) { + System.out.println("Text"); + + persist = new TextMonsterPersister(); + + } else { + + System.out.println("Binary"); + + persist = new BinaryMonsterPersister(); + + } + + persist.write(file, list); + } + } + } + + @FXML + protected void handleOpen() { + FileChooser choose = new FileChooser(); + + choose.setTitle("open attack list"); + choose.getExtensionFilters().add(new FileChooser.ExtensionFilter("Text IO", "*.monstertext")); + choose.getExtensionFilters().add(new FileChooser.ExtensionFilter("Binary IO", "*.monsterbinary")); + File file = choose.showOpenDialog(MonsterAttackApplication.getStage()); + + if (file != null) { + + String extension = file.getName().substring(file.getName().lastIndexOf(".") + 1); +// System.out.println(extension); + + MonsterPersister persist; + + if (extension.equals("monstertext")) { + System.out.println("Text"); + + persist = new TextMonsterPersister(); + + } else { + + System.out.println("Binary"); + + persist = new BinaryMonsterPersister(); + + } + + + list = persist.read(file); + refresh(); + } + } + +} diff --git a/CS2012 Lab 10/src/fx/MonsterAttackApplication.java b/CS2012 Lab 10/src/fx/MonsterAttackApplication.java new file mode 100755 index 0000000..0273db7 --- /dev/null +++ b/CS2012 Lab 10/src/fx/MonsterAttackApplication.java @@ -0,0 +1,41 @@ +package fx; + + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class MonsterAttackApplication extends Application { + + private static Stage stage; + + @Override + public void start(Stage stageIn) throws Exception { + stage = stageIn; + + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/main.fxml")); + + Parent root = (Parent)loader.load(); + + Scene scene = new Scene(root, 1000, 800); + + + stage.setMinHeight(800); + stage.setMinWidth(960); + stage.setTitle("fm framework"); + stage.setScene(scene); + stage.show(); + + } + + public static void main(String[] args) { + launch(args); + } + + public static Stage getStage() { + return stage; + } + +} diff --git a/CS2012 Lab 10/src/fx/styles/main.css b/CS2012 Lab 10/src/fx/styles/main.css new file mode 100755 index 0000000..1a4287b --- /dev/null +++ b/CS2012 Lab 10/src/fx/styles/main.css @@ -0,0 +1,16 @@ +.monsterName{ + + -fx-alignment: center; + -fx-font-size: 150%; + -fx-font-style: italic; + -fx-text-alignment: center; +} + +.headerLabel{ + + -fx-alignment: center; + -fx-font-size: 150%; + -fx-font-weight: bold; + -fx-text-alignment: center; + +} \ No newline at end of file diff --git a/CS2012 Lab 10/src/fx/ui/main.fxml b/CS2012 Lab 10/src/fx/ui/main.fxml new file mode 100755 index 0000000..27c7411 --- /dev/null +++ b/CS2012 Lab 10/src/fx/ui/main.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + +