Initial Commit
This commit is contained in:
8
Source Code/Assignment5Q2/.idea/.gitignore
generated
vendored
Normal file
8
Source Code/Assignment5Q2/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../../:\JavaProjects\JavaYear1\Assignment5Q2\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
25
Source Code/Assignment5Q2/.idea/codeStyles/Project.xml
generated
Normal file
25
Source Code/Assignment5Q2/.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,25 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="java.util" alias="false" withSubpackages="false" />
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
</JetCodeStyleSettings>
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
Source Code/Assignment5Q2/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
Source Code/Assignment5Q2/.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>
|
1
Source Code/Assignment5Q2/.idea/description.html
generated
Normal file
1
Source Code/Assignment5Q2/.idea/description.html
generated
Normal file
@ -0,0 +1 @@
|
||||
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
|
6
Source Code/Assignment5Q2/.idea/encodings.xml
generated
Normal file
6
Source Code/Assignment5Q2/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
12
Source Code/Assignment5Q2/.idea/misc.xml
generated
Normal file
12
Source Code/Assignment5Q2/.idea/misc.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectKey">
|
||||
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
|
||||
</component>
|
||||
<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/Assignment5Q2/.idea/modules.xml
generated
Normal file
8
Source Code/Assignment5Q2/.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$/Assignment5Q2.iml" filepath="$PROJECT_DIR$/Assignment5Q2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
3
Source Code/Assignment5Q2/.idea/project-template.xml
generated
Normal file
3
Source Code/Assignment5Q2/.idea/project-template.xml
generated
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
|
||||
</template>
|
124
Source Code/Assignment5Q2/.idea/uiDesigner.xml
generated
Normal file
124
Source Code/Assignment5Q2/.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
12
Source Code/Assignment5Q2/Assignment5Q2.iml
Normal file
12
Source Code/Assignment5Q2/Assignment5Q2.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?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.
Binary file not shown.
Binary file not shown.
46
Source Code/Assignment5Q2/src/CartesianPoint.java
Normal file
46
Source Code/Assignment5Q2/src/CartesianPoint.java
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
This class represents a point in 2D space.
|
||||
@author Natalie Webber
|
||||
*/
|
||||
public class CartesianPoint {
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
public CartesianPoint (double xVal, double yVal) {
|
||||
x = xVal;
|
||||
y = yVal;
|
||||
}
|
||||
|
||||
public double distance (double x2, double y2) {
|
||||
double dx = x - x2;
|
||||
double dy = y - y2;
|
||||
return Math.sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
public double distance (CartesianPoint other) {
|
||||
double dx = x - other.x;
|
||||
double dy = y - other.y;
|
||||
return Math.sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
public double getX () {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY () {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setX (double xVal) {
|
||||
x = xVal;
|
||||
}
|
||||
|
||||
public void setY (double yVal) {
|
||||
y = yVal;
|
||||
}
|
||||
|
||||
public void move (double xAmount, double yAmount) {
|
||||
x = x + xAmount;
|
||||
y = y + yAmount;
|
||||
}
|
||||
}
|
63
Source Code/Assignment5Q2/src/LineSegment.java
Normal file
63
Source Code/Assignment5Q2/src/LineSegment.java
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
This class represents a 2D line segment using 2 points.
|
||||
@author Natalie Webber
|
||||
@author Scott Bateman
|
||||
@author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
public class LineSegment {
|
||||
|
||||
private CartesianPoint pointA;
|
||||
private CartesianPoint pointB;
|
||||
|
||||
|
||||
public LineSegment (double x1, double y1, double x2, double y2) {
|
||||
pointA = new CartesianPoint (x1, y1);
|
||||
pointB = new CartesianPoint (x2, y2);
|
||||
}
|
||||
|
||||
public LineSegment (CartesianPoint p1, CartesianPoint p2) {
|
||||
pointA = p1;
|
||||
pointB = p2;
|
||||
}
|
||||
|
||||
public double getLength () {
|
||||
return pointA.distance(pointB);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks the cross product and dot products of the line and the given point to check if the point p is on the segment
|
||||
* @param p The point that is being tested to be on the segment
|
||||
* @return Value of if the returned point is on the segment
|
||||
*/
|
||||
public Boolean containsPoint (CartesianPoint p) {
|
||||
double crossProduct;
|
||||
crossProduct = ((p.getY() - pointA.getY()) * (pointB.getX() - pointA.getX())) - ((p.getX() - pointA.getX()) * (pointB.getY() - pointA.getY()));
|
||||
if (Math.abs(crossProduct) > Math.ulp(1.0)) {
|
||||
return false;
|
||||
}
|
||||
double dotProduct;
|
||||
dotProduct = ((p.getX() - pointA.getX()) * (pointB.getX() - pointA.getX())) + ((p.getY() - pointA.getY()) * (pointB.getY() - pointA.getY()));
|
||||
if (dotProduct < 0 ) {
|
||||
return false;
|
||||
}
|
||||
double squaredLength;
|
||||
squaredLength = ((pointB.getX() - pointA.getX()) * (pointB.getX() - pointA.getX())) + ((pointB.getY() - pointA.getY()) * (pointB.getY() - pointA.getY()));
|
||||
if (dotProduct > squaredLength) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if the line is vertical (only on one point in the x axis)
|
||||
* @return The value of is the line is vertical or not
|
||||
*/
|
||||
public boolean isVertical() {
|
||||
if (pointA.getX() == pointB.getX()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
59
Source Code/Assignment5Q2/src/TestLine.java
Normal file
59
Source Code/Assignment5Q2/src/TestLine.java
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
public class TestLine {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
LineSegment segment1 = new LineSegment(1.0, 1.0, 5.0, 5.0);
|
||||
CartesianPoint point1s1 = new CartesianPoint(3.0, 3.0);
|
||||
CartesianPoint point2s1 = new CartesianPoint(2.0, 3.0);
|
||||
|
||||
|
||||
LineSegment segment2 = new LineSegment(2.0, 2.0, 2.0, 6.0);
|
||||
CartesianPoint point1s2 = new CartesianPoint(2.0, 4.0);
|
||||
CartesianPoint point2s2 = new CartesianPoint(1.0, 5.0);
|
||||
|
||||
if (segment1.isVertical()) {
|
||||
System.out.println("Segment 1 is vertical");
|
||||
}
|
||||
else {
|
||||
System.out.println("Segment 1 is not vertical");
|
||||
}
|
||||
|
||||
if (segment1.containsPoint(point1s1)){
|
||||
System.out.println("Point 1 is on the line segment");
|
||||
}
|
||||
else {
|
||||
System.out.println("Point 1 is not on the line segment");
|
||||
}
|
||||
|
||||
if (segment1.containsPoint(point2s1)){
|
||||
System.out.println("Point 2 is on the line segment");
|
||||
}
|
||||
else {
|
||||
System.out.println("Point 2 is not on the line segment");
|
||||
}
|
||||
|
||||
if (segment2.isVertical()) {
|
||||
System.out.println("Segment 2 is vertical");
|
||||
}
|
||||
else {
|
||||
System.out.println("Segment 2 is not vertical");
|
||||
}
|
||||
|
||||
if (segment2.containsPoint(point1s2)){
|
||||
System.out.println("Point 1 is on the line segment");
|
||||
}
|
||||
else {
|
||||
System.out.println("Point 1 is not on the line segment");
|
||||
}
|
||||
|
||||
if (segment2.containsPoint(point2s2)){
|
||||
System.out.println("Point 2 is on the line segment");
|
||||
}
|
||||
else {
|
||||
System.out.println("Point 2 is not on the line segment");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user