Question

In: Computer Science

Create four classes named: Planet, solarSystem, Earth and Moon, 1. Think how to use inheritance in...

Create four classes named: Planet, solarSystem, Earth and Moon,
1. Think how to use inheritance in three classes
2. solarSystem has
Name, color, Diameter_Miles, dist_From_Sun and perimeter =(float) 3.14*Diameter_Miles;
3. Moon has the following attributes:
Name, color, Diameter_Miles, dist_From_Sun, surface_area = 4*3.14*Radius*Radius;
And volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles);
4. Planet has the following attributes:
Name, color, Diameter_Miles, dist_From_Sun and volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles);
5. Earth has the following attributes:
Name, color, Diameter_Miles, dist_From_Sun and volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles);
Every class has constructor to initialize the input variables and measurements Method that prints the following:
From the solarSystem Class consider the following inputs: name ="solar System", color="multi", Diameter_Miles=7500000000L, dist_From_Sun =3666000000L
The output should be:
Name Of The solarSystem : solar System
Colour Of The solarSystem : multi
Distance From the Sun : 3666000000 miles
Perimeter of the solarSystem : 2.35500012E10 miles
--------------------------------------
From the Planet Class consider the following inputs: name =" Earth ", color=" blue", Diameter_Miles=3959L, dist_From_Sun =93000000L
The output should be:
Name Of The Planet : Earth
Colour Of The Planet : blue
Distance From the Sun is : 93000000 miles
Volume Of The Planet : 1.9484360366806003E11 cubic units
From the Earth Class consider the following inputs: name =" Earth ", color=" blue", Diameter_Miles=3959L, dist_From_Sun =93000000L
The output should be:
Name Of The Planet : Earth
Colour Of The Planet : blue
Distance From the Sun is : 93000000 miles
Volume Of The Planet : 1.9484360366806003E11 cubic units
-----------------
From the Moon Class consider the following inputs: name =" Luna", color=" silvery ", Diameter_Miles=1740L, dist_From_Sun =238900L
The output should be:
Name Of The Moon : Luna
Colour Of The Moon : silvery
Distance From the Mother Planet : 238900 miles
Surface area Of The Moon : 3.8026656E7 km^2
---------------

java

Solutions

Expert Solution

//Java code

public  class SolarSystem {
    /**
     * Name, color, Diameter_Miles,
     * dist_From_Sun and perimeter =(float) 3.14*Diameter_Miles;
     */
    protected String name;
    protected String color;
    protected float diameter_miles;
    protected  float dist_From_Sun;
    //Constructor

    public SolarSystem(String name, String color, float diameter_miles, float dist_From_Sun) {
        this.name = name;
        this.color = color;
        this.diameter_miles = diameter_miles;
        this.dist_From_Sun = dist_From_Sun;
    }
    //Getters and setters

    public String getName() {
        return name;
    }

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

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public float getDiameter_miles() {
        return diameter_miles;
    }

    public void setDiameter_miles(float diameter_miles) {
        this.diameter_miles = diameter_miles;
    }

    public float getDist_From_Sun() {
        return dist_From_Sun;
    }

    public void setDist_From_Sun(float dist_From_Sun) {
        this.dist_From_Sun = dist_From_Sun;
    }
    public float perimeter()
    {
        return (float) (Math.PI*diameter_miles);
    }

    @Override
    public String toString() {
        return "Name Of The solarSystem : "+name+"\n" +
                "Colour Of The solarSystem : "+color+"\n" +
                "Distance From the Sun : "+dist_From_Sun+" miles\n" +
                "Perimeter of the solarSystem : "+perimeter()+" miles";
    }
}

//=====================================================

public  class Planet extends SolarSystem {
    public Planet(String name, String color, float diameter_miles, float dist_From_Sun) {
        super(name, color, diameter_miles, dist_From_Sun);
    }

    public double volume()
    {
        /**
         * (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles);
         */
        float radius = (float) (diameter_miles);
        return (float) ((4/3)*(Math.PI)*radius*radius*radius);
    }

    @Override
    public String toString() {
        return "Name Of The Planet : "+name+"\n" +
                "Colour Of The Planet : "+color+"\n" +
                "Distance From the Sun is : "+dist_From_Sun+" miles\n" +
                "Volume Of The Planet : "+volume()+" cubic units";
    }
}

//==================================================

