Creating and testing a Fraction class The exercise is as follows:


  Create a class called Fraction that can be used to represent the ratio of two integers.
  Include appropriate constructors, properties, and methods. If the denominator becomes
  zero, throw and handle an exception. Create an application class to test the Fraction class.


The program runs.  Will someone look over my code for this exercise?

Fraction.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Part2
{
    public class Fraction
    {
        private int numerator;
        private int denominator;

        /// &lt;summary&gt;
        /// Initialize the fraction properties
        /// &lt;/summary&gt;
        /// &lt;param name="numerator"&gt;Upper number&lt;/param&gt;
        /// &lt;param name="denominator"&gt;Lower number&lt;/param&gt;
        public Fraction(int numerator, int denominator)
        {
            this.Numerator = numerator;
            this.Denominator = denominator;
        }

        /// &lt;summary&gt;
        /// Access tot he numerator property
        /// &lt;/summary&gt;
        public int Numerator
        {
            get { return this.numerator; }
            set { this.numerator = value; }
        }

        /// &lt;summary&gt;
        /// Access to the denominator property
        /// &lt;/summary&gt;
        public int Denominator
        {
            get { return this.denominator; }
            set
            {
                if (value == 0)
                {
                    throw new Exception("0 denominator");
                }

                this.denominator = value;
            }
        }

        /// &lt;summary&gt;
        /// Return a string representation of a fraction
        /// &lt;/summary&gt;
        /// &lt;returns&gt;Displayable attribute&lt;/returns&gt;
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(this.Numerator + "/" + this.numerator);
            sb.Append(" or ");
            sb.Append(this.Numerator / this.Denominator);

            return sb.ToString();
        }
    }
}


Application.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Part2
{
    public class Application
    {
        /// &lt;summary&gt;
        /// Entry point of the program
        /// &lt;/summary&gt;
        public static void Main(string[] args)
        {
            // Create a fraction
            Fraction f1 = new Fraction(1, 2);
            Console.WriteLine(f1);

            try
            {
                // Create another fraction
                Fraction f2 = new Fraction(2, 0);
                Console.WriteLine(f2);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
    }
}
I think your class is pretty much useless. If you have a class that represents a fraction, you should be able to do operations with it that you can do with a fraction, like addition, subtraction, multiplication and division (possibly using operator overloading). Another possible operation is fraction simplification.

Also, you shouldn't throw Exception, you should instead a custom type that inherits from Exception (called something like ZeroDenominatorException) and throw that.

And your Main() isn't very realistic. In real code, you wouldn't write code that you know will always throw an exception. So I think that your try should be around both of your new Fraction() statements.

Also, if you're going to have all the operations I have mentioned above, a better application to show that would be a very simple fraction calculator.

Something like:

Enter numerator:
1
Enter denominator:
4
Enter operation:
+
Enter numerator:
3
Enter denominator:
4
Result: 4/4
Simplifies result: 1/1