Question: C# - Printing the return value of a method within a class to the console. Please see the ******* part for what I am trying

C# - Printing the return value of a method within a class to the console.

Please see the ******* part for what I am trying to do. Could you also please explain what I was doing wrong with my main method.

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

namespace DiceRoller { public class Die { static void Main(string[] args) { ***** I want to do Console.WriteLine here that displays the returned value in GetFaceValue() Console.ReadLine(); } private const int SIX_SIDED = 6; private const int DEFAULT_FACE_VALUE = 1; private const int MIN_FACES = 3; ///

/// /// 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; }

///

/// Allows user to specify the number of sides on a Die. /// If "faces" is less than 3, a six-sided die is instantiated. /// /// the numberr of sides public Die(int faces) {

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

RollDie(); }

///

/// Simulates the rolling of a Die. /// public void RollDie() { faceValue = randomNumber.Next(1, numFaces + 1); } // end RollDie

///

/// Die accessor /// /// The current face of the Die public int GetFaceValue() { return faceValue; } //end GetFaceValue

}// end Class Die }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!