예제 #1
0
파일: Program.cs 프로젝트: CMaC253/PCE_06
 public void PrintMyTV(Television theTV)
 {
     if (theTV == null)
     {
         Console.WriteLine("Nothing...");
     }
     if (theTV != null)
     {
         theTV.Print();
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: CMaC253/PCE_06
        public void RunExercise()
        {
            TelevisionHandler tvh = new TelevisionHandler();

            Television tv = new Television("Sony", 2000.0m, 50);

            Console.WriteLine("Printing using the Print method: ");
            tvh.PrintMyTV(tv);

            Console.WriteLine("Printing using getters: ");
            tvh.PrintMyTVUsingGetters(tv);
        }
예제 #3
0
        public void RunExercise()
        {
            Television ax = new Television("Sony", 1000.17m, 10.5);

            //ax.SetBrand("Sony");
            //string brand = ax.GetBrand();
            //ax.SetPrice(1000.17m);
            //decimal price = ax.GetPrice();
            //ax.SetSize(10.5);
            //double size = ax.GetSize();

            ax.Print();
        }
예제 #4
0
        public void PrintArrayOfTVs()
        {
            int pr = 10;

            Television[] ts = new Television[5];
            ts[0] = new Television("Toshiba", pr, 45.5);
            ts[1] = new Television("Samsung", pr, 10.5);
            ts[2] = new Television("Sony", pr, 23.5);
            ts[3] = new Television("LG", pr, 27.5);
            ts[4] = new Television("WestingHouse", pr, 80.5);

            for (int i = 0; i < ts.Length; i++)
            {
                ts[i].Print("Brand X", pr++, 42.0);
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: CMaC253/PCE_06
        public Television CreateATVFromUserInput()
        {
            decimal d;
            double  n;

            Console.WriteLine("Enter Brand: ");
            string s = Console.ReadLine();

            Console.WriteLine("Enter Price: ");
            Decimal.TryParse(Console.ReadLine(), out d);
            Console.WriteLine("Enter Size: ");
            Double.TryParse(Console.ReadLine(), out n);
            Television userTV = new Television();

            userTV.Print(s, d, n);
            return(userTV);
        }
예제 #6
0
파일: Program.cs 프로젝트: CMaC253/PCE_06
        public void RunExercise()
        {
            TelevisionHandler tvh      = new TelevisionHandler();
            Television        firstTV  = new Television("Samsung", 2.0m, 10.5);
            Television        secondTV = new Television("Westinghouse", 10.5m, 42);
            //firstTV = tvh.CreateATV();
            //secondTV = tvh.CreateATVFromUserInput();

            Television moreExpensiveTV;

            moreExpensiveTV = tvh.PickMoreExpensiveTV(firstTV, secondTV);

            firstTV.Print();
            secondTV.Print();

            Console.WriteLine("The more expensive TV is: ");
            tvh.PrintMyTV(moreExpensiveTV);
        }
예제 #7
0
        public void PrintArrayOfPossiblyNullTVs()
        {
            Television[] tx = new Television[10];
            for (int i = 0; i < tx.Length; i++)
            {
                Console.WriteLine("Slot {0} is null.", i);
                //we get null when using a simple Television class
            }

            int totalArray = 10;

            tx[0] = new Television("Brand X", totalArray, 42.0);
            tx[1] = new Television("Brand X", totalArray, 42.0);
            tx[4] = new Television("Brand X", totalArray, 42.0);
            tx[8] = new Television("Brand X", totalArray, 42.0);

            for (int i = 0; i < tx.Length; i++)
            {
                if (tx[i] == null)
                {
                    Console.WriteLine("Slot {0} is null.", i);
                }
                if (tx[i] != null)
                {
                    tx[i].Print("Brand X", i + totalArray, 42.0);
                }
                // when we get a null value we print out which values are null
                // but print the defined televisions
            }
            for (int i = 0; i < tx.Length; i++)
            {
                if (tx[i] == null)
                {
                    tx[i] = new Television("Brand X", 10 + i, 42.0);
                }
                if (tx[i] != null)
                {
                    tx[i].Print("Brand X", 10 + i, 42.0);
                }
                //once we find a null value in the array
                //we create a new television and give it some values
                //then we print.
            }
        }
예제 #8
0
파일: Program.cs 프로젝트: CMaC253/PCE_06
 public void PrintMyTVUsingGetters(Television theTV)
 {
     if (theTV == null)
     {
         Console.WriteLine("Nothing...");
     }
     else
     {
         theTV.SetBrand("Sony");
         string brand = theTV.GetBrand();
         theTV.SetPrice(1000.17m);
         decimal price = theTV.GetPrice();
         theTV.SetSize(10.5);
         double size = theTV.GetSize();
         Console.WriteLine("The TV's Brand is: {0}, which is rad.", brand);
         Console.WriteLine("The TV's Price is: {0}, which is really rad.", price);
         Console.WriteLine("The TV's Size is: {0}, which is wicked rad.", size);
     }
 }
예제 #9
0
            public void RunExercise()
            {
                TVStorage tvs = new TVStorage();

                tvs.PrintAllTVs();

                Television t = new Television("Brand X", 1000, 42);

                tvs.StoreTV(2, t);
                tvs.StoreTV(4, new Television("Brand Y", 2000, 52));

                Television t2 = tvs.GetTV(0);

                Console.WriteLine("Is t2 null? (It should be) {0}", t2 == null);

                tvs.PrintAllTVs();

                t2 = tvs.GetTV(2);
                Console.WriteLine("Is t2 the same as t? (It should be) {0}", t2 == t);
            }
예제 #10
0
 // TODO: Implement this method!
 // If the location is invalid (negative, or too large) do nothing.
 // If the parameter is null (and the location is ok), then replace
 //      the object reference in the array with null
 public void StoreTV(int iLocation, Television tvToStore)
 {
 }