Create a class called Planet eg httpsenwikipediaorgwikiSolar

Create a class called Planet (e.g. https://en.wikipedia.org/wiki/Solar_System) . It has instance variables, constructor parameters, and accessor methods for the following data:

- String name
- boolean innerPlanet
- double astronomicalUnitsFromSun
- double earthMasses

Create a method called getPlanetaryData() which returns a String in the exact format of “Mercury is an inner planet, weighs 0.055 Earth masses, and is 0.4 AU from the Sun.” or “Jupiter is an outer planet, weighs 318 Earth masses, and is 5.2 AU from the Sun.”, etc….

Create another method with the signature public Boolean isSimilarToEarth() which returns true if and only if the Planet is less than 1AU from the Sun or weighs less than 15 Earth masses.

Create a Main class with a main method. The main method creates all eight Planet objects for our solar system, calls each Planet’s getPlanetaryData() method, and also reports in one sentence for Planet whether the Planet is similar to Earth, in the format of “Jupiter is not similar to Earth.”.

Solution

public class Planet

{

private String name;

private boolean innerPlanet;

private double astronomicalUnitsFromSun;

private double earthMasses;

Planet(String s,boolean inner,double mass,double au)

{

name=s;

innerPlanet=inner;

earthMasses=mass;

astronomicalUnitsFromSun=au;

}

public Boolean isSimilarToEarth()

{

if(astronomicalUnitsFromSun<1||earthMasses<15)

return true;

return false;

}

public String getPlanetaryData()

{

return name+\"is an inner planet:\"+ innerPlanet+\" weighs \"+ earthMasses +\"Earth masses, and is\"+ astronomicalUnitsFromSun+\"AU from the Sun.”

}

public boolean getInnerPlanet()

{

return innerPlanet;

}

public double getMasses()

{

return earthMasses;

}

public double getAU()

{

return astronomicalUnitsFromSun;

}

public String getName()

{

return name;

}

}

Create a class called Planet (e.g. https://en.wikipedia.org/wiki/Solar_System) . It has instance variables, constructor parameters, and accessor methods for the
Create a class called Planet (e.g. https://en.wikipedia.org/wiki/Solar_System) . It has instance variables, constructor parameters, and accessor methods for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site