I am making a character generator for school. What I have to do is make my CalcPoints method abstract. Unfortunately I keep getting These three error for each of my derived character classes and I don't know what to do.

C:\Users\Hector Rosario\Documents\Visual Studio 2008\Projects\Rosario_Week3\ConsoleApplication2\Program.cs(126,26): error CS0115: 'UltimateWarrior.CalcPoints()': no suitable method found to override

C:\Users\Hector Rosario\Documents\Visual Studio 2008\Projects\Rosario_Week3\ConsoleApplication2\Program.cs(137,26): error CS0115: 'KarateWizard.CalcPoints()': no suitable method found to override

C:\Users\Hector Rosario\Documents\Visual Studio 2008\Projects\Rosario_Week3\ConsoleApplication2\Program.cs(152,26): error CS0115: 'Dragoon.CalcPoints()': no suitable method found to override

I've working on this for two days and I think I am close but I can't figure out what I am doing wrong. Any help or advice would be awesome, Thanx

 public class CharClass
    {
      public CharClass()
      {
          Console.WriteLine("Calculating Life points");
          Calculate();
      }
       public static void Main(string[] args)
        {


            string Name;
            string choose;
            string Sex;
            string race;
             string species;




             Dragoon Mydragoon = new Dragoon();
             Console.ReadLine();
             KarateWizard Mykaratewizard = new KarateWizard();
             Console.ReadLine();
             UltimateWarrior Myultimatewarrior = new UltimateWarrior();
           Console.ReadLine();
            Console.Write("Please enter your name: ");
            Name = Console.ReadLine();//set character's name
            Console.WriteLine("Your character's age is {0}", age);
            Console.WriteLine("You have three races that you can choose for your\n character. Please type in human, elf or dwarf.");
            race = System.Console.ReadLine();
            switch (race)//choose character's race
            {
                case "human":
                    species = "Your character is human.\n";
                    break;
                case "elf":
                    species = "Your character is an elf.\n";
                    break;
                case "dwarf":
                    species = "Your character is a dwarf.\n";
                    break;
                default:
                    species = "Please pick human, dwarf or elf";
                    break;

            }
            System.Console.Write("Ok, " + species);



            Console.WriteLine("Do you want your character to be male or female?\n Press m or f to make your choice.");
            choose = System.Console.ReadLine();

            switch (choose)//choose character's sex
            {
                case "m":
                    Sex = "Your character is male\n";
                    break;
                case "f":
                    Sex = "Your character is female\n";
                    break;

                default:
                    Sex = "I'm sorry but uh... last I checked there were only two sexes, \nmale and female.\n";
                    break;
            }//end switch statement

            System.Console.Write("Ok, " + Sex);

            Console.WriteLine("\nLet's see how charismatic " + Name + " is. \n");

            bool charisma = true;

            // WriteLine automatically converts the value of charisma to text.
            Console.WriteLine(charisma);

            int fate = DateTime.Now.DayOfYear;//Charisma will be set according to the day of the week


            // Assign the result of a boolean expression to charisma.
            charisma = (fate % 2 == 0);

            if (true == charisma)
            {
                Console.WriteLine(Name + " has great charisma and will be very popular!");
            }
            else
            {
                Console.WriteLine(Name + " has poor charisma.");
            }


            MessageBox.Show("Name: " + Name + "\nRace: " + species + "\nAge: " + age + "\nGender: " + Sex + "\nCharisma: " + charisma + "\nLife: " + life);
            Console.WriteLine("\nPress [ENTER] to Exit");
            Console.ReadLine();


        }


       virtual public void CalcPoints(int intMin, int intMax)
       {
           //Create a new instance of the class Random
           Random randomNumber = new Random();
           //Generate a random number using intMin as the minimum and intMax as the maximum
           return randomNumber.Next(intMin, intMax);
       }         



    }
}

public class UltimateWarrior
{

    int strength;
    public override void CalcPoints()
    {
        int life = Calcpoints(10, 100);//calculating life points
        Console.WriteLine(Name + " has {0} life points.", life);
        int age = Calcpoints(10, 40);//calculates charactersm age.
    }
}

public class KarateWizard  
{ 
    int magic;
    public override void CalcPoints()
    { 
        int life = Calcpoints(10, 100);//calculating life points
        Console.WriteLine(Name + " has {0} life points.", life);
        int age = Calcpoints(10, 40);//calculates charactersm age.
    }
}

public class Dragoon  
{ 
    int dexterity;
    public Dragoon()
    {
        Console.WriteLine("Call derived ctor.");
    }
    public override void CalcPoints()
    {

        int age = Calcpoints(10, 40);//calculates charactersm age.
        int life = Calcpoints(10, 100);//calculating life points
        Console.WriteLine(Name + " has {0} life points.", life);

    }
} 



public class CharTest
{

    private string race;
public CharTest(string Test)
    {
        Race = Test;// constructor
    }

    public string Race
    {
        get
        {
            return race;
        }
        set
        {
            race = value;
        }
    }

    public void DisplayMessage()
    {
        Console.WriteLine("Your Race\n{0}!",
            Race);
    }
}

Recommended Answers

All 5 Replies

Those three classes are not child classes so you do not need to override.

Looking at the code below, you are returning something?

virtual public void CalcPoints(int intMin, int intMax)
{
//Create a new instance of the class Random
Random randomNumber = new Random();
//Generate a random number using intMin as the minimum and intMax as the maximum
return randomNumber.Next(intMin, intMax);
}

function calcpoints that u have made virtual is having two parameters in its para.. list however to override that func u need to give same signature as that of ur virtual function that is with 2 para.. the overriding fn that u have made has no arguments so the compiler searches for a fn in the base class of calcpoint fn with no argiments to override.

Shouldnt you really have a class basis for your warrior, wizard etc so you dont have to redo half the same code? (that way you would have stuff you could override)

CalcPoints is a routine under your app not under a class, so you wont be able to override it

PS please use code tags next time it makes it easier to read

That is what I am trying to do. My assignment is to make the Calcpoints method abstract and I want to know how I can access it from my child class Ultimate Warrior, Dragoon and KarateWizard. By the I have have redone my code and put them in their own cs files as a class with : Charclass denote that as a base class. But yeah, Calcpoints is the of my problem right not now.

Well calcpoints would need to be in the base class, then it should be accessible

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.