From cf4c1ad9d0cda5306828d691409596ca161d90bf Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 31 Mar 2022 17:49:49 +0200 Subject: [PATCH] Refactor for AB3 --- src/BodyForceTreeMap.java | 37 +++++++++------- src/BodyLinkedList.java | 93 +++++++++++++++++++++++---------------- src/Simulation3.java | 11 ++--- 3 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/BodyForceTreeMap.java b/src/BodyForceTreeMap.java index 26dba11..11bab25 100644 --- a/src/BodyForceTreeMap.java +++ b/src/BodyForceTreeMap.java @@ -1,40 +1,45 @@ -// A map that associates a Body with a Vector3 (typically this is the force exerted on the body). -// The number of key-value pairs is not limited. +/** + * A map that associates a Body with a Vector3 (typically this is the force exerted on the body). + * The number of key-value pairs is not limited. + */ public class BodyForceTreeMap { //TODO: declare variables. - // Adds a new key-value association to this map. If the key already exists in this map, - // the value is replaced and the old value is returned. Otherwise 'null' is returned. - // Precondition: key != null. + /** + * Adds a new key-value association to this map. If the key already exists in this map, + * the value is replaced and the old value is returned. Otherwise 'null' is returned. + * Precondition: key != null. + */ public Vector3 put(Body key, Vector3 value) { - //TODO: implement method. return null; } - // Returns the value associated with the specified key, i.e. the method returns the force vector - // associated with the specified key. Returns 'null' if the key is not contained in this map. - // Precondition: key != null. + /** + * Returns the value associated with the specified key, i.e. the method returns the force vector + * associated with the specified key. Returns 'null' if the key is not contained in this map. + * Precondition: key != null. + */ public Vector3 get(Body key) { - //TODO: implement method. return null; } - // Returns 'true' if this map contains a mapping for the specified key. + /** + * Returns 'true' if this map contains a mapping for the specified key. + */ public boolean containsKey(Body key) { - //TODO: implement method. return false; } - // Returns a readable representation of this map, in which key-value pairs are ordered - // descending according to the mass of the bodies. + /** + * Returns a readable representation of this map, in which key-value pairs are ordered + * descending according to the mass of the bodies. + */ public String toString() { - //TODO: implement method. return null; - } } diff --git a/src/BodyLinkedList.java b/src/BodyLinkedList.java index 833afda..1e0ceef 100644 --- a/src/BodyLinkedList.java +++ b/src/BodyLinkedList.java @@ -1,102 +1,117 @@ -// A list of bodies implemented as a linked list. -// The number of elements of the list is not limited. +/** + * A list of bodies implemented as a linked list. + * The number of elements of the list is not limited. + */ public class BodyLinkedList { //TODO: declare variables. - // Initializes 'this' as an empty list. + /** + * Initializes 'this' as an empty list. + */ public BodyLinkedList() { - //TODO: define constructor. } - // Initializes 'this' as an independent copy of the specified list 'list'. - // Calling methods of this list will not affect the specified list 'list' - // and vice versa. - // Precondition: list != null. + /** + * Initializes 'this' as an independent copy of the specified list 'list'. + * Calling methods of this list will not affect the specified list 'list' + * and vice versa. + * Precondition: list != null. + */ public BodyLinkedList(BodyLinkedList list) { - //TODO: define constructor. } - // Inserts the specified element 'body' at the beginning of this list. + /** + * Inserts the specified element 'body' at the beginning of this list. + */ public void addFirst(Body body) { - //TODO: implement method. } - // Appends the specified element 'body' to the end of this list. + /** + * Appends the specified element 'body' to the end of this list. + */ public void addLast(Body body) { - //TODO: implement method. } - // Returns the last element in this list. - // Returns 'null' if the list is empty. + /** + * Returns the last element in this list. + * Returns 'null' if the list is empty. + */ public Body getLast() { - //TODO: implement method. return null; } - // Returns the first element in this list. - // Returns 'null' if the list is empty. + /** + * Returns the first element in this list. + * Returns 'null' if the list is empty. + */ public Body getFirst() { - //TODO: implement method. return null; } - // Retrieves and removes the first element in this list. - // Returns 'null' if the list is empty. + /** + * Retrieves and removes the first element in this list. + * Returns 'null' if the list is empty. + */ public Body pollFirst() { - //TODO: implement method. return null; } - // Retrieves and removes the last element in this list. - // Returns 'null' if the list is empty. + /** + * Retrieves and removes the last element in this list. + * Returns 'null' if the list is empty. + */ public Body pollLast() { - //TODO: implement method. return null; } - // Inserts the specified element 'body' at the specified position in this list. - // Precondition: i >= 0 && i <= size(). + /** + * Inserts the specified element 'body' at the specified position in this list. + * Precondition: i >= 0 && i <= size(). + */ public void add(int i, Body body) { - //TODO: implement method. } - // Returns the element at the specified position in this list. - // Precondition: i >= 0 && i < size(). + /** + * Returns the element at the specified position in this list. + * Precondition: i >= 0 && i < size(). + */ public Body get(int i) { - //TODO: implement method. return null; } - // Returns the index of the first occurrence of the specified element in this list, or -1 if - // this list does not contain the element. + /** + * Returns the index of the first occurrence of the specified element in this list, or -1 if + * this list does not contain the element. + */ public int indexOf(Body body) { - //TODO: implement method. return -2; } - // Removes all bodies of this list, which are colliding with the specified - // body. Returns a list with all the removed bodies. + /** + * Removes all bodies of this list, which are colliding with the specified + * body. Returns a list with all the removed bodies. + */ public BodyLinkedList removeCollidingWith(Body body) { - //TODO: implement method. return null; } - // Returns the number of bodies in this list. + /** + * Returns the number of bodies in this list. + */ public int size() { - //TODO: implement method. return -1; } diff --git a/src/Simulation3.java b/src/Simulation3.java index 55596f7..b5d1fad 100644 --- a/src/Simulation3.java +++ b/src/Simulation3.java @@ -1,11 +1,12 @@ -// Simulates the formation of a massive solar system. -// +/** + * Simulates the formation of a massive solar system. + */ public class Simulation3 { - // The main simulation method using instances of other classes. + /** + * The main simulation method using instances of other classes. + */ public static void main(String[] args) { - //TODO: change implementation of this method according to 'Aufgabenblatt3.md'. - } }