0

Hello everyone! i tried to run this code on the command prompt and got this error: "Invalid token '(' in class, struct or interface member declaration". Please how do i solve this? what does it mean? Thanks.

using System;
namespace FFC {
        public abstract class Furniture{

         protected string color;
         protected int width;
         protected int height;
                 public abstract void Accept();
                 public abstract void Display();
        }
        class Bookshelf : Furniture{
              private int numOf_shelves;
              public override void Accept(){
              }
                     string str2, str3, str4;
                     Console.WriteLine("ENTER VALUES FOR BOOKSHELF");
                     Console.WriteLine("Enter Color");

                    color = Console.ReadLine();
                    Console.WriteLine("Enter width");
                    str2 = Console.ReadLine();
                    width = Convert.ToInt32(str2);
                    Console.WriteLine("Enter height");
                    str3 = Console.ReadLine();
                    height = Convert.ToInt32(str3);
                    Console.WriteLine("Enter No. of shelves");
                    str4 = Console.ReadLine();
                    numOf_shelves = Convert.ToInt32(str4);

        }
        public override void Display(){
                    Console.WriteLine("DISPLAYING VALUES FOR BOOKSHELF");
                    Console.WriteLine("Color is {0}", color);
                    Console.WriteLine("Width is {0}", width);
                    Console.WriteLine("Height is {0}", height);
                    Console.WriteLine("Number of shelves is {0}", numOf_shelves);
        }

}
class Chair : Furniture{
      private int numOf_legs;
      public override void Accept(){
            string str2, str3, str4;
            Console.WriteLine("ENTER VALUES FOR CHAIR");
            Console.WriteLine("Enter Color");
            color = Console.ReadLine();
            Console.WriteLine("Enter width");
            str2 = Console.ReadLine();
            width = Convert.ToInt32(str2);
            Console.WriteLine("Enter height");
            str3 = Console.ReadLine();
            height = Convert.ToInt32(str3);
            Console.WriteLine("Enter No. of legs in a chair");
            str4 = Console.ReadLine();
            numOf_legs = Convert.ToInt32(str4);
      }
      public override void Display(){
             Console.WriteLine("DISPLAYING VALUES FOR CHAIR");
             Console.WriteLine("Color is {0}", color);
             Console.WriteLine("Width is {0}", width);
             Console.WriteLine("Height is {0}", height);
             Console.WriteLine("Number of legs is {0}", numOf_legs);
      }
   }
   class BookshelfChair{
        static int Main (string [] args){
                Bookshelf b1 = new Bookshelf();
                Chair c1 = new Chair();
                b1.Accept();
                b1.Display();
                c1.Accept();
                c1.Display();
                Console.ReadLine();
                return 0;
        }
   }

}




using System;
namespace FFC {
        public abstract class Furniture{

         protected string color;
         protected int width;
         protected int height;
                 public abstract void Accept();
                 public abstract void Display();
        }
        class Bookshelf : Furniture{
              private int numOf_shelves;
              public override void Accept(){
              }
                     string str2, str3, str4;
                     Console.WriteLine("ENTER VALUES FOR BOOKSHELF");
                     Console.WriteLine("Enter Color");

                    color = Console.ReadLine();
                    Console.WriteLine("Enter width");
                    str2 = Console.ReadLine();
                    width = Convert.ToInt32(str2);
                    Console.WriteLine("Enter height");
                    str3 = Console.ReadLine();
                    height = Convert.ToInt32(str3);
                    Console.WriteLine("Enter No. of shelves");
                    str4 = Console.ReadLine();
                    numOf_shelves = Convert.ToInt32(str4);

        }
        public override void Display(){
                    Console.WriteLine("DISPLAYING VALUES FOR BOOKSHELF");
                    Console.WriteLine("Color is {0}", color);
                    Console.WriteLine("Width is {0}", width);
                    Console.WriteLine("Height is {0}", height);
                    Console.WriteLine("Number of shelves is {0}", numOf_shelves);
        }

}
class Chair : Furniture{
      private int numOf_legs;
      public override void Accept(){
            string str2, str3, str4;
            Console.WriteLine("ENTER VALUES FOR CHAIR");
            Console.WriteLine("Enter Color");
            color = Console.ReadLine();
            Console.WriteLine("Enter width");
            str2 = Console.ReadLine();
            width = Convert.ToInt32(str2);
            Console.WriteLine("Enter height");
            str3 = Console.ReadLine();
            height = Convert.ToInt32(str3);
            Console.WriteLine("Enter No. of legs in a chair");
            str4 = Console.ReadLine();
            numOf_legs = Convert.ToInt32(str4);
      }
      public override void Display(){
             Console.WriteLine("DISPLAYING VALUES FOR CHAIR");
             Console.WriteLine("Color is {0}", color);
             Console.WriteLine("Width is {0}", width);
             Console.WriteLine("Height is {0}", height);
             Console.WriteLine("Number of legs is {0}", numOf_legs);
      }
   }
   class BookshelfChair{
        static int Main (string [] args){
                Bookshelf b1 = new Bookshelf();
                Chair c1 = new Chair();
                b1.Accept();
                b1.Display();
                c1.Accept();
                c1.Display();
                Console.ReadLine();
                return 0;
        }
   }

}
2
Contributors
1
Reply
20
Views
3 Years
Discussion Span
Last Post by chriswelborn
0

You closed the Accept function's block of code with }. To the compiler, all of that code is just hanging there in the namespace. Also, I'm not sure if you meant to or not but you've got double declarations of everything. Watch your braces and code blocks. Use proper indention to denote nesting levels. It'll help you spot stuff like this. For instance:

namespace FFC {
    class Furniture {
        void Accept () {
            // code here.
        }

        // not here.
    }

    class BookShelf : Furniture {
        void Accept() {
            // code here.
        }
    }

// This gets confusing, especially if you've been up too long:
class BadNesting : Furniture {
void BadAccept() {
}
}
}

Edited by chriswelborn: example of bad nesting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.