private static void Cook(Potato potato) { bool canBeCooked = potato.IsPeeled && !potato.IsRotten; if (!canBeCooked) { // throw trash potato exception } // continiue cooking }
public void Cook(Potato potato) { if (this.CheckPotato(potato)) { // some potato cooking logic goes here potato.IsCooked = true; } else { throw new ArgumentException("No potato to cook. Order yourself a pizza!"); } }
private bool CheckPotato(Potato potato) { if (potato != null) { if (potato.IsPeeled && !potato.IsRotten) { return(true); } return(false); } return(false); }
public static void RefactorPotatoStatements() { Potato potato = new Potato(); if (potato != null) { bool notPeeled = !potato.IsPeeled; bool notRotten = !potato.IsRotten; if (notPeeled && notRotten) { potato.Cook(); } } }
public static void Main() { /* * Potato potato; * //... * if (potato != null) * if(!potato.HasNotBeenPeeled && !potato.IsRotten) * Cook(potato); */ Potato potato = new Potato(); // .... if (potato != null) { bool notPeeled = !potato.IsPeeled; bool notRotten = !potato.IsRotten; if (notPeeled && notRotten) { potato.Cook(); } } /* * if (x >= MIN_X && (x =< MAX_X && ((MAX_Y >= y && * MIN_Y <= y) && !shouldNotVisitCell))) * { * VisitCell(); * } */ const int MinX = 5; const int MaxX = 15; const int MinY = 5; const int MaxY = 15; int x = 7; int y = 8; bool shouldVisitCell = true; if (shouldVisitCell && IsInRange(x, MinX, MaxX) && IsInRange(y, MinY, MaxY)) { VisitCell(); } }
public static void Main() { var potato = new Potato(15); if (potato.IsPeeled == false) { throw new Exception("The potato is not peeled!"); } if (potato.IsRotten == true) { throw new Exception("The potato is rotten!"); } if (potato != null && potato.IsPeeled && !potato.IsRotten) { potato.Cook(); } }
public static void Main() { // First if-statement to refactor: // Potato potato; ////... // if (potato != null) // if (!potato.HasNotBeenPeeled && !potato.IsRotten) // Cook(potato); Potato potato = new Potato(); if (potato == null) { throw new NullReferenceException("Potato is null. Cannot cook null."); } else { if (potato.IsPeeled && !potato.IsRotten) { Cook(potato); } else { Console.WriteLine("Cannot cook potato - not peeled or rotten"); } } // Second if-statement to refactor: // if (x >= MIN_X && (x =< MAX_X && ((MAX_Y >= y && MIN_Y <= y) && !shouldNotVisitCell))) // { // VisitCell(); // } int x = 1; int y = 2; bool shouldVisitCell = true; bool isValueInRange = IsInRange(x, MinX, MaxX) && IsInRange(y, MinY, MaxY); if (isValueInRange && shouldVisitCell) { VisitCell(); } }
/// <summary> /// Main method /// </summary> public static void Main() { // Task1 Potato potato = new Potato(); // ... if (potato == null) { throw new ArgumentNullException("Potato cannot be null"); } else { if (potato.IsPeeled && !potato.IsRotten) { Cook(potato); } } // Task2 const int MinX = 0; const int MaxX = 100; const int MinY = 0; const int MaxY = 100; bool isVisitedCell = false; int x = 0; int y = 0; bool isXInRange = x >= MinX && x <= MaxX; bool isYInRange = MinY >= y && y <= MaxY; if (isXInRange && isYInRange && isVisitedCell) { VisitCell(); } }
/// <summary> /// The entry point of the application. /// </summary> public static void Main() { Chef cook = new Chef(); Vegetable potato = new Potato(true, false, false); if (potato != null && potato.IsFresh) { if (!potato.IsPeeled) { cook.Peel(potato); } cook.Cut(potato); cook.PutInBowl(potato); } foreach (Vegetable vegetable in cook.VegitablesInBowl) { Console.WriteLine(vegetable.ToString()); Console.WriteLine("--------------------------------------------------"); } }
/// <summary> /// Method for cooking. /// </summary> /// <param name="potato">Potato for cooking</param> private static void Cook(Potato potato) { throw new NotImplementedException(); }
public static void Cook(Potato potato) { }
public static void Main() { // Part 1 /* Potato potato; //... if (potato != null) if (!potato.HasNotBeenPeeled && !potato.IsRotten) Cook(potato); */ Potato potato = new Potato(); // ... potato.HasBeenPeeled = true; potato.IsNotRotten = true; if (potato != null) { if (potato.HasBeenPeeled && !potato.IsNotRotten) { Cook(potato); } } // Part 2 /* if (x >= MIN_X && (x =< MAX_X && ((MAX_Y >= y && MIN_Y <= y) && !shouldNotVisitCell))) { VisitCell(); } */ int[,] matrixOfNumbers = new int[,] { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} }; Random randomX = new Random(); Random randomY = new Random(); for (int row = 0; row < matrixOfNumbers.GetLength(0); row++) { for (int col = 0; col < matrixOfNumbers.GetLength(1); col++) { int currentX = randomX.Next(0, 14); int currentY = randomY.Next(0, 14); bool isCorrectX = currentX >= 0 && currentX <= matrixOfNumbers.GetLength(0); bool isCorrectY = currentY >= 0 && currentY <= matrixOfNumbers.GetLength(1); bool shouldVisitCell = true; if (currentX == currentY) { shouldVisitCell = false; } if (isCorrectX && isCorrectY && shouldVisitCell) { VisitCell(); } } } }
private static void Cook(Potato potato) { Console.WriteLine("Cooking tators..."); }