Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Value 10% Abstract Planets Overview: Build and Implement the following classes a

ID: 3860811 • Letter: V

Question

Value 10% Abstract Planets Overview: Build and Implement the following classes and interfaces. This is a solo assignment. Maximum Mark: 68 Hafangs Fields dismeteri double type:string Meted e.moonCount in :Giantplaneti.mngname double dametar, double mam, tring type) ingCounti int Properties Diametere double Hslbable MoonCountlget set::in -flame (9 ):string Ratation Period Iget sat l: doubla Methods - Filds enbool Habitable(1 : bool TemestiaPlanetsong narne double dimeter double mass, bool ooygen -Method Progam Mathod Instructions (50 Marks: Functionality, 8 Marks: Program Structure, 6 Marks: Internal Documentation, 4 Marks: Version Control) 1. The Abstract Class Planet must include the following Properties and Methods: (24 Marks: Private Instance Variables:-diameter (double),-mass (double),-moonCount (int), name (string), orbitalPeriod (double), ringCount (int),_rotationPeriod (double) (7 Marks: Functionality) Public Properties: Diameter (Read Only), Mass (Read Only), MoonCount, Name (Read Only), OrbitalPeriod, RingCount, and RotationPeriod (7 Marks: Functionality). The constructor Method should take name, diameter and mass as local variables and set the related instance variables name,_diameter and_mass) to their values (6 Marks: Functionality) a. b. c.

Explanation / Answer

GiantPlanet.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    class GiantPlanet : Planet, IHasMoons, IHasRings

    {
      
        ///Private Properties
        private string _type;

        //Constructor
        public GiantPlanet(string name, double diameter, double mass, string type)
            : base(name, diameter, mass)
        {
            this._type = type;
            Console.WriteLine("****************************************");
            Console.WriteLine("This Giant planet type is: {0}",_type);
        }

          
        // Public method to check if the Giant Planet has moons
        public bool HasMoons()
        {
            bool hasMoons;
            if (MoonCount > 0)
            {
                hasMoons = true;
                Console.WriteLine("This Giant Planet has moons");
            }
            else
            {
                hasMoons = false;
                Console.WriteLine("This Giant Planet does not has moons");
            }
            return hasMoons;
        }

        // Public method to check if the Giant Planet has rings
        public bool HasRings()
        {
            bool hasRings;
            if (RingCount > 0)
            {
                hasRings = true;
                Console.WriteLine("This Giant Planet has rings");
            }
            else
            {
                hasRings = false;
                Console.WriteLine("This Giant Planet does not has rings");
            }
            return hasRings;
          
        }

    }
}


IHabitable.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    interface IHabitable
    {
        bool Habitable();
    }
}

IHasMoons.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    interface IHasMoons
    {
        bool HasMoons();
    }
}

Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    class Program
    {
        static void Main(string[] args)
        {
            //New Giant Planet Object
            GiantPlanet Saturno = new GiantPlanet("SATURNO",120536, 5683190000000000000,"Gas");
            Saturno.MoonCount = 31;
            Saturno.OrbitalPeriod = 30;
            Saturno.RingCount = 7;
            Saturno.RotationPeriod = 10.2;
            Saturno.HasMoons();
            Saturno.HasRings();
            Saturno.ToString();

            //New Giant Terrestrial Object
            TerrestrialPlanet Tierra = new TerrestrialPlanet("TIERRA", 12742, 59721900000000,true);
            Tierra.MoonCount = 1;
            Tierra.OrbitalPeriod = 1;
            Tierra.RingCount = 0;
            Tierra.RotationPeriod = 1;
            Tierra.HasMoons();
            Tierra.Habitable();
            Tierra.ToString();
        }
    }
}

TerrestrialPlanet.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    class TerrestrialPlanet : Planet, IHasMoons, IHabitable
    {
         ///Private Properties
        private bool _oxygen;

        //Constructor
        public TerrestrialPlanet(string name, double diameter, double mass, bool oxygen)
            : base(name, diameter, mass)
        {
            this._oxygen = oxygen;
        }

        // Public method to check if the Terrestrial Planet has moons
        public bool HasMoons()
        {
            bool hasMoons;
            if (MoonCount > 0)
            {
                hasMoons = true;
                Console.WriteLine("This Terrestrial Planet has rings");
            }
            else
            {
                hasMoons = false;
                Console.WriteLine("This Giant Planet does not has moons");
            }
            return hasMoons;
        }
        // Public method to check if the Terrestrial Planet is Habitable
        public bool Habitable()
        {

            if (_oxygen == true)
            {
                Console.WriteLine("This Terrestrial Planet is Habitable");
            }
            if (_oxygen == false)
            {
                Console.WriteLine("This Terrestrial Planet is not Habitable");
            }
            return _oxygen;
        }
    }
}


Planet.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    abstract class Planet
    {
        ////Private Instance Variables
        private double _diameter;
        private double _mass;
        private int _moonCount;
        private string _name;
        private double _orbitalPeriod;
        private int _ringCount;
        private double _rotationPeriod;

        ////Public Properties
        public double Diameter
        {
            get
            {
                return this._diameter;

            }

        }
        public double Mass
        {
            get
            {
                return this._mass;

            }
        }

        public string Name
        {
            get
            {
                return this._name;

            }
        }

        public int MoonCount
        {
            get
            {
                return this._moonCount;
            }

            set
            {
                this._moonCount = value;
            }
        }

        public double OrbitalPeriod
        {
            get
            {
                return this._orbitalPeriod;
            }

            set
            {
                this._orbitalPeriod = value;
            }
        }

        public int RingCount
        {
            get
            {
                return this._ringCount;
            }

            set
            {
                this._ringCount = value;
            }
        }

        public double RotationPeriod
        {
            get
            {
                return this._rotationPeriod;
            }

            set
            {
                this._rotationPeriod = value;
            }
        }

        //Constructor

        public Planet(string name, double diameter, double mass)
        {

            this._name = name;
            this._diameter = diameter;
            this._mass = mass;
        }

          
        //Public method to show in console the object properties
        public override string ToString()
        {

          
            Console.WriteLine("Name: {0}", this.Name);
            Console.WriteLine("Diameter: {0}",this.Diameter);
            Console.WriteLine("Mass: {0}", this.Mass);
            Console.WriteLine("Number of Moons: {0}", this.MoonCount);
            Console.WriteLine("Orbital Period: {0} year(s)", this.OrbitalPeriod);
            Console.WriteLine("Number of Rings: {0}", this.RingCount);
            Console.WriteLine("Rotation Period: {0} day(s)", this.RotationPeriod);
            Console.WriteLine("*****************************************");
            Console.ReadKey();
            return this.Name;
        }
    }
}

IHasRings.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment03
{
    interface IHasRings
    {
        bool HasRings();
    }
}