Menu

[Solved]Use Dbpm Class Construction Format Create Classes Attributes Methods Modify Universe Progr Q37075040

Use the DBPM Class Construction Format to create all ofthe classes, attributes and methods.

MODIFY THE UNIVERSE PROGRAM: Universe.java

Modify the existing program to expand the currentuniverse.
A. Add one Star called Sun. Specify the Name, Size and Distancefrom the Sun.
B. Two planets called Earth (name=”Blue Planet”) with one moon(called blueMoon),
and Mars (name=”Red Planet”) with two moons (Deimus andPhobos).
-For each planet specify the name, size and distance from theSun.
-For each moon specify the name, size and distance from itsplanet.

Comment out all other program code and verify that steps A and Bwill compile without error.

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

2. Comments “**MODIFICATION NEEDED**” will indicate ifadditional coding is required

package universe;

import java.util.ArrayList;

// NO CHANGES REQUIRED FOR THIS CLASS

// CelestialObject is a fully DBPM implemented class with anabstract

method:

// a default constructor, overloaded constructors, setters andgetters

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 constructordistance

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(CelestialObjectotherObj);//

abstract method

}

//**MODIFICATION NEEDED**

// write the concrete method forcalculateDistanceBetweenCelestialObject()

class Star extends CelestialObject { // Star Class

}

//**MODIFICATION NEEDED**

// write the concrete method forcalculateDistanceBetweenCelestialObject()

class Moon extends CelestialObject { // Moon Class

}

// NO CHANGES REQUIRED:

class Planet extends CelestialObject { // Planet Class

private ArrayList <Moon> moon = new ArrayList<Moon>() ;

// moon attribute

public Planet() {} // default

constructor

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

moon the the planet

public Planet(ArrayList <Moon> 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> moon)

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

array of moons the the planet

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

array of moons

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

get an individual moon

public doublecalculateDistanceBetweenCelestialObject(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 exampleto follow.

//For the planet attribute:

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

class SolarSystem {

private Star star;

private ArrayList <Planet> planet = new ArrayList<Planet>() ;

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 thesolarsystem

public SolarSystem(Star star, ArrayList <Planet>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 anexample to

follow.

//For the solarSystem attribute:

// Create 1 default constructor, 1 overloaded constuctor, 1setter, 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 anexample to

follow.

//Create a galaxy attribute of type Galaxy:

//Create 1 default constructor, 1 overloaded constuctor, 1setter, 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 sizeof

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 asthe

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 SolarSystemInterStellerSpace

// 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, twoplanets

with their own moons and all the details

System.out.println(“The Solor System contains thefollowing”);

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

}

}

Expert Answer


Answer to Use the DBPM Class Construction Format to create all of the classes, attributes and methods. MODIFY THE UNIVERSE PROGRAM… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *