public override void UnexpectedResult() { // Note the different data types! Man jakeRef = new Jake(); Woman maryRef = new Mary(); maryRef.Accept(jakeRef); /* The previous code will print: * * > Jake loves Mary. * * As expected! */ }
public override void UnexpectedResult() { // Note the different data types! Man jakeRef = new Jake(); Woman maryRef = new Mary(); jakeRef.Loves(maryRef); /* The previous code will print: * * > Jake loves every woman! * * instead of * * > Jake loves Mary. * * Runtime chooses method dynamically based on jakeRef ONLY! */ }
public IActionResult Stats(Jake j) { int gameTotal = 0; double damageTotal = 0; double killTotal = 0; double revivesTotal = 0; double revivedTotal = 0; double respawnsTotal = 0; double gameScoreTotal = 0; double damageAvg = 0; double killAvg = 0; double revivesAvg = 0; double respawnsAvg = 0; double revivedAvg = 0; double gameScoreAvg = 0; List <Jake> averages = _context.Jake.ToList(); foreach (var item in averages) { gameTotal++; damageTotal = damageTotal + item.Damage; killTotal = killTotal + item.Kills; revivesTotal = revivesTotal + item.Revives; revivedTotal = revivedTotal = item.Revived; respawnsTotal = respawnsTotal + item.Respawns; gameScoreTotal = gameScoreTotal + item.GameScore; damageAvg = damageTotal / gameTotal; killAvg = killTotal / gameTotal; revivesAvg = revivesTotal / gameTotal; revivedAvg = revivedTotal / gameTotal; gameScoreAvg = gameScoreTotal / gameTotal; Console.WriteLine(damageTotal); } return(View(j)); }
public IActionResult Index(Jake j, string calculate, string save) { if (calculate == "calc") { j.GameScore = j.Damage + (j.Kills * 75) + (j.Revives * 50) + (j.Respawns * 150) - (j.Revived * 50); return(View(j)); } else if (save == "save") { _context.Jake.Add(j); _context.SaveChanges(); return(RedirectToAction("Index")); } else { return(View()); } }
public override void ExpectedResult() { Man theMan = new Man(); Jake jake = new Jake(); Woman theWoman = new Woman(); Mary mary = new Mary(); theMan.Loves(theWoman); theMan.Loves(mary); jake.Loves(theWoman); jake.Loves(mary); /* The previous code will print: * * > Every man loves every woman! * > Every man loves Mary. * > Jake loves every woman! * > Jake loves Mary. * * As expected! */ }