public class Moon extends SolarSystem {
    public Moon(String name, String color, float diameter_miles, float dist_From_Sun) {
        super(name, color, diameter_miles, dist_From_Sun);
    }
    public float surface_area()
    {
        float radius = (float) (diameter_miles);
        return (float) (4*Math.PI*radius*radius);
    }
    public float volume()
    {
        float Radius_Miles = (float) (diameter_miles/2.0);
        return (float) ((4.0/3.0)*(Math.PI)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles));
    }
    @Override
    public String toString() {
        return "Name Of The Moon : "+name+"\n" +
                "Colour Of The Moon : "+color+"\n" +
                "Distance From the Mother Planet : "+dist_From_Sun+" miles\n" +
                "Surface area Of The Moon : "+surface_area()+" km^2";
    }
}

//====================================================

public class Earth extends Planet {
    public Earth(String name, String color, float diameter_miles, float dist_From_Sun) {
        super(name, color, diameter_miles, dist_From_Sun);
    }

    @Override
    public String toString() {
        return super.toString();
    }
}

//==============================================

public class TestPlanet {
    public static void main(String[] args)
    {
        SolarSystem solarSystem = new SolarSystem("Solar System","Multi",7500000000L,3666000000L);
        System.out.println(solarSystem);
        System.out.println("==============================");
        Planet planet = new Planet("Earth","blue",3959L,93000000L);
        System.out.println(planet);
        System.out.println("==============================");
        Earth earth = new Earth("Earth","blue",3959L,93000000L);
        System.out.println(earth);
        System.out.println("==============================");
        Moon moon = new Moon("Luna","silvery",1740L,238900L);
        System.out.println(moon);
        System.out.println("==============================");

    }
}

//Output

//If you need any help regarding this solution .......... please leave a comment ........ thanks


Related Solutions

Create four classes named: Planet, solarSystem, Earth and Moon, 1. Think how to use inheritance in...
Create four classes named: Planet, solarSystem, Earth and Moon, 1. Think how to use inheritance in three classes 2. solarSystem has Name, color, Diameter_Miles, dist_From_Sun and perimeter =(float) 3.14*Diameter_Miles; 3. Moon has the following attributes: Name, color, Diameter_Miles, dist_From_Sun, surface_area = 4*3.14*Radius*Radius; And volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles); 4. Planet has the following attributes: Name, color, Diameter_Miles, dist_From_Sun and volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles); 5. Earth has the following attributes: Name, color, Diameter_Miles, dist_From_Sun and volume = (4/3)*(3.14)*(Radius_Miles)*(Radius_Miles)*(Radius_Miles); Every class has constructor to initialize...
Planet Lex is four times as massive as the Earth and has a radius four times...
Planet Lex is four times as massive as the Earth and has a radius four times larger than the Earth's radius. Note: You do not have to express your answers in scientific notation. Mass of the Earth = 5.97 x 1024 kg Radius of the Earth = 6.37 x 106 m a. What is the value of the acceleration due to gravity (in m/s2) on the surface of this planet? Round off your answer up to two decimal digits. b....
Earth and Moon Questions What does the term moon mean? How big is the moon (diameter,...
Earth and Moon Questions What does the term moon mean? How big is the moon (diameter, volume, comparison to earth)? Describe the main surface features of the moon? What are some of the more important discoveries of the Apollo program? Does the flag fly on the moon? What is the theory of the origin of the moon? What are the major effects of the moon on the earth? What is an eclipse? Describe the 2 kinds. What are time zones?  ...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problems [30 marks] Problem 1: The Account class...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problem : The Fraction class (Filename: TestFraction.java) Design...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the...
Create an enumeration named Planet that holds the names for the eight planets in our solar...
Create an enumeration named Planet that holds the names for the eight planets in our solar system, starting with MERCURY equal to 1 and ending with NEPTUNE. Write a program named Planets that prompts the user for a numeric position, and display the name of the planet that is in the requested position. For example, if 3 is input, the output would be: EARTH is 3 planet(s) from the sun Answer in C# (Posting incomplete and probably wrong code that...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Think of an imaginary product, and create content for the advertisement of it. Use four headings...
Think of an imaginary product, and create content for the advertisement of it. Use four headings according to the AIDA model: Attention, Interest, Desire, and Action. Write 50-80 words. [10 marks] • While writing, ensure coherence. • Take care of the formality of the language. • Provide name and type of the product in the beginning of the answer. • Product must be unique and could be anything.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT