Question
Examine the following code. Is there any problem according to design by contract? If yes, please list the problem(s). using System; using System.Collections.Generic; using System.Linq;
Examine the following code. Is there any problem according to design by contract? If yes, please list the problem(s).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignByContractDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please input numerator:");
int numerator = int.Parse(Console.ReadLine());
Console.WriteLine("Please input denominator:");
int denominator = int.Parse(Console.ReadLine());
Division d = new Division(numerator, denominator);
if (denominator == 0)
Console.WriteLine("Result = {0} ", double.PositiveInfinity);
else
Console.WriteLine("Result = {0} ", d.Divid());
Console.ReadKey();
}
}
class Division
{
double numerator;
double denominator;
public Division(double _numerator, double _denominator)
{
numerator = _numerator;
denominator = _denominator;
}
public double Divid()
{
if (denominator != 0)
return numerator / denominator;
else
return double.PositiveInfinity;
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started