public void PrintMyTV(Television theTV) { if (theTV == null) { Console.WriteLine("Nothing..."); } if (theTV != null) { theTV.Print(); } }
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); }
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(); }
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); } }
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); }
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); }
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. } }
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); } }
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); }
// 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) { }