الأحد، 3 أبريل 2011

quize 4 suggested solution



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

namespace quize4
{
    class MobilePhone
    {
        int cost;
        int serial;
        protected string color;
        public MobilePhone()
        {
        Console.WriteLine("default values is cost =0, serial=0 and color=non");
            cost = 0;
            serial = 0;
            color = "non";
        }
        public MobilePhone(int c, int s, string co)
        {
            cost = c;
            serial = s;
            color = co;
             Console.WriteLine("general mobile object created");
             Console.WriteLine("{0},{1},{2}",cost,serial,color);

        }
        public int Cost
        {
        set {cost=value;}
        get{return cost;}
         }

       public int Serial{
        set { serial = value; }
        get { return serial; }
   
    }


        public void ComputePrice(double tax)
        {
            Console.WriteLine("total price in piaster is :");
            Console.WriteLine(tax + cost);
           
        }

    }

    class NokiPhone:MobilePhone
    {
        string model;
      
        public NokiPhone(  int c, int s,string co, string m):base(c,s,co)
        {
            model = m;
           Console.WriteLine(model);
        }



        public new void ComputePrice(double tax)
        {
            Console.WriteLine("total price in JD is :");
         
            Console.WriteLine(tax + Cost/100);
          

        }
   
    }

    class  SonyPhone: MobilePhone
    {

        public SonyPhone()
        {
            color = "blue";
            Console.WriteLine("\nthe sony color is {0} \n",color);
         }
   
    }

    class Program
    {
        static void Main(string[] args)
        {
            MobilePhone m = new MobilePhone(20,11,"red");
            m.ComputePrice(0.4);

            NokiPhone n = new NokiPhone(20, 22, "yellow","6300");
           
            n.ComputePrice(0.4);

       
         
            SonyPhone s = new SonyPhone();



        }
    }
}

ليست هناك تعليقات:

إرسال تعليق