Create a class named Pizza. Data fields include a string for toppings (such as pepperoni), an integer for diameter in inches (such as 12), and a double for price (such as 13.99). Include properties to get and set values for each of these fields. Create a class named TestPizza that instantiates one Pizza object and demonstrates the use of the Pizza set and get accessors

class Pizza
    {
         string toppings;
            int diameter;
            double price;
        }

      public string Toppings
      {
          get
          {
              return this.toppings;
          }
          set
          {
              this.toppings = value;
          }
      }

public int Diameter 
{ 
get
{
return this.diameter;
}
set
{
this.diameter = value;
}
}
public double Price 
{ 
get 
{
return this.price;
}
set 
{
this.price = value;
}
}
      public class TestPizza
          {
          public static void main(String[] args)
          {
  
              Pizza p = new Pizza();
              p.Toppings = "pepperoni, cheese, mushrooms";
              p.Diameter = 12;
              p.Price = 13.99;
              Console.WriteLine("Topping: " + p.getTopping());
              Console.WriteLine("Diameter: " + p.getDiameter());
              Console.WriteLine("Price: " + p.getPrice()); 
}

}

Expected class, delegate, enum, interface, or struct is the error that i am getting with: public string toppings,public int Diameter and public double Price.

Check your opening { and closing } throughout your file. The sample you provided closes the class very early in your code...

Darkagn is right - line 6 certainly looks wrong

check the brackets, all are in place. Rebuild the program and it is now giving the following errors:
1. The variable 'toppings' ,'diameter', and 'price'is declared but never used.
2. Program does not contain a definition for 'toppings', 'diameter' and 'price'.
3. The type or namespace name 'Pizza' could not be found

if i remove the bracket from line 6, the error said } expected.

Remove the bracket from 6th line and place it before public class TestPizza starts.

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.