diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build.xml b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build.xml new file mode 100644 index 0000000..77fc166 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project BinarySearchTreeTest. + + + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ArrayUtility.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ArrayUtility.class new file mode 100644 index 0000000..6646459 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ArrayUtility.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/BinarySearchTree$1.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/BinarySearchTree$1.class new file mode 100644 index 0000000..525c525 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/BinarySearchTree$1.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Car.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Car.class new file mode 100644 index 0000000..b045783 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Car.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$1.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$1.class new file mode 100644 index 0000000..bd1b576 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$1.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$CarNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$CarNode.class new file mode 100644 index 0000000..47e6ae8 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$CarNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$DealershipNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$DealershipNode.class new file mode 100644 index 0000000..436387e Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$DealershipNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$ListNode.class new file mode 100644 index 0000000..b6b9f44 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotFoundException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotFoundException.class new file mode 100644 index 0000000..9cd7144 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotFoundException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotUniqueException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotUniqueException.class new file mode 100644 index 0000000..a6bf596 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$NotUniqueException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$CarNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$CarNode.class new file mode 100644 index 0000000..71063f7 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$CarNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$DealershipNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$DealershipNode.class new file mode 100644 index 0000000..9ea951a Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$DealershipNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$ListNode.class new file mode 100644 index 0000000..a383dd8 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList$ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList.class new file mode 100644 index 0000000..fca476a Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership$SortedLinkedList.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership.class new file mode 100644 index 0000000..95e0c84 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Dealership.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$CarNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$CarNode.class new file mode 100644 index 0000000..4710b85 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$CarNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$ListNode.class new file mode 100644 index 0000000..d26066e Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest$ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest.class new file mode 100644 index 0000000..a052858 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/DealershipTest.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Input.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Input.class new file mode 100644 index 0000000..1a649ac Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/Input.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/InsertionSort.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/InsertionSort.class new file mode 100644 index 0000000..e742406 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/InsertionSort.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ListNode.class new file mode 100644 index 0000000..3da6c4a Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotFoundException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotFoundException.class new file mode 100644 index 0000000..eb0bb60 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotFoundException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotUniqueException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotUniqueException.class new file mode 100644 index 0000000..c7c5a32 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT$NotUniqueException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT.class new file mode 100644 index 0000000..4f9a5a5 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedADT.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList$ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList$ListNode.class new file mode 100644 index 0000000..1f964f7 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList$ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList.class new file mode 100644 index 0000000..c24181a Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/build/classes/SortedLinkedList.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/manifest.mf b/Dealership-CW-Step2 - 10-04-19/DealershipCW/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/build-impl.xml b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/build-impl.xml new file mode 100644 index 0000000..a0200fd --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/genfiles.properties b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/genfiles.properties new file mode 100644 index 0000000..eaab25c --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=efae4f42 +build.xml.script.CRC32=bfa31719 +build.xml.stylesheet.CRC32=8064a381@1.74.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=efae4f42 +nbproject/build-impl.xml.script.CRC32=bf272f58 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.properties b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.properties new file mode 100644 index 0000000..8c600f8 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\B00330262\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.xml b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.xml new file mode 100644 index 0000000..6ec822a --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/private/private.xml @@ -0,0 +1,12 @@ + + + + + + file:/E:/CW1%20WIP/BinarySearchTreeTest/src/DealershipTest.java + file:/E:/CW1%20WIP/BinarySearchTreeTest/src/Dealership.java + file:/E:/CW1%20WIP/BinarySearchTreeTest/src/Car.java + file:/E:/CW1%20WIP/BinarySearchTreeTest/src/CarList.java + + + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.properties b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.properties new file mode 100644 index 0000000..35376ad --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.properties @@ -0,0 +1,73 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BinarySearchTreeTest.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=DealershipTest +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.xml b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.xml new file mode 100644 index 0000000..7436fc3 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + BinarySearchTreeTest + + + + + + + + + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ArrayUtility.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ArrayUtility.java new file mode 100644 index 0000000..3b39df7 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ArrayUtility.java @@ -0,0 +1,21 @@ + +public class ArrayUtility { + + public static void display(Object[] values) { + /* can be used to output array contents where the component object has a toString method + will output every slot in the array including empty slots which will be output as null + */ + for (Object value : values) { + System.out.print(value + " "); + } + System.out.println(); + } + + public static Integer getNumberOfObjects(Object[] objects) { + Integer index = 0; + while (index < objects.length && objects[index] != null) { + index++; + } + return index; + } +} diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.class new file mode 100644 index 0000000..6db54ee Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.java new file mode 100644 index 0000000..0c33eac --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Car.java @@ -0,0 +1,38 @@ +/*//@author B00330262 - Gary Hughes*/ +public class Car implements Comparable{ + + //decalre variables using info from GameListTest class + private String RegistrationNumber; + private String ModelName; + private String colour; + + //takes game details from GameListTest + //adds info to local variables declared above + public void addDetails(String RegistrationNumber, String ModelName, String colour){ + this.RegistrationNumber = RegistrationNumber; + this.ModelName = ModelName; + this.colour = colour; + + } + + //uses "compareTo" method with details of games + public int compareTo(Car car){ + + //Sort by year (descending), if year is the same + //compare names for further sorting (ascending) + Integer result = this.ModelName.compareTo(car.ModelName); + if (result == 0){ + result = this.RegistrationNumber.compareToIgnoreCase(car.RegistrationNumber); + //make result negative to change to descending order + result = result * -1; + } + return result; + } + + //details of all games to string for printing, returned to GameListTest + public String toString(){ + String gameDetails = new String(); + gameDetails=String.format("%-20s%-20s%-20s", this.RegistrationNumber, this.ModelName, this.colour); + return gameDetails; + } +} diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$CarNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$CarNode.class new file mode 100644 index 0000000..42d2fbf Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$CarNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$DealershipNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$DealershipNode.class new file mode 100644 index 0000000..a511887 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$DealershipNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotFoundException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotFoundException.class new file mode 100644 index 0000000..1a374e0 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotFoundException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotUniqueException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotUniqueException.class new file mode 100644 index 0000000..eb3a2f6 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership$NotUniqueException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.class new file mode 100644 index 0000000..e9a824c Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.java new file mode 100644 index 0000000..615d6c7 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Dealership.java @@ -0,0 +1,269 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; + +public class Dealership { + + private static List instancesOfManufacturers = new ArrayList(); + private static List instancesOfAllCars = new ArrayList(); + public static List getInstances() { + return instancesOfManufacturers; + } + public static List getAllCars() { + Collections.sort(instancesOfAllCars); + return instancesOfAllCars; + } + + public class NotFoundException extends Exception { + } + + public class NotUniqueException extends Exception { + } + + public abstract class SortedLinkedList implements SortedADT { + } + + public class ListNode { + private Comparable object; + private ListNode next; + } + + public ListNode head; + + public class CarNode { + + public Car car; + public CarNode next; + public CarNode current; + + } + + protected class DealershipNode { + + public String Manufacturer; + public DealershipNode left; + public DealershipNode right; + public CarNode carhead; + + } + + + protected DealershipNode root; + protected DealershipNode current; + protected DealershipNode parent; + + + + + + //change getTree to getInOrder gives alphabetical order of manufacturers + public String toString() { + String treeDetails = new String(); + if (this.root != null) { + treeDetails += this.getTree(this.root, 0); + } else { + treeDetails += "No manufacturers found"; + } + return treeDetails; + } + + + public String getTree(DealershipNode current, Integer level) { + String treeDetails = new String(); + level++; + if (current != null) { + + + + treeDetails += this.getTree(current.right, level); + for (Integer i = 0; i < level; i++) { + treeDetails += " "; + for(int j=0; j< instancesOfAllCars.size(); j++){ + + + if(instancesOfAllCars.contains(current.Manufacturer.toString())) + treeDetails+=(instancesOfAllCars.get(j)); + StringBuilder treeall = new StringBuilder(); + treeall.append(treeDetails); + + } + } + + + treeDetails += current.Manufacturer + "\n"; + if(current.carhead != null){ + if(instancesOfAllCars.contains(current.Manufacturer + "\t" + "\t" +(current.carhead.car.toString())+"\n")) + treeDetails += current.carhead.car.toString() + "\n"; + + treeDetails += this.getTree(current.left, level); + + } else { + for (Integer i = 0; i < level; i++) { + treeDetails += " "; + } + treeDetails += "null\n"; + } + + } + return treeDetails; + } + + private String getInOrder(DealershipNode current) { + String inOrderDetails = new String(); + if (current != null) { + inOrderDetails += this.getInOrder(current.left); + inOrderDetails += current.Manufacturer + " "; + inOrderDetails += this.getInOrder(current.right); + } + return inOrderDetails; + } + + //both this block and the following deal with manufacturers in the tree! + public void insert(Object car) throws NotUniqueException { + + DealershipNode newNode = new DealershipNode(); + newNode.Manufacturer = car.toString(); + if (this.root == null) { + this.root = newNode; + } else { + this.insert(newNode, this.root); + } + //List of manufacturers added - unique only + instancesOfManufacturers.add(newNode.Manufacturer.toString() +"\n"); + } + + public void insert(DealershipNode newNode, DealershipNode current) + throws NotUniqueException { + + //manufacturer already added + if (newNode.Manufacturer.compareTo(current.Manufacturer) == 0) { + throw new NotUniqueException(); + } + + + + //manufacturer added to left of root + if (newNode.Manufacturer.compareTo(current.Manufacturer) < 0) { + if (current.left == null) { + current.left = newNode; + current.left.carhead = null; + } else { + this.insert(newNode, current.left); + newNode.carhead = null; + } + + //manufacturer added to right of root + } else if (current.right == null) { + current.right = newNode; + current.right.carhead = null; + } else { + this.insert(newNode, current.right); + } + } + + public Comparable find(Comparable Manufacturer) throws NotFoundException { + return this.find(Manufacturer, this.root); + } + + private Comparable find(Comparable Manufacturer, DealershipNode current) + throws NotFoundException { + + Comparable foundObject; + if (current != null) { + if (Manufacturer.compareTo(current.Manufacturer) == 0) { + this.current = current; + foundObject = current.Manufacturer; + } else { + this.parent = current; + if (Manufacturer.compareTo(current.Manufacturer) < 0) { + foundObject = this.find(Manufacturer, current.left); + } else { + foundObject = this.find(Manufacturer, current.right); + } + } + } else { + throw new NotFoundException(); + } + return foundObject; + } + + //remove manufacturer + public Comparable remove(Comparable Manufacturer) throws NotFoundException { + // sets up parent and current + Comparable removedObject = this.find(Manufacturer); + if (this.current.left == null && this.current.right == null) { + this.replaceNode(null); + } else if (this.current.left != null && this.current.right == null) { + this.replaceNode(this.current.left); + this.current.left = null; + } else if (this.current.left == null && this.current.right != null) { + this.replaceNode(this.current.right); + this.current.right = null; + } else { + this.replaceWithNextLargest(this.current, this.current, this.current.right); + } + for(int j=0; j< instancesOfAllCars.size(); j++){ + if(instancesOfAllCars.get(j).toString().contains(Manufacturer + "\t" + "\t")) + instancesOfAllCars.remove(instancesOfAllCars.get(j)); + } + instancesOfManufacturers.remove(Manufacturer.toString()+"\n"); + + + return removedObject; + } + + private void replaceNode(DealershipNode replacement) { + + if (this.current == this.root) // removing root + { + this.root = replacement; + } else if (this.current == this.parent.left) { + this.parent.left = replacement; + } else { + this.parent.right = replacement; + } + this.current.Manufacturer = null; + } + + private void replaceWithNextLargest(DealershipNode nodeForDeletion, DealershipNode parent, DealershipNode current) { + + if (current.left == null) { + nodeForDeletion.Manufacturer = current.Manufacturer; + if (parent == nodeForDeletion) { + parent.right = current.right; + } else { + parent.left = current.right; + } + current.Manufacturer = null; + current.right = null; + } else { + this.replaceWithNextLargest(nodeForDeletion, current, current.left); + } + } + + + public void insertCar(Car car, String Manufacturer) { + + + CarNode newNode = new CarNode(); + newNode.car = car; + instancesOfAllCars.add(Manufacturer + "\t" + "\t" +car.toString()+"\n"); + + if (this.current.carhead == null) { + this.current.carhead = newNode; + } else { + Dealership.CarNode curr = this.current.carhead; + this.current.carhead = newNode; + newNode.next = curr; + + } + } + + + public void removeCar(Car car, String Manufacturer){ + instancesOfAllCars.remove(Manufacturer + "\t" +car.toString()+"\n"); + } +} + + + diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.class new file mode 100644 index 0000000..409879e Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.java new file mode 100644 index 0000000..63e4566 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/DealershipTest.java @@ -0,0 +1,319 @@ +import java.util.ArrayList; +import java.util.InputMismatchException; +import java.util.List; +import java.util.Scanner; + +public class DealershipTest { + + public class CarNode { + + public Car car; + public CarNode next; + //public CarNode carhead; + public CarNode current; + } + + + private class ListNode { + private Comparable object; + private ListNode next; + public Car car; + public CarNode current; + public String NodeDetails; + } + + public static void main(String[] args) throws SortedADT.NotUniqueException, Dealership.NotFoundException { + Dealership dealership = new Dealership(); + String Manufacturer; + Integer option = null; + String RegistrationNumber; + String ModelName; + String colour; + List specificMake = new ArrayList(); + + String[] where = new String [100000]; + Car car = null; + + + do { + System.out.println("0: quit"); + System.out.println("1: Add manufacturer"); + System.out.println("2: Remove manufacturer"); + System.out.println("3: Find"); + System.out.println("4: Display manufacturers"); + System.out.println("5: Add Car"); + System.out.println("6: Remove Car"); + System.out.println("7: Display tree of manufacturers AND cars"); + System.out.println("8: Display all cars - alphabetical by manufacturer"); + System.out.println("9: Display tree of manufacturers ONLY"); + System.out.println("10: Display cars of specific manufacturer"); + System.out.println("11: Display cars of specific manufacturer AND model"); + + + Scanner sc=new Scanner(System.in); + try{ + //option = Input.getInteger("option: "); + System.out.println("option: "); + option = sc.nextInt(); + } + catch(InputMismatchException exception){ + System.out.println("Not a Number"); + option = null; + } + + if(option != null){ + switch (option) { + + //quit program + case 0: + try{ + System.out.println("1: Quit"); + System.out.println("2: Cancel"); + + System.out.println("Are you sure you want to quit?"); + option = sc.nextInt(); + } + catch(InputMismatchException exception) + { + System.out.println("Not a Number"); + option = 2; + } + + if(option == 1){ + System.out.println("Goodbye"); + System.exit(0); + } + else{ + System.out.println("Returning to Menu"); + } + break; + + + + //add maufacturer + case 1: + Manufacturer=Input.getString("Manufacturer: "); + try{ + dealership.insert(Manufacturer); + System.out.println("inserted"); + } + catch(Dealership.NotUniqueException e){ + System.out.println("insert invalid - Manufacturer not unique"); + } + break; + + + + + //remove manufacturer + case 2: + Manufacturer=Input.getString("Manufacturer: "); + try{ + Manufacturer=(String)dealership.remove(Manufacturer); + + System.out.println(Manufacturer+" removed"); + } + catch(Dealership.NotFoundException e){ + System.out.println("remove invalid - Manufacturer not found"); + } + break; + + + + + //find manufacturer + case 3: + Manufacturer=Input.getString("Manufacturer: "); + if(Manufacturer.equals("") || Manufacturer.equals(" ")){ + System.out.println("No valid Input - returning to menu"); + break; + } + else{ + try{ + Manufacturer=(String)dealership.find(Manufacturer); + System.out.println(Manufacturer+" found"); + } + catch(Dealership.NotFoundException e){ + System.out.println("Manufacturer not found"); + } + } + break; + + + + + //display manufacturers + case 4: + + if(Dealership.getInstances().isEmpty()){ + System.out.println("We currently have no manufaturers on sale"); + + + } + else{ + //uglist formatting in existsance but didnae touch it + String output = ("All Manufacturers we sell: " + "\n" + (Dealership.getInstances())).toString().replace("[","").replace("]","").replace(",",""); + System.out.println(output); + } + break; + + + + //add a car - find way to turn manufacturer name into string to create a linked list for that manufacter to add the car to + case 5: + Manufacturer=Input.getString("Manufacturer of Car: "); + try{ + Manufacturer=(String)dealership.find(Manufacturer); + + RegistrationNumber = Input.getString("Registration Number: "); + ModelName = Input.getString("Model Name: "); + colour = Input.getString("Vehicle Colour: "); + if( + RegistrationNumber.equals("") || RegistrationNumber.equals(" ") || + ModelName.equals("") || ModelName.equals(" ") || + colour.equals("") || colour.equals(" ") ) + { + System.out.println("Car details cannot be blank. Returning to Main Menu"); + } + + + Car currentCar = new Car(); + currentCar.addDetails(RegistrationNumber, ModelName, colour); + dealership.insertCar(currentCar, Manufacturer); + System.out.println("inserted"); + StringBuilder allCars = new StringBuilder(); + allCars.append("Manufacturer:" + Manufacturer + "/n" + "currentCar:" + currentCar); + where[0] = allCars.toString(); + + + } + catch(Dealership.NotFoundException e){ + System.out.println("Manufacturer not found - returning to menu"); + } + + break; + + + + //remove a car + case 6: + Manufacturer=Input.getString("Manufacturer of Car: "); + try{ + Manufacturer=(String)dealership.find(Manufacturer); + } + catch(Dealership.NotFoundException e){ + System.out.println("Manufacturer not found - returning to menu"); + } + + + RegistrationNumber = Input.getString("Registration Number: "); + ModelName = Input.getString("Model Name: "); + colour = Input.getString("Vehicle Colour: "); + Car currentCar = new Car(); + currentCar.addDetails(RegistrationNumber, ModelName, colour); + + dealership.removeCar(currentCar, Manufacturer); + + System.out.println(Dealership.getAllCars()); + break; + + + //display tree of manufacturers + case 7: + System.out.println(dealership); + break; + + + case 8: + if(Dealership.getAllCars().isEmpty()){ + System.out.println("We currently have no cars on sale"); + } + else{ + System.out.println("All cars we sell: " + "\n" + "Manufacturer" + "\t" + "Registration" + "\t" + "Model" + "\t" + "\t" + "vehicle colour" + "\n" + Dealership.getAllCars().toString().replace("[","").replace("]","").replace(",","")); + StringBuilder getallcars = new StringBuilder(); + getallcars.append(Dealership.getAllCars()); + } + + break; + + case 9: + + System.out.println("All manufacturers on sale: " + "\n" + Dealership.getInstances().toString().replace("[","").replace("]","").replace(",","")); + StringBuilder getallmanu = new StringBuilder(); + getallmanu.append(Dealership.getInstances()); + break; + + case 10: + + specificMake.clear(); + Manufacturer=Input.getString("Manufacturer of Car: "); + try{ + Manufacturer=(String)dealership.find(Manufacturer); + List allCars = Dealership.getAllCars(); + for(int j=0; j< allCars.size(); j++){ + if(allCars.get(j).toString().contains(Manufacturer)) + specificMake.add(allCars.get(j)); + } + System.out.println(specificMake.size() + " cars from " + Manufacturer + "\n" + "Manufacturer" + "\t" + "Registration" + "\t" + "\t" + "Model" + "\t" + "\t" + "vehicle colour" + "\n" + specificMake.toString().replace("[","").replace("]","").replace(",","")); + + + }catch(Dealership.NotFoundException e){ + System.out.println("Manufacturer not found - returning to menu"); + } + + break; + + + case 11: + List specificModel = new ArrayList(); + specificModel.clear(); + specificMake.clear(); + Manufacturer=Input.getString("Manufacturer of Car: "); + try{ + Manufacturer=(String)dealership.find(Manufacturer); + + List allCars = Dealership.getAllCars(); + for(int j=0; j< allCars.size(); j++){ + if(allCars.get(j).toString().contains(Manufacturer)) + specificMake.add(allCars.get(j)); + + } + + if(specificMake.isEmpty()) + System.out.println("No cars from " + Manufacturer + ", returning to main menu"); + else{ + String Model = Input.getString("Model of Car: "); + + + for(int j=0; j< specificMake.size(); j++){ + if(specificMake.get(j).toString().contains(Model)) + + specificModel.add(specificMake.get(j)); + + } + + System.out.println(specificModel.size() + " " + Manufacturer + " " + Model + " for sale" + "\n" + "Manufacturer" + "\t" + "Registration" + "\t" + "\t" + "Model" + "\t" + "\t" + "vehicle colour" + "\n" + specificModel.toString().replace("[","").replace("]","").replace(",","")); + } + + }catch(Dealership.NotFoundException e){ + System.out.println("Manufacturer not found - returning to menu"); + } + + break; + + /* alphabetical DA + case 12: + System.out.println(Dealership.inOrderAlphabet); + + + + break; + */ + + default: + System.out.println("\n" + "invalid option" + "\n"); + } + } + } while (option == null || option != 0); + } +} \ No newline at end of file diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.class new file mode 100644 index 0000000..a43edac Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.java new file mode 100644 index 0000000..5464b62 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/Input.java @@ -0,0 +1,56 @@ +import java.io.*; +public class Input{ + private static BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); + + public static Character getCharacter(String prompt){ + Character value; + System.out.print(prompt); + try{ + value=Input.input.readLine().charAt(0); + } + catch(Exception error){ + // error condition + value=null; + } + return value; + } + + public static Double getDouble(String prompt){ + Double value; + System.out.print(prompt); + try{ + value=Double.parseDouble(Input.input.readLine()); + } + catch(Exception error){ + // error condition + throw new NumberFormatException(); + } + return value; + } + + public static Integer getInteger(String prompt){ + Integer value; + System.out.print(prompt); + try{ + value=Integer.parseInt(Input.input.readLine()); + } + catch(Exception error){ + // error condition + throw new NumberFormatException(); + } + return value; + } + + public static String getString(String prompt){ + String string; + System.out.print(prompt); + try{ + string=Input.input.readLine(); + } + catch(Exception error){ + // error condition + string=null; + } + return string; + } +} \ No newline at end of file diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/InsertionSort.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/InsertionSort.java new file mode 100644 index 0000000..c402448 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/InsertionSort.java @@ -0,0 +1,29 @@ + +public class InsertionSort { + + public static void sort(Comparable[] values) { + Boolean insertionPositionFound; + Comparable insertValue; + Integer size = ArrayUtility.getNumberOfObjects(values); + for (Integer current = 1; current < size; current++) { + insertionPositionFound = false; + Integer insertion = 0; + while (!insertionPositionFound) { + if (values[current].compareTo(values[insertion]) > 0) { + insertionPositionFound = true; + insertValue = values[current]; + for (Integer index = current; index > insertion; index--) { + values[index] = values[index - 1]; + } + values[insertion] = insertValue; + } else { + insertion++; + if (insertion == current) { + insertionPositionFound = true; + } + } + } + } + } + +} \ No newline at end of file diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ListNodeDA.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ListNodeDA.java new file mode 100644 index 0000000..f36a101 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/ListNodeDA.java @@ -0,0 +1,20 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author B00330262 + */ +public class ListNode { + + + + + public Comparable object; + public ListNode next; + + +} diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotFoundException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotFoundException.class new file mode 100644 index 0000000..9acf4e1 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotFoundException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotUniqueException.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotUniqueException.class new file mode 100644 index 0000000..b3c32b8 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT$NotUniqueException.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.class new file mode 100644 index 0000000..a102518 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.java new file mode 100644 index 0000000..a10a4f0 --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedADT.java @@ -0,0 +1,19 @@ + +public abstract interface SortedADT { + + public void insertCar(String string); + + public void insert(Car currentCar); + + + public class NotFoundException extends Exception{} + + public class NotUniqueException extends Exception{} + + + // returns the object found + public abstract Comparable remove(Comparable object) throws NotFoundException; + + // returns the object removed + public abstract Comparable find(Comparable object) throws NotFoundException; +} diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList$ListNode.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList$ListNode.class new file mode 100644 index 0000000..aab63b1 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList$ListNode.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.class b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.class new file mode 100644 index 0000000..9429ac1 Binary files /dev/null and b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.class differ diff --git a/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.java b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.java new file mode 100644 index 0000000..c4becfc --- /dev/null +++ b/Dealership-CW-Step2 - 10-04-19/DealershipCW/src/SortedLinkedList.java @@ -0,0 +1,179 @@ + +public abstract class SortedLinkedList implements SortedADT { + + + + public class ListNode { + + public Comparable object; + public ListNode next; + //public ListNode head; + + } + + public ListNode head; + // set by find to allow remove to remove the found node + private ListNode current; + private ListNode previous; + + public String toString() { + /* algorithm + set up a string to contain the list details + if list not empty then + set current node to head of list + while nodes remain loop + add the node object to the string + move to next node + end loop + else + add empty list message to the string + end if + */ + String listDetails = new String(); + if (this.head != null) { + ListNode current = this.head; + while (current != null) { + listDetails += current.object + "\n"; + current = current.next; + } + } else { + listDetails += "list is empty"; + } + return listDetails; + } + + public void insertCar(Comparable object) throws NotUniqueException { + /* algorithm + create a new node //will create component object reference + if list empty then + add to head of list + else + set current node to head of list + while insertion position not yet found loop + if current object matches object to be added then + // attempt to add duplicate object + throw not unique exception + end if + if insertion point found then + link the new node to the current node + if current node is the head then + // add to the front of the list + link the head to the new node + else + link the previous node to the new node + end if + else + if current node is the last in the list + // add at end + link the current node to the new node + else + // move to the next node + set the previous node as the current node + set the current node to the next node + end if + end if + end loop + end if + */ + ListNode newNode = new ListNode(); + newNode.object = object; + if (this.head == null) { + this.head = newNode; + } else { + ListNode current = this.head; + // require to explicitly set to null to avoid compilation error + ListNode previous = null; + Boolean insertionPositionFound = false; + while (!insertionPositionFound) { + if (object.compareTo(current.object) == 0) { + throw new NotUniqueException(); + } + if (object.compareTo(current.object) < 0) { + insertionPositionFound = true; + newNode.next = current; + if (current == this.head) { + this.head = newNode; + } else { + previous.next = newNode; + } + } else if (current.next == null) { + insertionPositionFound = true; + current.next = newNode; + } else { + previous = current; + current = current.next; + } + } + } + } + + public Comparable find(Comparable object) throws NotFoundException { + /* algorithm + if list empty then + throw not found exception + end if + set current node to head of list + while object not found loop + if object matches current node object then + object found + else + if object is less than current object then + // object is not in the list + throw not found exception + else + if no more objects to compare with then + // object is not in the list + throw not found exception + else + // move to the next node + set the previous node to the current node + set the current node to the next node + end if + end if + end if + end loop + */ + if (this.head == null) { + throw new NotFoundException(); + } + Comparable foundObject = null; + this.current = this.head; + while (foundObject == null) { + if (object.compareTo(this.current.object) == 0) { + foundObject = this.current.object; + } else if (object.compareTo(this.current.object) < 0) { + throw new NotFoundException(); + } else if (this.current.next == null) { + throw new NotFoundException(); + } else { + this.previous = this.current; + this.current = this.current.next; + } + } + return foundObject; + } + + public Comparable remove(Comparable object) throws NotFoundException { + /* algorithm + find the object //sets up current and previous + if current node is the head then + link the head to the next node + else + link the previous node to the next node + end if + remove object and link from current node + */ + // current will refer to the node to be removed + // previous will refer to the node immediately before the one to be removed + Comparable removedObject = this.find(object); + if (this.current == this.head) { + this.head = this.current.next; + } else { + this.previous.next = this.current.next; + } + this.current.object = null; + this.current.next = null; + return removedObject; + } + +}