0

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.

4
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by samueal
0

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

0

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

0

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

0

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

This article 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.