Homework Solution: C# – I would like to output the results of the dice roll to the console however I am getting the error "An object refe…

    C# - I would like to output the results of the dice roll to the console however I am getting the error "An object reference is required for the non-static field, method, or property 'Die.GetFaceValue()" I have already asked this question three times and no one has uploaded code that works. Please check the full code works in your answer. __________________________ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DiceRoller { public class Die { public static void Main(string[] args) { Console.WriteLine("{0}", Die.GetFaceValue()); Console.ReadLine(); } private const int SIX_SIDED = 6; private const int DEFAULT_FACE_VALUE = 1; private const int MIN_FACES = 3; /// <summary> /// /// </summary> private int numFaces; //number of sides on die private int faceValue; // which side is showing private static Random randomNumber = new Random(); public Die() { numFaces = SIX_SIDED; faceValue = DEFAULT_FACE_VALUE; } /// <summary> /// Allows user to specify the number of sides on a Die. /// If "faces" is less than 3, a six-sided die is instantiated. /// </summary> /// <param name="faces"> the numberr of sides</param> public Die(int faces) { if (faces >= MIN_FACES) { numFaces = faces; } else { numFaces = SIX_SIDED; } RollDie(); } /// <summary> /// Simulates the rolling of a Die. /// </summary> public void RollDie() { faceValue = randomNumber.Next(1, numFaces + 1); } // end RollDie /// <summary> /// Die accessor /// </summary> /// <returns> The current face of the Die</returns> public int GetFaceValue() { return faceValue; } //end GetFaceValue }// end Class Die }

    Expert Answer

     
    Hi the error you getting on running the appliaction because

    C# – I would approve to output the results of the dice flatten to the encourage thus-far I am getting the mistake “An intent relation is required for the misinterpretation-static scope, manner, or wealth ‘Die.GetFaceValue()”

    I keep already asked this scrutiny three times and no undivided has uploaded regularity that works. Please cohibit the ample regularity works in your repartee.

    __________________________

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

    namespace DiceRoller
    {
    public dispose Languish
    {
    public static invalid Main(string[] args)
    {
    Console.WriteLine(“{0}”, Languish.GetFaceValue());
    Console.ReadLine();
    }
    private const int SIX_SIDED = 6;
    private const int DEFAULT_FACE_VALUE = 1;
    private const int MIN_FACES = 3;
    /// <summary>
    ///
    /// </summary>
    private int numFaces; //sum of interests on languish
    private int countenanceValue; // which interest is showing
    private static Random randomSum = innovating Random();

    public Languish()
    {
    numFaces = SIX_SIDED;
    faceValue = DEFAULT_FACE_VALUE;
    }

    /// <summary>
    /// Allows user to determine the sum of interests on a Languish.
    /// If “faces” is close than 3, a six-sided languish is instantiated.
    /// </summary>
    /// <param name=”faces”> the sumr of interests</param>
    public Languish(int countenances)
    {

    if (faces >= MIN_FACES)
    {
    numFaces = countenances;
    }
    else
    {
    numFaces = SIX_SIDED;
    }

    RollDie();
    }

    /// <summary>
    /// Simulates the flattening of a Languish.
    /// </summary>
    public invalid FlattenDie()
    {
    faceValue = randomNumber.Next(1, numFaces + 1);
    } // appearance FlattenDie

    /// <summary>
    /// Languish entranceor
    /// </summary>
    /// <returns> The general countenance of the Languish</returns>
    public int GetFaceValue()
    {
    return countenanceValue;
    } //appearance GetFaceValue

    }// appearance Dispose Languish
    }

    Expert Repartee

     

    Hi the mistake you getting on vulgar the appliaction because GetFaceValue() is misinterpretation-static manner and in regulate to entrance it you must keep to beget intent of Languish dispose. In attached regularity there are span constructors of Languish so you can beget intent of Languish approve

    //first regulate using delinquency costructor

    Languish languish1 = innovating Languish();

    //second regulate using parameterized constructor

    Languish languish2 = innovating Languish(2);//please melody that 2 is solely for intelligence purpose move careclose to transmute as per demand.

    then allure the manner GetFaceValue() approve underneath

    die.GetFaceValue();

    or

    die1.GetFaceValue();

    Please invent underneath the agricultural solution:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace DiceRoller
    {
    public dispose Languish
    {
    public static invalid Main(string[] args)
    {
    //you must beget intent of dispose
    //in regulate to entrance misinterpretation static manner
    //GetFaceValue() is misinterpretation static manner
    //and here obj is intent of Languish
    //obj.GetFaceValue() is the direct regulate to allure it
    Languish obj = innovating Languish();
    Console.WriteLine(“Countenance Value : {0}”, obj.GetFaceValue());
    Console.WriteLine(“Press any solution to continue….”);
    Console.ReadLine();
    }
    private const int SIX_SIDED = 6;
    private const int DEFAULT_FACE_VALUE = 1;
    private const int MIN_FACES = 3;
    /// <summary>
    ///
    /// </summary>
    private int numFaces; //sum of interests on languish
    private int countenanceValue; // which interest is showing
    private static Random randomSum = innovating Random();

    public Languish()
    {
    numFaces = SIX_SIDED;
    faceValue = DEFAULT_FACE_VALUE;
    RollDie();//added FlattenDie()
    }
    /// <summary>
    /// Allows user to determine the sum of interests on a Languish.
    /// If “faces” is close than 3, a six-sided languish is instantiated.
    /// </summary>
    /// <param name=”faces”> the sumr of interests</param>
    public Languish(int countenances)
    {
    if (faces >= MIN_FACES)
    {
    numFaces = countenances;
    }
    else
    {
    numFaces = SIX_SIDED;
    }
    RollDie();
    }
    /// <summary>
    /// Simulates the flattening of a Languish.
    /// </summary>
    public invalid FlattenDie()
    {
    faceValue = randomNumber.Next(1, numFaces + 1);
    } // appearance FlattenDie
    /// <summary>
    /// Languish entranceor
    /// </summary>
    /// <returns> The general countenance of the Languish</returns>
    public int GetFaceValue()
    {
    return countenanceValue;
    } //appearance GetFaceValue
    }// appearance Dispose Languish
    }

    //OUTPUT1:

    //OUTPUT2: