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.

Member Avatar for stbuchok

So instead of trying to read something that is cryptic, can you write it in plain English next time please?

public class Pizza
{
   //shorthand property declaration, no need for additional variables
   //good for simple properties that are meant for getting and setting only
   //not good for properties that have objects
   public string Toppings { get; set; }
   public int Diameter { get; set; }
   public double { get; set; }

   public Pizza(){} 
   //you didn't have a constructor you need that in order to do new Pizza()
}
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.