No overload for method 'Formula1'takes'1' arguments....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alireza6485
    New Member
    • Jan 2009
    • 19

    No overload for method 'Formula1'takes'1' arguments....

    Hi would you please help me to fix this error...Thank a lot.
    Code:
    using System;
    using System.Threading;
    namespace Car
    {
        class UseMyCar2
        {
            static void Main(string[] args)
            {
            Car myFirstCar = new Car("Toyota");
            Formula1 mySecondCar = new Formula1("Formula1");   //this is where i get the error
                
    
                Car myThirdCar = new Car();
                string theWinner = "";
                Console.WriteLine();
                Console.WriteLine("\t\t\t\t" + "CAR RACING");
                Console.WriteLine("\t\t\t\t" + "----------");
                Console.WriteLine();
                Console.WriteLine();
                int i = 1;
                while (i < 10)
                {
                    Random number = new Random();
                    int mov = number.Next(100);
                    if (mov - 25 > 0)
                    {
                        myFirstCar.accelerate();
                        Console.Write(+mov + " >>> " + myFirstCar.NameCar + " Acc : "
                        + myFirstCar.Speed);
                    }
                    else
                    {
                        myFirstCar.decelerate();
                        Console.Write(+mov + " <<< " + myFirstCar.NameCar + " Dec : "
                        + myFirstCar.Speed);
                    }
                    if (75 - mov > 0)
                    {
                        mySecondCar.accelerate();
                        Console.Write("\t\t " + mov + " >>> " + mySecondCar.NameCar + " Acc : " + mySecondCar.Speed);
                    }
                    else
                    {
                        mySecondCar.decelerate();
                        Console.Write("\t\t " + mov + " <<< " + mySecondCar.NameCar + " Dec : " + (mySecondCar.Speed));
                    }
                    Console.WriteLine("\t\t " + myThirdCar.NameCar + " Sp : " +
                    myThirdCar.Speed);
                    Thread.Sleep(2000);
                    i++;
                }
                Console.WriteLine();
                Console.WriteLine();
                if (myFirstCar.Speed > 499)
                {
                    Console.WriteLine("Catastrophe = The toyota car is crashed");
                }
    
                if (mySecondCar.Speed > 499)
                {
                    Console.WriteLine("Catastrophe = The Formula1 car is crashed");
                }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace Car
    {
        class Formula1 : Car
        {
    
            public new int Increase
            {
                get
                {
                    return increase;
                }
                set
                {
                    increase = value;
                }
            }
        }
    }
    using System;
    namespace Car
    {
    public class Car
    {
    private string nameCar;
    private int speed;
    public int increase;
    private int decrease;
    public Car(string myNameCar)
    {
                                                                         
        // implicit call to object constructor occurs here                                                       
        nameCar=myNameCar;
        speed=0;                                               
        increase=10;                                    
        decrease=10;      
    
        }
    public Car(int initialSpeed, int inc, int dec, string myNameCar)
    {
    speed=initialSpeed;                                               
    increase=inc;                                    
    decrease=dec;
    nameCar=myNameCar;
    }
    
    public Car()
    {
    nameCar="Toy Car";
    }
    public string NameCar
    {
     get
    {
        return nameCar;
    }
        set
    {
        nameCar=value;
    }
    }
    public int Speed
    {
        get
    {
        return speed;
    }
        set
    {
        speed=value;
    }
    }
    
    public int Increase
    {
    get
    {
        return increase;
    }
        set
    {
        increase=value;
    }
    }
    public int Decrease
    {
        get
        {
            return decrease;
        }
        set
        {
            decrease = value;
        }
    }
    public int accelerate()
    {
        Speed = Speed + Increase;
        return Speed;
    }
    public int decelerate()
    {
        Speed = Speed - Decrease; //captal letter cause we do not use them directly
        return Speed;
    }
    }
    }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The error message says it all

    No overload for method 'Formula1'takes '1' arguments....
    The method 'Forumula1'...
    Code:
        class Formula1 : Car
        {
            public new int Increase
            {
                get
                {
                    return increase;
                }
                set
                {
                    increase = value;
                }
            }
        }
    ...has no overload that takes '1' argument:
    The class car has no constructor method that takes the one argument you are trying to pass it. In fact, it has no constructor at all, so it has an implied constructor of zero arguments.

    Code:
    Formula1 mySecondCar = new Formula1("Formula1");   //this is where i get the error
    In creating a new Car you are passing one argument: "Formula1"

    Comment

    • alireza6485
      New Member
      • Jan 2009
      • 19

      #3
      Thanks

      Thanks for your answer:) I fixed it :) :) :)

      Comment

      Working...