Question: MODIFY THE UNIVERSE PROGRAM: Universe.java Modify the existing program to expand the current universe. A. Add one Star called Sun. Specify the Name, Size and

MODIFY THE UNIVERSE PROGRAM: Universe.java

Modify the existing program to expand the current universe. A. Add one Star called Sun. Specify the Name, Size and Distance from the Sun. B. Two planets called Earth (name="Blue Planet") with one moon (called blueMoon), and Mars (name="Red Planet") with two moons (Deimus and Phobos). -For each planet specify the name, size and distance from the Sun. -For each moon specify the name, size and distance from its planet.

C. Research the size of each CelestialObject and its distance from the sun (for planets) and the distance of the moons from the planets

D. Calculate the distance between any two CelestialObject (e.g. between 2 planets and or between two moons

1. Follow the naming patterns used by DBPM for all classes

2. Comments "**MODIFICATION NEEDED**" will indicate if additional coding is required

*/

***Program***

package universe;

import java.util.ArrayList;

// NO CHANGES REQUIRED FOR THIS CLASS

// CelestialObject is a fully DBPM implemented class with an abstract

method:

// a default constructor, overloaded constructors, setters and getters

abstract class CelestialObject {

private String name; // name attribute

private double size; // size attribute

private long distance; // distance attribute

public CelestialObject() { this.name = ""; this.size =

0.0; this.distance = 0; } // default constructor

public CelestialObject(String name) { this.name = name; this.size =

0.0; this.distance = 0; } // overloaded constructor name

public CelestialObject(double size) { this.name = ""; this.size =

size;this.distance = 0; } // overloaded constructor size

public CelestialObject(int distance) { this.name = ""; this.size =

0.0; this.distance = distance; } // overloaded constructor distance

public CelestialObject(String name,

double size,

int distance) { this.name = name; this.size =

size; this.distance = distance; } // overloaded constructor

name,sizedistancer

public void setName(String name) { this.name = name; } //

setter method name

public void setSize(double size) { this.size = size; } //

setter method size

public void setDistance(long distance){ this.distance = distance; } //

setter method distance

public String getName() { return this.name; } //

getter method name

public double getSize() { return this.size; } //

getter method size

public long getDistance() { return this.distance; } //

getter method distance

abstract public double

calculateDistanceBetweenCelestialObject(CelestialObject otherObj);//

abstract method

}

//**MODIFICATION NEEDED**

// write the concrete method for calculateDistanceBetweenCelestialObject()

class Star extends CelestialObject { // Star Class

}

//**MODIFICATION NEEDED**

// write the concrete method for calculateDistanceBetweenCelestialObject()

class Moon extends CelestialObject { // Moon Class

}

// NO CHANGES REQUIRED:

class Planet extends CelestialObject { // Planet Class

private ArrayList moon = new ArrayList () ;

// moon attribute

public Planet() {} // default

constructor

public Planet(Moon moon) { this.moon.add(moon); } // adding a

moon the the planet

public Planet(ArrayList moon)

{ this.moon = moon; } // adding an

array of moons the the planet

public void setMoon(Moon moon) { this.moon.add(moon); } // adding a

moon the the planet

public void setMoon(ArrayList moon)

{ this.moon = moon; } // adding an

array of moons the the planet

public ArrayList getMoon() { return this.moon; } // get the

array of moons

public Moon getMoon(int position) { return this.moon.get(position); } //

get an individual moon

public double calculateDistanceBetweenCelestialObject(CelestialObject

otherPlanet) {

return this.getDistance() - otherPlanet.getDistance();}

}

//**MODIFICATION NEEDED**

//Use the DBPM format to complete the class.

//Review the Planet class for the moon attribute as an example to follow.

//For the planet attribute:

// Create 2 overloaded constuctors, two setters, two getters

class SolarSystem {

private Star star;

private ArrayList planet = new ArrayList () ;

public SolarSystem() {} // default

constructor

public SolarSystem(Star star) { this.star = star; } // overloaded

constructor star

public SolarSystem(Star star, Planet planet)

{ this.star = star;

this.planet.add(planet); } // adding a star/planet to the solarsystem

public SolarSystem(Star star, ArrayList planet)

{ this.star = star; this.planet =

planet; } // adding a star/planets to the solarsystem

public void setStar(Star star) { this.star = star; } // setter

method name

public Star getStar() { return this.star; } // getter

method name

}

//**MODIFICATION NEEDED**

//Use the DBPM format to complete the class.

//Review the SolarSystem class for the Star attribute as an example to

follow.

//For the solarSystem attribute:

// Create 1 default constructor, 1 overloaded constuctor, 1 setter, 1

getter

class Galaxy {

SolarSystem solarSystem;

}

//**MODIFICATION NEEDED**

//Use the DBPM format to complete the class.

//Review the SolarSystem class for the Star attribute as an example to

follow.

//Create a galaxy attribute of type Galaxy:

//Create 1 default constructor, 1 overloaded constuctor, 1 setter, 1

getter

public class Universe {

// Create a galaxy attritute of type Galaxy

//**MODIFICATION NEEDED**

public static void main(String[] args) {

// Create a star call Sun and set the name to SOL, set the size, no

distance is needed

// Create two planet objects called Earth and Mars

// Set the Planet names (Blue Planet and Red Planet), the size of

each planet and the distance from the sun

// Create one moon for Earth called BlueMoon (named Blue moon), set

the size and the distance from the Earth object

// set the BlueMoon to Earth object

// Create two moons for Mars called Phobos and Deimus (use as the

name), set the size and the distance from the Mars object

// set the two moons to Mars

// Create a solarSystem called InterStellerSpace

// Set Sun (which is a star) to the SolarSystem InterStellerSpace

// Set the Planets, Earth and Mars to the SolarSystem

InterStellerSpace

// Create a galaxy object called MilkyWay

// Set InterStellerSpace solarSystem to the galaxy MilkyWay

// NO CHANGES REQUIRED

// This will test your logic and should show the sun, two planets

with their own moons and all the details

System.out.println("The Solor System contains the following");

System.out.println("-- Sun Information --");

System.out.println(" Name : " +

MilkyWay.getSolarSystem().getStar().getName());

System.out.println(" Size : " +

MilkyWay.getSolarSystem().getStar().getSize());

for (int i = 0; i < MilkyWay.getSolarSystem().getPlanet().size();

i ++){

System.out.println(" ++ Planet Information ++");

System.out.println(" Name : " +

MilkyWay.getSolarSystem().getPlanet(i).getName());

System.out.println(" Size : " +

MilkyWay.getSolarSystem().getPlanet(i).getSize());

System.out.println(" Distance: " +

MilkyWay.getSolarSystem().getPlanet(i).getDistance());

// for the moons for each planet

for (int m = 0; m <

MilkyWay.getSolarSystem().getPlanet(i).getMoon().size(); m ++){

System.out.println(" !! Moon Information !!");

System.out.println(" Name : " +

MilkyWay.getSolarSystem().getPlanet(i).getMoon(m).getName());

System.out.println(" Size : " +

MilkyWay.getSolarSystem().getPlanet(i).getMoon(m).getSize());

System.out.println(" Distance: " +

MilkyWay.getSolarSystem().getPlanet(i).getMoon(m).getDistance());

}

}

//**MODIFICATION NEEDED**

// Calculate the distance between the two planets

}

}

************************************

OUTPUT EXAMPLE:

The Solor System contains the following -- Sun Information -- Name : SOL Size : 864938.0 ++ Planet Information ++ Name : Blue Planet Size : 3959.0 Distance: 92960000 !! Moon Information !! Name : Blue Moon Size : 1097.6 Distance: 238900 ++ Planet Information ++ Name : Red Planet Size : 2106.0 Distance: 141600000 !! Moon Information !! Name : Phobos Size : 6.9 Distance: 5738 !! Moon Information !! Name : Deimus Size : 3.9 Distance: 14576 The Distance between Earth Mars is -4.864E7

*****************************************

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!