Reference no: EM133388771
Introduction
This assignment consists of three parts, each with their own weight in the final grade. You will create a model of a galaxy with stars and planets and build a graphical user interface to examine and if needed change it. The stars and planets are generated by another application and provided as .csv files.
You start by importing the provided Eclipse project. In it you will find some domain classes (Body, Star, Planet and Coordinate and a few helper classes and enumerations. Especially the enumerations contain a lot of information, read them!
Start the assignments from there. There also is a test set with Stars; use (a subset of) this to load data into the application. When required a much larger dataset is also available (but too large to put on the server.)
Assignment 1a
First implement a few generic utilities.
Open the class called MathUtil. Implement a static method which calculates the distance between two Bodies or subclasses thereof. Make the method itself inherently generic, do not trust on mere type checking.
Change the class Coordinate so it uses the new method.
Assignment 1b
The next thing to do is getting the data into collections. These collections need specific functionality.
StarCollection
Create a class called StarCollection. This collection only accepts subclasses of Body. When trying to add an already existing Body (as defined by the equals method of Body) it will not add it but return false.
When creating an object of this class it should read the .csv file provided as a (String) parameter and fill the collection with objects created from the file's contents.
Whenever adding a Star to the collection check that:
• The new star is not between 0.03 and 0.3 parsecs from an already existing star
• Not within 0.01 parsecs of an existing star
• Not within 0.3 parsecs of a double star
Whenever adding a star to the collection check whether it is within 0.1 parsecs of exactly one star which is not already a double star; if so, update both stars to reflect them being a double star.
Give the class methods to:
• Return a Set of stars of a given StarType (public Set<Star> x getStarList(StarType type)
• Give a Star with the given designation (public Star find(String designation) Use Delegation of Responsibility to implement this.
Adapting Planet
With the test set you will be able to fill the collection with all stars, but with the full set that is way too much. Internally you need to generate the planets whenever one is needed. The class Planet has a static method to generate a random planet for a star, which if given the same star with the same index and the same seed will yield the same planet all the time. Change this method so it no longer uses an explicit seed but derives it from properties of the star and the distance of the planet.
Add a method which gives a List of Planets, not just a single one. Use the data from the Enumeration StarType to determine how many planets to generate; assume the distance from the planet to the star doubles for each subsequent one1 and spread them over the whole distance (from minimum to maximum.)
PlanetCollection
Create a class called PlanetCollection. This class behaves like a Map<Star, List<Body>>. It is also possible to iterate over its keys without explicitly getting the keyset, so it implements Iterable<List<Body>, giving a list with at index 0 the star and then in order the planets in the star system.
When adding a Star to an object of this class it should only really store the star itself in its internal data, but when retrieving a value (as in myPlanetCollection.get(myStar) it will return a List with the (generated at that time) planets.
Use Delegation of Responsibility to implement this.
Assignment 1c
The current code needs to be tested. Create a class with a main method. Instantiate an object of the class StarCollection, which should mean the data from the file is loaded. Create an object of type PlanetCollection and add all stars to it.
Remove stars having either no planets or only planets of types R, T, Y from the planet collection. Remove stars having no planets from the star collection.