Prime b

Prime b

  • NA
  • 810
  • 344k

Classes and objects

Jan 20 2012 11:42 PM
Create a class named Pizza. Data fi elds 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
fi elds. Create a class named TestPizza that instantiates one
Pizza object and demonstrates the use of the Pizza set and
get accessors.


Even though my classes are named differently cause I just used same project for this problem
I am not really sure which part to post because this is new to me, but I will just post both classes.
Is this correct? Did I solve the problem? I didn't make TestPizza class, cause I used main class.


Main Class:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee pizza = new Employee();
            pizza.DiameterInInches = 12;
            pizza.Toppings = "Cheese";
            pizza.Price = 5;

            Console.WriteLine("The pizza will have toppings {0} , pizza's diamter {1}, and price is {2}", pizza.Toppings, pizza.DiameterInInches, pizza.Price);
        }

Employee class AKA PIZZA CLASS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Employee
    {

        string toppings;
        int diameterInInches;
        double price;

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

        }
        public int DiameterInInches
        {
            get
            {
                return diameterInInches;
            }
            set
            {
                diameterInInches = value;
            }

        }
        public double Price
        {
            get
            {
                return price;
            }
            set
            {
                price = value;
            }
        }
  
    }
   
}


Answers (4)