public Icalculations GetIcalculations(int number) { Icalculations obj = null; if (number == 1) { //the implementation of the super class is done in the child class //superclass object= new subclass obj = new Add(); } else if (number == 2) { //the implementation of the super class is done in the child class //superclass object= new subclass obj = new Sub(); } else if (number == 3) { //the implementation of the super class is done in the child class //superclass object= new subclass obj = new multiply(); } else if (number == 4) { //the implementation of the super class is done in the child class //superclass object= new subclass obj = new Harder(); } return(obj); }
public void Initialize() { var container = ContainerConfig.Configure(); using (var scope = container.BeginLifetimeScope()) { cal = scope.Resolve <Icalculations>(); } }
/// <summary> /// this the constructor of this object, it will create instance of the other classes /// whenever needed (_disp is the display class whenever we need to write anything in the console /// _calc for calculation whenever we need to make caluclation (consumable duration or number of stops) /// and _dataapi for bringing data from api) /// </summary> /// <param name="calc">it is the class calculation which is related to calculation</param> /// <param name="disp">the class specialized in displaying info</param> /// <param name="dataapi">class related to manipulating data from api</param> public businesslogic(Icalculations calc, Idisplay disp, Idatafromapi dataapi) { _calc = calc; _disp = disp; _dataapi = dataapi; }
static void Main(string[] args) { Console.Clear(); int wrong = 3; int score = 0; Console.WriteLine("what is your Username?"); string Username = Console.ReadLine(); Console.WriteLine("what is your Password?"); string Password = Console.ReadLine(); Console.Clear(); while (wrong > 0) { Random random = new Random(); int whaa = 1; int value1 = random.Next(1, 10); int value2 = random.Next(1, 10); if (score >= 3) { whaa = 3; value1 = random.Next(2, 10); value2 = random.Next(2, 10); } if (score >= 6) { whaa = 2; value1 = random.Next(1, 20); value2 = random.Next(1, 20); } if (score >= 9) { whaa = 4; value1 = random.Next(3, 10); value2 = random.Next(3, 10); } FactoryClass factoryMethod = new FactoryClass(); Icalculations obj = factoryMethod.GetIcalculations(whaa); if (value1 < value2) { int temp = value2; value2 = value1; value1 = temp; } obj.calculate(value1, value2); Console.WriteLine($"{wrong} tries to go"); Console.WriteLine($"your current score is {score}"); Console.WriteLine("Enter Answer"); int num; int.TryParse(Console.ReadLine(), out num); if (num == value2 + value1 && whaa == 1 || num == value1 - value2 && whaa == 2 || num == value2 * value1 && whaa == 3 || num == value1 + (value1 * value2) - value1 && whaa == 4) { Console.Clear(); score++; } else { Console.Clear(); wrong--; if (wrong == 0) { Console.WriteLine($"Hello {Username}, Your final score was {score}, try again next time"); } } } }