Static Objects

Introduction

A static object is one that is accessed without using a variable of its class. A static value is created with the static keyword.

A Static Field

Yon can declare a static variable in a class. Here is an example:

@functions{
    public class Chemistry
    {
        static string Category;
    }
}

The access modifier (private, public, internal or protected) can be written before or after the static keyword. Here are examples:

@functions{
    public class Chemistry
    {
        public static int Period;
        static public int Group;
    }
}

To access a static variable, you must "qualify" it. Here are examples:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Car.make = "Ford";
    Car.model = "Escort";
}

@functions{
    public class Car
    {
        public static string make;
        static public string model;
    }
}

<pre>Vehicle Registration
---------------------
Make:  @Car.make
Model: @Car.model
======================</pre>

This would produce:

Vehicle Registration
---------------------
Make:  Ford
Model: Escort
======================

In your class, you can create a combination of static and non-static fields. Here is an example:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Car cr    = new();
    Car.make  = "Toyota";
    Car.model = "Camry";
    cr.doors  = 4;
}

@functions{
    public class Car
    {
        public static string make;
        static public string model;
        public int           doors;
    }
}

<pre>Vehicle Registration
---------------------
Make:  @Car.make
Model: @Car.model
Doors: @cr.doors
======================</pre>

This would produce:

Vehicle Registration
---------------------
Make:  Toyota
Model: Camry
Doors: 4
======================

Static Methods

A method of a class can be made static. Here is an example:

@functions{
    public class Chemistry
    {
        static void Display()
        {
        }
    }
}

The access modifier of a static method can be written before or after the static keyword. Here is an example:

@functions{
    public class Chemistry
    {
        public static void Display()
        {
        }
    }
}

If you have a static field in a class, any method in that class can directly access static and non-static members by their names. Here are examples:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Residence res = new Residence();
    
    res.Present();
}

@functions{
    class Residence
    {
        public static int Bedrooms;
        static public double Bathrooms;
        public double MarketValue;
        public string ConstructionStatus;
        
        public void Present()
        {
            Bedrooms = 5;
            Residence.Bathrooms = 3.50;
            ConstructionStatus = "Needs Renovation";
            MarketValue = 545_825;
        }
    }
}

<pre>   ==//== Altair Realtors ==//==
---------------------------------------
Number of Bedrooms:   @Residence.Bedrooms
Number of Bathrooms:  @Residence.Bathrooms
Construction Status:  @res.ConstructionStatus
Market Value:         @res.MarketValue
=======================================</pre>

This would produce:

   ==//== Altair Realtors ==//==
---------------------------------------
Number of Bedrooms:   5
Number of Bathrooms:  3.5
Construction Status:  Needs Renovation
Market Value:         545825
=======================================

Static Properties

A property can be made static. Here is an example:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Square sqr = new Square();

    Square.Side = 248.77;
}

@functions{
    public class Square
    {
        private static double s;

        public static double Side
        {
            get { return s; }
            set { s = value; }
        }

        static public double Perimeter
        {
            get
            {
                return s * 4;
            }
        }

        public double Area { get { return s * s; } }
    }
}

<pre>===========================
Square Values
---------------------------
Area:      @sqr.Area
Perimeter: @Square.Perimeter
===========================</pre>

This would produce:

===========================
Square Values
---------------------------
Area:      61886.5129
Perimeter: 995.08
===========================

A Static Class

A class can be made static. To create a static class, precede the class keyword with the static keyword. Here is an example:

namespace CountriesStatistics.Models
{
    public static class Region
    {
        public static string Name;
        public static string States;
    }
}

To use a static class, type the name of the class, a period, and the desired member. Here are examples:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Person pers = new();
    
    pers.firstName = "Gertrude";
}

@functions{
    public class Person
    {
        public string firstName;

        static Person()
        {
            
        }
    }
}

<pre>===========================
Employee Information
---------------------------
Empl Name: @pers.firstName
===========================</pre>

A constructor can be made static. Here is an example:

@page
@model PracticalLearning.Pages.StaticityModel
@{
    Person.firstName = "Gertrude";
}

@functions{
    public class Person
    {
        public static string firstName;
        
        static Person()
        {
            firstName = "Gertrude";
        }
    }
}

<pre>===========================
Employee Information
---------------------------
Empl Name: @Person.firstName
===========================</pre>

this Object

When a class is not static, that class is represented in its body (in the body of the class) by a special object named this. You can use that object to access the members of that class but only when accessing those members from inside the class.

Introduction to Built-In Static Classes

The Console Class

When you have created an ASP.NET Core Web application, when you execute it, Microsoft Visual Studio opens a Hosting window and creates a website to display in a browser. The Hosting window is a Microsoft Windows object with a dark (usually black) background that displays some characters. Here is an example:

Add New Item

When the hosting window comes up, Microsoft Visual Studio writes some lines about the local server setup of your current application. You too can display some values about your application in that window. To allow you to display some values in the Hosting window, the .NET Framework provides the Console static class.

You can use the Console class to write in the console window through its Write() or its WriteLine() methods. Here is an example:

@{
    System.Console.Write("The Wonderful World of C# Programming");
}

If you are writing your code in a razor page, in the top section, after the @page and the other top lines, type @using System. After doing any of this, you can access a class of the namespace in your code.

Practical LearningPractical Learning: Introducing the Console

  1. Start a new ASP.NET Core Web App named CompoundInterest2 that uses the .NET 6.0 (Long-Term Support). Uncheck the Configure For HTTPS check box
  2. In the Solution Explorer, expand wwwroot
  3. In the Solution Explorer, under wwwroot, right-click css -> Add -> New Item...
  4. In the left list of the Add New Item dialog box, under Visual C#, expand ASP.NET Core. Expand Web, and click Content
  5. In the middle list, click Style Sheet
  6. Change the file Name to CompoundInterest
  7. Press Enter
  8. Change the document as follows:
    body {
    }
    
    .bold        { font-weight:      bold;  }
    .text-right  { text-align:       right  }
    .delimiter   { margin:           auto;
                   width:            650px; }
    .top-bar     { border-bottom:    6px solid blue;
                   background-color: #5f2c19 !important; }
    .common-font { font-family:      Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  9. In the Solution Explorer, expand Pages
  10. In the Solution Explorer, under Pages, expand Shared
  11. In the Solution Explorer, under Pages and under Shared, double-click _Layout.cshtml
  12. Change the document as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - Compound Interest</title>
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/CompoundInterest.css" asp-append-version="true" />
    </head>
    <body>
        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 top-bar">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-page="/Index">Compound Interest</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Index">Home</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Privacy">Privacy</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>
        <div class="container">
            <main role="main" class="pb-3">
                @RenderBody()
            </main>
        </div>
    
        <footer class="border-top footer text-muted">
            <div class="container">
                <p class="text-center common-font">&copy; 2022 - Compound Interest - <a asp-area="" asp-page="/Privacy">Privacy</a></p>
            </div>
        </footer>
    
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @await RenderSectionAsync("Scripts", required: false)
    </body>
    </html>
  13. In the Solution Explorer, under Pages, double-click Index.cshtml to open it

Practical LearningPractical Learning: Clearing the Console

  1. Change the Index.cshtml document as follows:
    @page
    @model IndexModel
    @{
        string strError          = "";
        string strFrequency      = "";
    
        double periods           = 0.00;
        double principal         = 0.00;
        double interestRate      = 0.00;
    
        string strFutureValue    = "0.00";
        string strInterestEarned = "0.00";
    
        if (Request.HasFormContentType)
        {
            try
            {
                principal = double.Parse(Request.Form["txtInitialValue"]);
            }
            catch(FormatException fe)
            {
                strError = "There was an error related to the Principal. The error is as follows: " + 
                            Environment.NewLine + fe.Message;
            }
    
            try
            {
                interestRate = double.Parse(Request.Form["txtInterestRate"]);
            }
            catch (FormatException fe)
            {
                strError = "The program produced an error related to the interest rate. The error was as follows: " +
                            Environment.NewLine + fe.Message;
            } 
    
            try
            {
                periods = double.Parse(Request.Form["txtPeriods"]);
            }
            catch (FormatException fe)
            {
                strError = "An error resulted from the value meant for the period. Please report the error as follows: " +
                            Environment.NewLine + fe.Message;
            } 
    
    
            double frequency   = 12.00;
            
            strFrequency = Request.Form["rdoFrequency"];
    
            switch (strFrequency)
            {
                case "Daily":
                    frequency = 365.00;
                    break;
                case "Weekly":
                    frequency = 52.00;
                    break;
                case "Monthly":
                    frequency = 12.00;
                    break;    
                case "Quaterly":
                    frequency = 4.00;
                    break;
                case "Semiannually":
                    frequency = 2.00;
                    break;
                case "Annually":
                    frequency = 1.00;
                    break;
            }
    
            double per            = periods / 100;
            double futureValue    = principal * Math.Pow((1.00 + (interestRate / frequency)), frequency * per);
            double interestEarned = futureValue - principal;
    
            strFutureValue        = $"{futureValue:F}";
            strInterestEarned     = $"{interestEarned:F}";
    
            System.Console.Clear();
            
            System.Console.WriteLine("======================================================");
            System.Console.WriteLine("Compound Interest");
            System.Console.WriteLine("======================================================");
            System.Console.WriteLine("Principal:        {0:f}", principal);
            System.Console.WriteLine("Interest Rate:    {0:f}%", interestRate);
            System.Console.WriteLine("Periods:          {0} years", periods);
            System.Console.WriteLine("------------------------------------------------------");
            System.Console.WriteLine("Future Value:     {0:f}", futureValue);
            System.Console.WriteLine("Interest Earned:  {0:f}", interestEarned);
            System.Console.WriteLine("======================================================");
        }
    }
    
    <h1 class="common-font text-center bold">Compound Interest</h1>       
    
    <hr />
    
    <form name="PayrollEvaluation" method="post" class="common-font delimiter">
    
    <h4>Compound Values:</h4>
    
    <hr />
        <table>
            <tr>
                <td style="width: 150px">@Html.Label("txtInitialValue", "Principal:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInitialValue", @principal, new { @class = "form-control" })</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>@Html.Label("txtInterestRate", "Interest Rate:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInterestRate", @interestRate, new { @class = "form-control" })</td>
                <td>%</td>
            </tr>
            <tr>
                <td>@Html.Label("txtPeriods", "Periods:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtPeriods", @periods, new { @class = "form-control" })</td>
                <td>years</td>
            </tr>
        </table>
    
        <hr />
    
        <h4>Compound Frequency:</h4>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 100px"><label for="rdoDaily">Daily</label></td>
                <td><input type="radio" id="rdoDaily" name="rdoFrequency" value="Daily" /></td>
                <td style="width: 50px">&nbsp;</td>
                <td style="width: 100px"><label for="rdoQuaterly">Quaterly</label></td>
                <td><input type="radio" id="rdoQuaterly" name="rdoFrequency" value="Quaterly" /></td>
            </tr>
            <tr>
                <td><label for="rdoWeekly">Weekly</label></td>
                <td><input type="radio" id="rdoWeekly" name="rdoFrequency" value="Weekly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoSemiannually">Semiannually</label></td>
                <td><input type="radio" id="rdoSemiannually" name="rdoFrequency" value="Semiannually" /></td>
            </tr>
            <tr>
                <td><label for="rdoMonthly">Monthly</label></td>
                <td><input type="radio" id="rdoMonthly" name="rdoFrequency" value="Monthly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoAnnually">Annually</label></td>
                <td><input type="radio" id="rdoAnnually" name="rdoFrequency" value="Annually" /></td>
            </tr>
        </table>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 150px">&nbsp;</td>
                <td><input type="submit" value="Evaluate Compound Interest" name="btnCalculate" style="width: 250px" /></td>
            </tr>
        </table>
    
        <hr />
        
        <table>
            <tr>
                <td style="width: 200px" class="bold">Compound Frequency:</td>
                <td style="text-align: right">@strFrequency</td>
            </tr>
            <tr>
                <td class="bold">Future Value:</td>
                <td style="text-align: right">@strFutureValue</td>
            </tr>
            <tr>
                <td class="bold">Interest Earned:</td>
                <td style="text-align: right">@strInterestEarned</td>
            </tr>
        </table>
    </form>
  2. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Compount Interest

  3. Click the Principal text box and type 12668.74
  4. Click the Interest Rate text box and type 10.85
  5. Click the Periods text box and type 4

    Compount Interest

  6. Click each of the radio buttons and click the Evaluate Compound Interest button:

    Compount Interest

    Compount Interest

    Compount Interest

    Compount Interest

  7. Close the browser and return to your programming environment, press Enter

The Built-In Math Class

To help you perform some basic algebraic and geometric operations in your application, the .NET Framework provides a static class named Math. Besides the Math class, you can also take advantage of Visual Basic's very powerful library of functions. This library is one of the most extended set of functions of various area of business mathematics.

Practical LearningPractical Learning: Introducing Math Functions

  1. Start Microsoft Visual Studio and create a new ASP.NET Core Web App named CompoundInterest1 that uses the .NET 6.0 (Long-Term Support). Uncheck the Configure For HTTPS check box
  2. In the Solution Explorer, expand wwwroot
  3. In the Solution Explorer, under wwwroot, right-click css -> Add -> New Item...
  4. In the left list of the Add New Item dialog box, under Visual C#, expand ASP.NET Core. Expand Web, and click Content
  5. In the middle list, click Style Sheet
  6. Change the file Name to CompoundInterest
  7. Press Enter
  8. Change the document as follows:
    body {
    }
    
    .bold        { font-weight:      bold;  }
    .text-right  { text-align:       right  }
    .delimiter   { margin:           auto;
                   width:            650px; }
    .top-bar     { border-bottom:    6px solid blue;
                   background-color: #5f2c19 !important; }
    .common-font { font-family:      Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  9. In the Solution Explorer, expand Pages
  10. In the Solution Explorer, under Pages, expand Shared
  11. In the Solution Explorer, under Pages and under Shared, double-click _Layout.cshtml
  12. Change the document as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - Compound Interest</title>
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/CompoundInterest.css" asp-append-version="true" />
    </head>
    <body>
        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 top-bar">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-page="/Index">Compound Interest</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Index">Home</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Privacy">Privacy</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>
        <div class="container">
            <main role="main" class="pb-3">
                @RenderBody()
            </main>
        </div>
    
        <footer class="border-top footer text-muted">
            <div class="container">
                <p class="text-center common-font">&copy; 2022 - Compound Interest - <a asp-area="" asp-page="/Privacy">Privacy</a></p>
            </div>
        </footer>
    
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @await RenderSectionAsync("Scripts", required: false)
    </body>
    </html>

Practical LearningPractical Learning: Getting the Power of a Number

  1. In the Solution Explorer, under Pages, double-click Index.cshtml to open it
  2. Change the document as follows:
    @page
    @model IndexModel
    @{
        string strError          = "";
        double periods           = 0.00;
        double principal         = 0.00;
        double interestRate      = 0.00;
        string strFutureValue    = "0.00";
        string strInterestEarned = "0.00";
    
        if (Request.HasFormContentType)
        {
            try
            {
                principal = double.Parse(Request.Form["txtInitialValue"]);
            }
            catch(FormatException fe)
            {
                strError = "There was an error related to the Principal. The error is as follows: " + 
                            Environment.NewLine + fe.Message;
            }
    
            try
            {
                interestRate = double.Parse(Request.Form["txtInterestRate"]);
            }
            catch (FormatException fe)
            {
                strError = "The program produced an error related to the interest rate. The error was as follows: " +
                            Environment.NewLine + fe.Message;
            } 
    
            try
            {
                periods = double.Parse(Request.Form["txtPeriods"]);
            }
            catch (FormatException fe)
            {
                strError = "An error resulted from the value meant for the period. Please report the error as follows: " +
                            Environment.NewLine + fe.Message;
            } 
            
            double frequency   = 12.00;
            double per         = periods / 100;
            double futureValue = principal * Math.Pow((1.00 + (interestRate / frequency)), frequency * per);
            double interestEarned = futureValue - principal;
    
            strFutureValue = $"{futureValue:F}";
            strInterestEarned       = $"{interestEarned:F}";
        }
    }
    
    <h1 class="common-font text-center bold">Compound Interest</h1>       
    
    <hr />
    
    <form name="PayrollEvaluation" method="post" class="common-font delimiter">
    
    <h4>Compound Values:</h4>
    
    <hr />
        <table>
            <tr>
                <td style="width: 150px">@Html.Label("txtInitialValue", "Principal:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInitialValue", @principal, new { @class = "form-control" })</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>@Html.Label("txtInterestRate", "Interest Rate:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInterestRate", @interestRate, new { @class = "form-control" })</td>
                <td>%</td>
            </tr>
            <tr>
                <td>@Html.Label("txtPeriods", "Periods:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtPeriods", @periods, new { @class = "form-control" })</td>
                <td>years</td>
            </tr>
        </table>
    
        <hr />
    
        <h4>Compound Frequency:</h4>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 100px"><label for="rdoDaily">Daily</label></td>
                <td><input type="radio" id="rdoDaily" name="rdoFrequency" value="Daily" /></td>
                <td style="width: 50px">&nbsp;</td>
                <td style="width: 100px"><label for="rdoQuaterly">Quaterly</label></td>
                <td><input type="radio" id="rdoQuaterly" name="rdoFrequency" value="Quaterly" /></td>
            </tr>
            <tr>
                <td><label for="rdoWeekly">Weekly</label></td>
                <td><input type="radio" id="rdoWeekly" name="rdoFrequency" value="Weekly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoSemiannually">Semiannually</label></td>
                <td><input type="radio" id="rdoSemiannually" name="rdoFrequency" value="Semiannually" /></td>
            </tr>
            <tr>
                <td><label for="rdoMonthly">Monthly</label></td>
                <td><input type="radio" id="rdoMonthly" name="rdoFrequency" value="Monthly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoAnnually">Annually</label></td>
                <td><input type="radio" id="rdoAnnually" name="rdoFrequency" value="Annually" /></td>
            </tr>
        </table>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 150px">&nbsp;</td>
                <td><input type="submit" value="Evaluate Compound Interest" name="btnCalculate" style="width: 250px" /></td>
            </tr>
        </table>
    
        <hr />
        
        <table>
            <tr>
                <td style="width: 200px" class="bold">Future Value:</td>
                <td style="text-align: right">@strFutureValue</td>
            </tr>
            <tr>
                <td class="bold">Interest Earned:</td>
                <td style="text-align: right">@strInterestEarned</td>
            </tr>
        </table>
    </form>
  3. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Compount Interest

  4. Click the Principal text box and type 5284.65
  5. Click the Interest Rate text box and type 12.35
  6. Click the Periods text box and type 5

    Compount Interest

  7. Click the Evaluate Compound Interest button:

    Compount Interest

  8. Return to your programming environment, press Enter
  9. Change the Index.cshtml document as follows:
    @page
    @model IndexModel
    @{
        string strError          = "";
        double periods           = 0.00;
        double principal         = 0.00;
        double interestRate      = 0.00;
        string strFutureValue    = "0.00";
        string strInterestEarned = "0.00";
        string strFrequency      = "";
    
        if (Request.HasFormContentType)
        {
            try
            {
                principal = double.Parse(Request.Form["txtInitialValue"]);
            }
            catch(FormatException fe)
            {
                strError = "There was an error related to the Principal. The error is as follows: " + 
                            Environment.NewLine + fe.Message;
            }
    
            try
            {
                interestRate = double.Parse(Request.Form["txtInterestRate"]);
            }
            catch (FormatException fe)
            {
                strError = "The program produced an error related to the interest rate. The error was as follows: " +
                            Environment.NewLine + fe.Message;
            } 
    
            try
            {
                periods = double.Parse(Request.Form["txtPeriods"]);
            }
            catch (FormatException fe)
            {
                strError = "An error resulted from the value meant for the period. Please report the error as follows: " +
                            Environment.NewLine + fe.Message;
            } 
    
    
            double frequency   = 12.00;
            
            strFrequency = Request.Form["rdoFrequency"];
    
            switch (strFrequency)
            {
                case "Daily":
                    frequency = 365.00;
                    break;
                case "Weekly":
                    frequency = 52.00;
                    break;
                case "Monthly":
                    frequency = 12.00;
                    break;    
                case "Quaterly":
                    frequency = 4.00;
                    break;
                case "Semiannually":
                    frequency = 2.00;
                    break;
                case "Annually":
                    frequency = 1.00;
                    break;
            }
    
            double per            = periods / 100;
            double futureValue    = principal * Math.Pow((1.00 + (interestRate / frequency)), frequency * per);
            double interestEarned = futureValue - principal;
    
            strFutureValue        = $"{futureValue:F}";
            strInterestEarned     = $"{interestEarned:F}";
        }
    }
    
    <h1 class="common-font text-center bold">Compound Interest</h1>       
    
    <hr />
    
    <form name="PayrollEvaluation" method="post" class="common-font delimiter">
    
    <h4>Compound Values:</h4>
    
    <hr />
        <table>
            <tr>
                <td style="width: 150px">@Html.Label("txtInitialValue", "Principal:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInitialValue", @principal, new { @class = "form-control" })</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>@Html.Label("txtInterestRate", "Interest Rate:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtInterestRate", @interestRate, new { @class = "form-control" })</td>
                <td>%</td>
            </tr>
            <tr>
                <td>@Html.Label("txtPeriods", "Periods:", new { @class = "bold" })</td>
                <td>@Html.TextBox("txtPeriods", @periods, new { @class = "form-control" })</td>
                <td>years</td>
            </tr>
        </table>
    
        <hr />
    
        <h4>Compound Frequency:</h4>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 100px"><label for="rdoDaily">Daily</label></td>
                <td><input type="radio" id="rdoDaily" name="rdoFrequency" value="Daily" /></td>
                <td style="width: 50px">&nbsp;</td>
                <td style="width: 100px"><label for="rdoQuaterly">Quaterly</label></td>
                <td><input type="radio" id="rdoQuaterly" name="rdoFrequency" value="Quaterly" /></td>
            </tr>
            <tr>
                <td><label for="rdoWeekly">Weekly</label></td>
                <td><input type="radio" id="rdoWeekly" name="rdoFrequency" value="Weekly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoSemiannually">Semiannually</label></td>
                <td><input type="radio" id="rdoSemiannually" name="rdoFrequency" value="Semiannually" /></td>
            </tr>
            <tr>
                <td><label for="rdoMonthly">Monthly</label></td>
                <td><input type="radio" id="rdoMonthly" name="rdoFrequency" value="Monthly" /></td>
                <td>&nbsp;</td>
                <td><label for="rdoAnnually">Annually</label></td>
                <td><input type="radio" id="rdoAnnually" name="rdoFrequency" value="Annually" /></td>
            </tr>
        </table>
    
        <hr />
    
        <table>
            <tr>
                <td style="width: 150px">&nbsp;</td>
                <td><input type="submit" value="Evaluate Compound Interest" name="btnCalculate" style="width: 250px" /></td>
            </tr>
        </table>
    
        <hr />
        
        <table>
            <tr>
                <td style="width: 200px" class="bold">Compound Frequency:</td>
                <td style="text-align: right">@strFrequency</td>
            </tr>
            <tr>
                <td class="bold">Future Value:</td>
                <td style="text-align: right">@strFutureValue</td>
            </tr>
            <tr>
                <td class="bold">Interest Earned:</td>
                <td style="text-align: right">@strInterestEarned</td>
            </tr>
        </table>
    </form>
  10. To execute the application, on the main menu, click Debug -> Start Without Debugging
  11. If the browser presents a Resend button, click it, or refresh the browser
  12. Click each of the radio buttons and click the Evaluate Compound Interest button:

    Compount Interest

    Compount Interest

    Compount Interest

  13. Close the browser and return to your programming environment, press Enter
  14. Save the following images to your computer:

    Polygons - Square

    Polygons - Equilateral Triangle

  15. Start a new ASP.NET Core Web App named Geometry3 that uses the .NET 6.0 (Long-Term Support). Uncheck the Configure For HTTPS check box
  16. In the Solution Explorer, right-click Geometry3 -> Add -> New Folder
  17. Type Models
  18. In the Solution Explorer, right-click wwwroot -> Add -> New Folder
  19. Type images and press Enter
  20. In the Solution Explorer, under wwwroot, right-click images -> Add -> Existing Item...
  21. Select the above images, then select the trapezoid1.png and the tp.png images you had saved in previous lessons. Add them to the project
  22. In the Solution Explorer, under wwwroot, right-click css -> Add -> New Item...
  23. In the left list of the Add New Item dialog box, under Visual C#, expand ASP.NET Core. Expand Web, and click Content
  24. In the middle list, click Style Sheet
  25. Change the file Name to Geometry
  26. Press Enter
  27. Change the document as follows:
    body {
    }
    
    .bold        { font-weight:      bold;  }
    .text-right  { text-align:       right  }
    .delimiter   { margin:           auto;
                   width:            650px; }
    .top-bar     { border-bottom:    6px solid blue;
                   background-color: #0046be !important; }
    .common-font { font-family:      Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  28. In the Solution Explorer, expand Pages
  29. In the Solution Explorer, under Pages, expand Shared
  30. In the Solution Explorer, under Pages and under Shared, double-click _Layout.cshtml
  31. Change the document as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - Geometry</title>
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/Geometry.css" asp-append-version="true" />
    </head>
    <body>
        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 top-bar">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-page="/Index">Geometry</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Square">Square</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/EquilateralTriangle">Equilateral Triangle</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/Trapezoid">Trapezoid</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/TrapezoidalPrism">Trapezoid Prism</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>
        <div class="container">
            <main role="main" class="pb-3">
                @RenderBody()
            </main>
        </div>
    
        <footer class="border-top footer text-muted">
            <div class="container">
                <p class="text-center common-font">&copy; 2022 - Geometry - <a asp-area="" asp-page="/Privacy">Privacy</a></p>
            </div>
        </footer>
    
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @await RenderSectionAsync("Scripts", required: false)
    </body>
    </html>

ApplicationPractical Learning: Finding the Square Root of a Number

  1. In the Solution Explorer, right-click Models -> Add -> Class...
  2. In the middle list of the Add New Item dialog box, make sure Class is selected.
    Change the suggested name to Square
  3. Click Add
  4. Change the Square class as follows:
    namespace Geometry3.Models
    {
        public class Square
        {
            public double Side { get; set; }
    
            public Square(double side)
            {
                Side = side;
            }
    
            public double Perimeter
            {
                get
                {
                    return Side * 4.00;
                }
            }
    
            public virtual double Area
            {
                get
                {
                    return Side * Side;
                }
            }
    
            public virtual double CalculateInradius()
            {
                return Side / 2.00;
            }
    
            public virtual double CalculateCircumradius()
            {
                return Math.Sqrt(2.00) * Side / 2.00;
            }
        }
    }
  5. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  6. In the middle list of the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Press Enter
  7. Change the file name to Square
  8. Click Add
  9. Change the document as follows:
    @page
    @model Geometry3.Pages.SquareModel
    @using Geometry3.Models
    @{
        double side = 0.00;
        string? strMessage = null;
        Square sqr = new Square(0.00);
    
        if (Request.HasFormContentType)
        {
            try
            {
                side = double.Parse(Request.Form["txtSide"])!;
            }
            catch(FormatException fexc)
            {
                strMessage = "You must provide a valid value for the side of the square." + 
                             Environment.NewLine + "The error produced is: " + 
                             fexc.Message;
            }
    
            sqr = new(side);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Geometry - Polygon - Square</h2>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 400px" rowspan="8">
                      <img src="~/images/triangle1.png" width="391" height="315" alt="Geometry - Square">
                  </td>
                  <td style="width: 150px" class="bold">Side:</td>
                  <td>@Html.TextBox("txtSide", @sqr.Side, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Calculate" /></td>
              </tr>
              <tr>
                  <td class="bold">Perimeter:</td>
                  <td class="text-right">@sqr.Perimeter</td>
              </tr>
              <tr>
                  <td class="bold">Area:</td>
                  <td class="text-right">@sqr.Area</td>
              </tr>
              <tr>
                  <td class="bold">Inradius:</td>
                  <td class="text-right">@sqr.CalculateInradius()</td>
              </tr>
              <tr>
                  <td class="bold">Circumradius:</td>
                  <td class="text-right">@sqr.CalculateCircumradius()</td>
              </tr>
          </table>
      </form>
    
      <hr />
      <p class="text-center">@strMessage</p>
    </div>
  10. In the Solution Explorer, right-click Models -> Add -> Class...
  11. In the middle list of the Add New Item dialog box, make sure Class is selected.
    Change the file Name to EquilateralTriangle
  12. Press Enter
  13. Change the document as follows:
    namespace Geometry3.Models
    {
        public class EquilateralTriangle
        {
            private double s;
            public readonly double NumberOfSides;
    
            public EquilateralTriangle(double side)
            {
                s = side;
                NumberOfSides = 3;
            }
    
            public double Side
            {
                get { return s;  }
                set { s = value; }
            }
    
            public double Perimeter    => s * NumberOfSides;
            public double Height       => s * Math.Sqrt(3) / 2;
            public double Area         => s * s * Math.Sqrt(3) / 4;
            public double Inradius     => s * Math.Sqrt(3) / 6;
            public double Circumradius => s / Math.Sqrt(3);
        }
    }
  14. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  15. In the middle list of the Add New Scaffolded Item dialog box, make sure Razor -Page - Empty is selected.
    Click Add
  16. Change the file Name to EquilateralTriangle
  17. Click Add
  18. Change the document as follows:
    @page
    @model Geometry3.Pages.EquilateralTriangleModel
    @using Geometry3.Models
    @{
        double side = 0.00;
        string? strMessage = null;
        EquilateralTriangle et = new(0.00);
    
        if (Request.HasFormContentType)
        {
            try
            {
                side = double.Parse(Request.Form["txtSide"])!;
            }
            catch(FormatException fexc)
            {
                strMessage = "You must provide a valid common value for the sides of the triangle." + 
                             Environment.NewLine + "The error produced is: " + 
                             fexc.Message;
            }
    
            et = new(side);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Geometry - Equilateral Triangle</h2>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 400px" rowspan="8">
                      <img src="~/images/triangle1.png" width="391" height="315" alt="Geometry - Square">
                  </td>
                  <td style="width: 150px" class="bold">Side:</td>
                  <td>@Html.TextBox("txtSide", @et.Side, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Calculate" /></td>
              </tr>
              <tr>
                  <td class="bold">Number of Sides:</td>
                  <td class="text-right">@et.NumberOfSides</td>
              </tr>
              <tr>
                  <td class="bold">Height:</td>
                  <td class="text-right">@et.Height</td>
              </tr>
              <tr>
                  <td class="bold">Perimeter:</td>
                  <td class="text-right">@et.Perimeter</td>
              </tr>
              <tr>
                  <td class="bold">Area:</td>
                  <td class="text-right">@et.Area</td>
              </tr>
              <tr>
                  <td class="bold">Inradius:</td>
                  <td class="text-right">@et.Inradius</td>
              </tr>
              <tr>
                  <td class="bold">Circumradius:</td>
                  <td class="text-right">@et.Circumradius</td>
              </tr>
          </table>
      </form>
    
      <hr />
      <p class="text-center">@strMessage</p>
    </div>
  19. In the Solution Explorer, right-click Models -> Add -> Clas...
  20. In the middlelist of the Add New Item dialog box, make sure Class is selected.
    Change the Name of the file to Trapezoid
  21. Click Add
  22. Change the class as follows:
    namespace Geometry3.Models
    {
        public class Trapezoid
        {
            public double Edge      { get; set; }
            public double ShortWidth { get; set; }
            public double LargeWidth { get; set; }
    
            public Trapezoid(double sSide, double lSide, double edge)
            {
                Edge       = edge;
                LargeWidth = lSide;
                ShortWidth = sSide;
            }
    
            public double Perimeter => LargeWidth + Edge + ShortWidth + Edge;
    
            // http://mathworld.wolfram.com/IsoscelesTrapezoid.html
            public double Height
            {
                get
                {
                    return Math.Sqrt((Edge * Edge) - (Math.Pow(LargeWidth - ShortWidth, 2.00) / 4.00));
                }
            }
    
            virtual public double CalculateArea()
            {
                return (LargeWidth + ShortWidth) * Height / 2.00;
            }
        }
    }
  23. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  24. In the middle list of the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  25. Change the file Name to Trapezoid
  26. Click Add
  27. Cchange the document as follows:
    @page
    @model Geometry3.Pages.TrapezoidModel
    @using Geometry3.Models
    @{
        string? strMessage = null;
        Trapezoid trap = new(0.00, 0.00, 0.00);
    
        if (Request.HasFormContentType)
        {
            try
            {
                trap.ShortWidth = double.Parse(Request.Form["txtShortWidth"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
    
            try
            {
                trap.LargeWidth = double.Parse(Request.Form["txtLargeWidth"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
    
            try
            {
                trap.Edge = double.Parse(Request.Form["txtEdge"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Geometry - Trapezoid</h2>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="9">
                      <img src="~/images/trapezoid1.png" width="296" height="247" alt="Geometry - Trapezoid">
                  </td>
                  <td style="width: 125px" class="bold">Short Width:</td>
                  <td>@Html.TextBox("txtShortWidth", @trap.ShortWidth, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Large Width:</td>
                  <td>@Html.TextBox("txtLargeWidth", @trap.LargeWidth, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Edge:</td>
                  <td>@Html.TextBox("txtEdge", @trap.Edge, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Calculate" /></td>
              </tr>
              <tr>
                  <td class="bold">Height:</td>
                  <td>@Html.TextBox("txtHeight", @trap.Height, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Area:</td>
                  <td>@Html.TextBox("txtArea", @trap.CalculateArea(), new { @class = "form-control text-right" })</td>
              </tr>
          </table>
      </form>
    
      <hr />
      <p class="text-center">@strMessage</p>
    </div>
  28. In the Solution Explorer, right-click Models -> Add -> Class...
  29. Make sure Class is selected in the Add New Item dialog box.
    Change the file Name to TrapezoidalPrism
  30. Click Add
  31. Change the class as follows:
    namespace Geometry3.Models
    {
        public class TrapezoidalPrism : Trapezoid
        {
            public double Length { get; set; }
    
            public TrapezoidalPrism(double sSide, double lSide, double side, double len)
                    : base(sSide, lSide, side)
            {
                Length = len;
            }
    
            public double BaseArea => base.CalculateArea();
    
            override public double CalculateArea()
            {
                double shortArea = ShortWidth * Length;
                double longArea  = LargeWidth * Length;
                double sideArea  = Edge       * Length;
                return (BaseArea * 2.00) + shortArea + longArea + (sideArea * 2.00);
            }
    
            public double Volume => BaseArea * Length;
        }
    }
  32. To start a new razor page, in the Solution Explorer, right-click Pages -> Add -> Razor Page...
  33. In the Add New Scaffolded Item dialog box, makew sure Razor Page - Empty is selected and click Add
  34. Change the file Name to TrapezoidalPrism
  35. Press Enter
  36. Change the document as follows:
    @page
    @model Geometry3.Pages.TrapezoidalPrismModel
    @using Geometry3.Models
    @{
        string? strMessage = null;
        TrapezoidalPrism trap = new TrapezoidalPrism(0.00, 0.00, 0.00, 0.00);
    
        if (Request.HasFormContentType)
        {
            try
            {
                trap.ShortWidth = double.Parse(Request.Form["txtShortWidth"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
            try
            {
                trap.LargeWidth = double.Parse(Request.Form["txtLargeWidth"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
            try
            {
                trap.Edge = double.Parse(Request.Form["txtEdge"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
            try
            {
                trap.Length = double.Parse(Request.Form["txtLength"]);
            }
            catch(FormatException fexc)
            {
                strMessage = fexc.Message;
            }
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Geometry - Trapezoidal Prism</h2>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="9">
                      <img src="~/images/tp.png" width="289" height="230" alt="Geometry - Trapezoidal Prism">
                  </td>
                  <td style="width: 125px" class="bold">Short Width:</td>
                  <td>@Html.TextBox("txtShortWidth", @trap.ShortWidth, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Large Width:</td>
                  <td>@Html.TextBox("txtLargeWidth", @trap.LargeWidth, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Edge:</td>
                  <td>@Html.TextBox("txtEdge", @trap.Edge, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Length:</td>
                  <td>@Html.TextBox("txtLength", @trap.Length, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Calculate" /></td>
              </tr>
              <tr>
                  <td class="bold">Base Area:</td>
                  <td>@Html.TextBox("txt>BaseArea", @trap.BaseArea, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Total Area:</td>
                  <td>@Html.TextBox("txtTotalArea", @trap.CalculateArea(), new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td class="bold">Volume:</td>
                  <td>@Html.TextBox("txtVolume", @trap.Volume, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
      </form>
    
      <hr />
      <p class="text-center">@strMessage</p>
    </div>
  37. To execute the application to test it, on the main menu, click Debug -> Start Without Debugging
  38. Click the Square link:

    Mathematical Functions - Square

  39. Click the Side text box and type 837.59

    Mathematical Functions - Square

  40. Click the Calculate button:

    Mathematical Functions - Square

  41. Click the Equilateral Triangle link:

    Mathematical Functions

  42. Click the Side text box and type 309.66

    Mathematical Functions

  43. Click the Calculate button:

    Mathematical Functions

  44. Click the Trapezoid link

    Mathematical Functions

  45. Click the Short Width text box and type 137.96
  46. Click the Large Width text box and type 209.73
  47. Click the Edge text box and type 87.59

    Mathematical Functions

  48. Click the Calculate button

    Mathematical Functions

  49. Click the Trapezoidal Prism link

    Mathematical Functions

  50. Click the Short Width text box and type 229.47
  51. Click the Large Width text box and type 167.66
  52. Set the Edge value to 98.59
  53. For the Length, type 214.85

    Mathematical Functions

  54. Click theb Calculate button

    Mathematical Functions

  55. Close the browser and return to your programming environment
  56. Close your programming environment

Practical LearningPractical Learning: Introducing Trigonometry

  1. Save the following images to your computer:

    Oblique Triangles

    Oblique Triangles

    Oblique Triangles

    Oblique Triangles

  2. Start Microsoft Visual Studio and create a new ASP.NET Core Web App that supports .NET 6.0 (Long-Term Support) named ObliqueTriangles1. Uncheck the Configure For HTTPS check box
  3. In the Solution Explorer, right-click wwwroot -> Add -> New Folder
  4. Type images and press Enter
  5. In the Solution Explorer, under wwwroot, right-click images -> Add -> Existing Item...
  6. Select the images you had saved and click Add them to the project
  7. In the Solution Explorer, expand wwwroot
  8. In the Solution Explorer, under wwwroot, right-click css -> Add -> New Item...
  9. In the left list of the Add New Item dialog box, under Visual C#, expand ASP.NET Core. Expand Web, and click Content
  10. In the middle list, click Style Sheet
  11. Change the file Name to Trigonometry
  12. Press Enter
  13. Change the document as follows:
    body {
    }
    
    .bold        { font-weight:      bold;  }
    .text-right  { text-align:       right  }
    .delimiter   { margin:           auto;
                   width:            650px; }
    .top-bar     { border-bottom:    6px solid blue;
                   background-color: #800000 !important; }
    .common-font { font-family:      Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  14. In the Solution Explorer, expand Pages
  15. In the Solution Explorer, under Pages, expand Shared
  16. In the Solution Explorer, under Pages and under Shared, double-click _Layout.cshtml
  17. Change the document as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - Oblique Triangles</title>
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/Geometry.css" asp-append-version="true" />
    </head>
    <body>
        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 top-bar">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-page="/Index">Oblique Triangles</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/AAS">AAS</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/SAS">SAS</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/ASA">ASA</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/SSS">SSS</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>
        <div class="container">
            <main role="main" class="pb-3">
                @RenderBody()
            </main>
        </div>
    
        <footer class="border-top footer text-muted">
            <div class="container">
                <p class="text-center common-font">&copy; 2022 - Oblique Triangles - <a asp-area="" asp-page="/Privacy">Privacy</a></p>
            </div>
        </footer>
    
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @await RenderSectionAsync("Scripts", required: false)
    </body>
    </html>

Practical LearningPractical Learning: Introducing the Sine Value

  1. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  2. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  3. Change the file Name to AAS
  4. Click Add
  5. Change the document as follows:
    @page
    @model ObliqueTriangles1.Pages.AASModel
    @{
        string? strMessage = null;
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                angle1 = double.Parse(Request.Form["txtAASAngle1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the lower left angle of the AAS shape.";
            }
    
            try
            {
                  angle2 = double.Parse(Request.Form["txtAASAngle2"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the lower right angle of the AAS shape.";
            }
    
            try
            {
                side1 = double.Parse(Request.Form["txtAASSide1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the right side of the AAS shape.";
            }
    
            // Here, we use the law of sines
            angle3 = 180 - (angle1 + angle2);
            side2 = side1 * Math.Sin(angle2 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
            side3 = side1 * Math.Sin(angle3 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - AAS Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Angles and 1 Side</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/aas.png" width="258" height="159" alt="Oblique Triangles - AAS Shape">
                  </td>
                  <td style="width: 150px">Known Angle 1:</td>
                  <td>@Html.TextBox("txtAASAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 2:</td>
                  <td>@Html.TextBox("txtAASAngle2", @angle2, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 1:</td>
                  <td>@Html.TextBox("txtAASSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 1 Angle and 2 Sides</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 3:</td>
              <td>@Html.TextBox("txtAASAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 2:</td>
              <td>@Html.TextBox("txtAASSide2", @side2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtAASSide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    
      <hr />
      <p class="text-center">@strMessage</p>
    </div>
  6. To execute, on the main menu, click Debug -> Start Without Debugging
  7. Click the AAS link

    Oblique Triangles - AAS

  8. Click the Known Angle 1 text box and type 58
  9. Click the Known Angle 2 text box and type 28
  10. Click the Known Side 1 text box and type 6.2

    Oblique Triangles - AAS

  11. Click the Find Unknown Values button:

    Oblique Triangles - AAS

  12. Return to your programming environment

Practical LearningPractical Learning: Introducing Cosines

  1. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  2. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  3. Change the file Name to SAS
  4. Click Add
  5. Change the document as follows:
    @page
    @model ObliqueTriangles1.Pages.SASModel
    @{
        string? strMessage = null;
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                side1 = double.Parse(Request.Form["txtSASSide1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for one of the known sides of the SAS shape.";
            }
    
            try
            {
                  angle1 = double.Parse(Request.Form["txtSASAngle1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the known angle of the SAS shape.";
            }
    
            try
            {
                side2 = double.Parse(Request.Form["txtSASSide2"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the other known side of the SAS shape.";
            }
    
            // Here, we use the law of cosines
            side3 = Math.Sqrt((side1 * side1) +
                              (side2 * side2) -
                              (2 * side1 * side2 * Math.Cos(angle1 * Math.PI / 180)));
            angle2 = Math.Acos(((side3 * side3) +
                               (side2 * side2) -
                               (side1 * side1)) /
                               (2 * side3 * side2)) * 180 / Math.PI;
            angle3 = 180 - (angle1 + angle2);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - SAS  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Sides and 1 Angle</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/sas.png" width="260" height="138" alt="Oblique Triangles - SAS Shape">
                  </td>
                  <td style="width: 150px">Known Side 1:</td>
                  <td>@Html.TextBox("txtSASSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 1:</td>
                  <td>@Html.TextBox("txtSASAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 2:</td>
                  <td>@Html.TextBox("txtSASSide2", @side2, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 1 Side and 2 Angles</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 2:</td>
              <td>@Html.TextBox("txtSASAngle2", @angle2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtSASSide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtSASAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    
      <hr />
    
      <p class="text-center">@strMessage</p>
    </div>
  6. To execute, on the main menu, click Debug -> Start Without Debugging
  7. Click the SAS link:

    Oblique Triangles - SAS

  8. Click the Known Side 1 text box and type 15
  9. Click the Known Angle 1 text box and type 28
  10. Click the Known Side 2 text box and type 43.6

    Oblique Triangles - SAS

  11. Click the Find Unknown Values button:

    Oblique Triangles - SAS

  12. Return to your programming environment
  13. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  14. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  15. Change the file Name to ASA
  16. Click Add
  17. Change the document as follows:
    @page
    @model ObliqueTriangles1.Pages.ASAModel
    @{
        string? strMessage = null;
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                angle1 = double.Parse(Request.Form["txtASAAngle1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for one of the known angles of the ASA shape.";
            }
    
            try
            {
                  side1 = double.Parse(Request.Form["txtASASide1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the side that is between the angles whose values are about the ASA shape.";
            }
    
            try
            {
                angle2 = double.Parse(Request.Form["txtASAAngle2"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the other known angle of the ASA oblique triangle.";
            }
    
            // Here, we use the law of sines
            angle3 = 180 - (angle1 + angle2);
            side2 = side1 * Math.Sin(angle2 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
            side3 = side1 * Math.Sin(angle3 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - ASA  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Angles and 1 Side joining them</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/asa.png" width="260" height="138" alt="Oblique Triangles - SAS Shape">
                  </td>
                  <td style="width: 150px">Known Angle 1:</td>
                  <td>@Html.TextBox("txtASAAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 1:</td>
                  <td>@Html.TextBox("txtASASide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 2:</td>
                  <td>@Html.TextBox("txtASAAngle2", @angle2, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 2 Sides and 1 Angle between them</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Side 2:</td>
              <td>@Html.TextBox("txtASASide2", @side2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtASAAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtASASide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    
      <hr />
    
      <p class="text-center">@strMessage</p>
    </div>
  18. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  19. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  20. Change the file Name to SSS
  21. Click Add
  22. Change the document as follows:
    @page
    @model ObliqueTriangles1.Pages.SSSModel
    @{
        string? strMessage = null;
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                side1 = double.Parse(Request.Form["txtSSSSide1"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for one of the known sides of the SSS shape.";
            }
    
            try
            {
                  side2 = double.Parse(Request.Form["txtSSSSide2"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for another side of the SSS triangle.";
            }
    
            try
            {
                side3 = double.Parse(Request.Form["txtSSSSide3"]);
            }
            catch (FormatException)
            {
                strMessage = "You must type a value for the remaining known side of the SSS oblique triangle.";
            }
    
            // Here, we use the law of cosines
            angle1 = Math.Acos(((side3 * side3) +
                                (side2 * side2) -
                                (side1 * side1)) /
                                (2 * side3 * side2)) * 180 / Math.PI;
                
            angle2 = Math.Acos(((side3 * side3) +
                                (side1 * side1) -
                                (side2 * side2)) /
                                (2 * side3 * side1)) * 180 / Math.PI;
          
            angle3 = 180 - (angle1 + angle2);
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - SSS  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: All 3 Sides</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/sss.png" width="259" height="137" alt="Oblique Triangles - SSS Shape">
                  </td>
                  <td style="width: 150px">Known Side 1:</td>
                  <td>@Html.TextBox("txtSSSSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 2:</td>
                  <td>@Html.TextBox("txtSSSSide2", @side2, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 3:</td>
                  <td>@Html.TextBox("txtSSSSide3", @side3, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: All 3 Angles</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 1:</td>
              <td>@Html.TextBox("txtSSSAngle1", @angle1, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 2:</td>
              <td>@Html.TextBox("txtSSSAngle2", @angle2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtSSSAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    
      <hr />
    
      <p class="text-center">@strMessage</p>
    </div>
  23. To execute the application to test it, on the main menu, click Debug -> Start Without Debugging
  24. Click the ASA link:

    Oblique Triangles - ASA

  25. Click the Known Angle 1 text box and type 131
  26. Click the Known Angle 2 text box and type 10
  27. Click the Known Side 1 text box and type 23

    Oblique Triangles - ASA

  28. Click the Find Unknown Values button:

    Oblique Triangles - ASA

  29. Click the SSS link

    Oblique Triangles - SSS

  30. Click the Known Side 1 text box and type 2.8
  31. Click the Known Side 2 text box and type 4.7
  32. Click the Known Side 3 text box and type 3.5

    Oblique Triangles - SSS

  33. Click the Find Known Values

    Oblique Triangles - SSS

  34. Close the window and return to your programming environment
  35. Start Microsoft Visual Studio and create a new ASP.NET Core Web App that supports .NET 7.0 (Standard Term Support) named ObliqueTriangles3. Uncheck the Configure For HTTPS check box
  36. In the Solution Explorer, right-click wwwroot -> Add -> New Folder
  37. Type images and press Enter
  38. In the Solution Explorer, under wwwroot, right-click images -> Add -> Existing Item...
  39. Select the aas.png, asa.png, sas.png, and sss.png images you had saved from a previous lesson. Click Add to add them to the project
  40. In the Solution Explorer, under wwwroot, right-click css -> Add -> New Item...
  41. In the left list of the Add New Item dialog box, under Visual C#, expand ASP.NET Core. Expand Web, and click Content
  42. In the middle list, click Style Sheet
  43. Change the file Name to Trigonometry
  44. Press Enter
  45. Change the document as follows:
    body {
    }
    
    .bold        { font-weight:      bold;  }
    .text-right  { text-align:       right  }
    .delimiter   { margin:           auto;
                   width:            650px; }
    .top-bar     { border-bottom:    6px solid blue;
                   background-color: #800000 !important; }
    .common-font { font-family:      Georgia, Garamond, 'Times New Roman', serif; }
    .navbar-light .navbar-brand       { color:       white;  }
    .navbar-light .navbar-brand:hover { color:       yellow; }
    .navbar-light .navbar-brand:focus { color:       khaki;  }
    .navbar-light .navbar-brand       { font-family: Georgia, Garamond, 'Times New Roman', serif; }
    .nav-link                         { font-family: Georgia, Garamond, 'Times New Roman', serif; }
  46. In the Solution Explorer, expand Pages
  47. In the Solution Explorer, under Pages, expand Shared
  48. In the Solution Explorer, under Pages and under Shared, double-click _Layout.cshtml
  49. Change the document as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - Oblique Triangles</title>
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/Geometry.css" asp-append-version="true" />
    </head>
    <body>
        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 top-bar">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-page="/Index">Oblique Triangles</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/AAS">AAS</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/SAS">SAS</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/ASA">ASA</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link text-white" asp-area="" asp-page="/SSS">SSS</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>
        <div class="container">
            <main role="main" class="pb-3">
                @RenderBody()
            </main>
        </div>
    
        <footer class="border-top footer text-muted">
            <div class="container">
                <p class="text-center common-font">&copy; 2022 - Oblique Triangles - <a asp-area="" asp-page="/Privacy">Privacy</a></p>
            </div>
        </footer>
    
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @await RenderSectionAsync("Scripts", required: false)
    </body>
    </html>
  50. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  51. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  52. Change the file Name to AAS
  53. Click Add

Practical LearningPractical Learning: Introducing Data Writing

  1. Change the AAS.cshtml document as follows:
    @page
    @model ObliqueTriangles3.Pages.AASModel
    @{
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                angle1 = double.Parse(Request.Form["txtAASAngle1"]);
            }
            catch (FormatException)
            {
                System.Console.WriteLine("You must type a value for the lower left angle of the AAS shape.");
            }
    
            try
            {
                  angle2 = double.Parse(Request.Form["txtAASAngle2"]);
            }
            catch (FormatException)
            {
                System.Console.WriteLine("You must type a value for the lower right angle of the AAS shape.");
            }
    
            try
            {
                side1 = double.Parse(Request.Form["txtAASSide1"]);
            }
            catch (FormatException)
            {
                System.Console.WriteLine("You must type a value for the right side of the AAS shape.");
            }
    
            // Here, we use the law of sines
            angle3 = 180 - (angle1 + angle2);
            side2 = side1 * Math.Sin(angle2 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
            side3 = side1 * Math.Sin(angle3 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
    
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Oblique Triangles - AAS Shape");
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Known Values: 2 Angles and 1 Side");
            System.Console.WriteLine("----------------------------------------------------------------------");
            System.Console.WriteLine("Known Angle   1:  " + angle1.ToString());
            System.Console.WriteLine("Known Angle   2:  " + angle2.ToString());
            System.Console.WriteLine("Known Side    1:  " + side1.ToString());
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Unknown Values: 1 Angle and 2 Sides");
            System.Console.WriteLine("----------------------------------------------------------------------");
            System.Console.WriteLine("Unknown Angle 3:  " + angle3.ToString());
            System.Console.WriteLine("Unknown Side  2:  " + side2.ToString());
            System.Console.WriteLine("Unknown Side  3:  " + side3.ToString());
            System.Console.WriteLine("======================================================================");
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - AAS Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Angles and 1 Side</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/aas.png" width="258" height="159" alt="Oblique Triangles - AAS Shape">
                  </td>
                  <td style="width: 150px">Known Angle 1:</td>
                  <td>@Html.TextBox("txtAASAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 2:</td>
                  <td>@Html.TextBox("txtAASAngle2", @angle2, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 1:</td>
                  <td>@Html.TextBox("txtAASSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 1 Angle and 2 Sides</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 3:</td>
              <td>@Html.TextBox("txtAASAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 2:</td>
              <td>@Html.TextBox("txtAASSide2", @side2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtAASSide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    </div>
  2. To execute, on the main menu, click Debug -> Start Without Debugging
  3. Click the AAS link

    Oblique Triangles - AAS

  4. Click the Known Angle 1 text box and type 38
  5. Click the Known Angle 2 text box and type 21
  6. Click the Known Side 1 text box and type 24

    Oblique Triangles - AAS

  7. Display the Hosting window and the browser side by side
  8. Click the Find Unknown Values button:

    Oblique Triangles - AAS - The Hosting Window

    Oblique Triangles - AAS

  9. Return to your programming environment
  10. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  11. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  12. Change the file Name to SAS
  13. Click Add

Practical LearningPractical Learning: Using a Namespace

  1. Change the document as follows:
    @page
    @model ObliqueTriangles3.Pages.SASModel
    @using System
    @{
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                side1 = double.Parse(Request.Form["txtSASSide1"]);
            }
            catch (FormatException)
            {
                Console.WriteLine("You must type a value for one of the known sides of the SAS shape.");
            }
    
            try
            {
                  angle1 = double.Parse(Request.Form["txtSASAngle1"]);
            }
            catch (FormatException)
            {
                Console.WriteLine("You must type a value for the known angle of the SAS shape.");
            }
    
            try
            {
                side2 = double.Parse(Request.Form["txtSASSide2"]);
            }
            catch (FormatException)
            {
                Console.WriteLine("You must type a value for the other known side of the SAS shape.");
            }
    
            // Here, we use the law of cosines
            side3 = Math.Sqrt((side1 * side1) +
                              (side2 * side2) -
                              (2 * side1 * side2 * Math.Cos(angle1 * Math.PI / 180)));
            angle2 = Math.Acos(((side3 * side3) +
                               (side2 * side2) -
                               (side1 * side1)) /
                               (2 * side3 * side2)) * 180 / Math.PI;
            angle3 = 180 - (angle1 + angle2);
    
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Oblique Triangles - SAS Shape");
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Known Values: 2 Sides and 1 Angle");
            System.Console.WriteLine("----------------------------------------------------------------------");
            System.Console.WriteLine("Known Side    1:  " + side1.ToString());
            System.Console.WriteLine("Known Angle   1:  " + angle1.ToString());
            System.Console.WriteLine("Known Side    2:  " + side2.ToString());
            System.Console.WriteLine("======================================================================");
            System.Console.WriteLine("Unknown Values: 1 Side and 2 Angles");
            System.Console.WriteLine("----------------------------------------------------------------------");
            System.Console.WriteLine("Unknown Angle 2:  " + angle2.ToString());
            System.Console.WriteLine("Unknown Side  3:  " + side3.ToString());
            System.Console.WriteLine("Unknown Angle 3:  " + angle3.ToString());
            System.Console.WriteLine("======================================================================");
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - SAS  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Sides and 1 Angle</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/sas.png" width="260" height="138" alt="Oblique Triangles - SAS Shape">
                  </td>
                  <td style="width: 150px">Known Side 1:</td>
                  <td>@Html.TextBox("txtSASSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 1:</td>
                  <td>@Html.TextBox("txtSASAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 2:</td>
                  <td>@Html.TextBox("txtSASSide2", @side2, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 1 Side and 2 Angles</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 2:</td>
              <td>@Html.TextBox("txtSASAngle2", @angle2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtSASSide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtSASAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    </div>
  2. To execute, on the main menu, click Debug -> Start Without Debugging
  3. If the browser presents a Resend button, click it, or refresh the browser
  4. Click the SAS link:

    Oblique Triangles - SAS

  5. Click the Known Side 1 text box and type 24
  6. Click the Known Angle 1 text box and type 34
  7. Click the Known Side 2 text box and type 36.5

    Oblique Triangles - SAS

  8. Click the Find Unknown Values button:

    Oblique Triangles - SSS - The Hosting Window

    Oblique Triangles - SAS

  9. Return to your programming environment

Practical LearningPractical Learning: Using a Namespace

  1. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  2. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  3. Change the file Name to ASA
  4. Click Add
  5. Change the document as follows:
    @page
    @model ObliqueTriangles3.Pages.ASAModel
    @using static System.Console
    @{
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                angle1 = double.Parse(Request.Form["txtASAAngle1"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for one of the known angles of the ASA shape.");
            }
    
            try
            {
                  side1 = double.Parse(Request.Form["txtASASide1"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for the side that is between the angles whose values are about the ASA shape.");
            }
    
            try
            {
                angle2 = double.Parse(Request.Form["txtASAAngle2"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for the other known angle of the ASA oblique triangle.");
            }
    
            // Here, we use the law of sines
            angle3 = 180 - (angle1 + angle2);
            side2 = side1 * Math.Sin(angle2 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
            side3 = side1 * Math.Sin(angle3 * Math.PI / 180) / Math.Sin(angle1 * Math.PI / 180);
    
            WriteLine("======================================================================");
            WriteLine("Oblique Triangles - ASS Shape");
            WriteLine("======================================================================");
            WriteLine("Known Values: 2 Angles and 1 Side joining them");
            WriteLine("----------------------------------------------------------------------");
            WriteLine("Known Angle   1:  " + angle1.ToString());
            WriteLine("Known Side    1:  " + side1.ToString());
            WriteLine("Known Angle   2:  " + angle2.ToString());
            WriteLine("======================================================================");
            WriteLine("Unknown Values: 2 Sides and 1 Angle between them");
            WriteLine("----------------------------------------------------------------------");
            WriteLine("Unknown Side  2:  " + side2.ToString());
            WriteLine("Unknown Angle 3:  " + angle3.ToString());
            WriteLine("Unknown Side  3:  " + side3.ToString());
            WriteLine("======================================================================");
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - ASA  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: 2 Angles and 1 Side joining them</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/asa.png" width="260" height="138" alt="Oblique Triangles - SAS Shape">
                  </td>
                  <td style="width: 150px">Known Angle 1:</td>
                  <td>@Html.TextBox("txtASAAngle1", @angle1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 1:</td>
                  <td>@Html.TextBox("txtASASide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Angle 2:</td>
                  <td>@Html.TextBox("txtASAAngle2", @angle2, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: 2 Sides and 1 Angle between them</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Side 2:</td>
              <td>@Html.TextBox("txtASASide2", @side2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtASAAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Side 3:</td>
              <td>@Html.TextBox("txtASASide3", @side3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    </div>
  6. In the Solution Explorer, right-click Pages -> Add -> Razor Page...
  7. In the Add New Sacffolded Item dialox box, make sure Razor Page - Empty is selected.
    Click Add
  8. Change the file Name to SSS
  9. Click Add
  10. Change the document as follows:
    @page
    @model ObliqueTriangles3.Pages.SSSModel
    @using static System.Console
    @{
        double side1 = 0.00, side2 = 0.00, side3 = 0.00;
        double angle1 = 0.00, angle2 = 0.00, angle3 = 0.00;
    
        if (Request.HasFormContentType)
        {
            try
            {
                side1 = double.Parse(Request.Form["txtSSSSide1"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for one of the known sides of the SSS shape.");
            }
    
            try
            {
                  side2 = double.Parse(Request.Form["txtSSSSide2"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for another side of the SSS triangle.");
            }
    
            try
            {
                side3 = double.Parse(Request.Form["txtSSSSide3"]);
            }
            catch (FormatException)
            {
                WriteLine("You must type a value for the remaining known side of the SSS oblique triangle.");
            }
    
            // Here, we use the law of cosines
            angle1 = Math.Acos(((side3 * side3) +
                                (side2 * side2) -
                                (side1 * side1)) /
                                (2 * side3 * side2)) * 180 / Math.PI;
                
            angle2 = Math.Acos(((side3 * side3) +
                                (side1 * side1) -
                                (side2 * side2)) /
                                (2 * side3 * side1)) * 180 / Math.PI;
          
            angle3 = 180 - (angle1 + angle2);
    
            WriteLine("======================================================================");
            WriteLine("Oblique Triangles - SSS Shape");
            WriteLine("======================================================================");
            WriteLine("Known Values: All 3 Sides");
            WriteLine("----------------------------------------------------------------------");
            WriteLine("Known Side    1:  " + side1.ToString());
            WriteLine("Known Side    2:  " + side2.ToString());
            WriteLine("Known Side    3:  " + side3.ToString());
            WriteLine("======================================================================");
            WriteLine("Unknown Values: All 3 Angles");
            WriteLine("----------------------------------------------------------------------");
            WriteLine("Unknown Angle 1:  " + angle1.ToString());
            WriteLine("Unknown Angle 2:  " + angle2.ToString());
            WriteLine("Unknown Angle 3:  " + angle3.ToString());
            WriteLine("======================================================================");
        }
    }
    
    <div class="delimiter common-font">
        <h2 class="text-center bold">Oblique Triangles - SSS  Shape</h2>
        <hr />
        <h5 class="text-right">Known Values: All 3 Sides</h5>
        <hr />
       <form name="frmGeometry" method="post">
          <table>
              <tr>
                  <td style="width: 300px" rowspan="3">
                      <img src="~/images/sss.png" width="259" height="137" alt="Oblique Triangles - SSS Shape">
                  </td>
                  <td style="width: 150px">Known Side 1:</td>
                  <td>@Html.TextBox("txtSSSSide1", @side1, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 2:</td>
                  <td>@Html.TextBox("txtSSSSide2", @side2, new { @class = "form-control text-right" })</td>
              </tr>
              <tr>
                  <td>Known Side 3:</td>
                  <td>@Html.TextBox("txtSSSSide3", @side3, new { @class = "form-control text-right" })</td>
              </tr>
          </table>
          
          <hr />
                  
          <table>
              <tr>
                  <td style="width: 350px">&nbsp;</td>
                  <td style="text-align: center"><input type="submit" name="btnSubmit" value="Find Unknown Values" /></td>
              </tr>
          </table>
      </form>
    
      <hr />
      
      <h5 class="text-right">Unknown Values: All 3 Angles</h5>
      
      <hr />
      
      <table>
          <tr>
              <td style="width: 300px">&nbsp;</td>
              <td style="width: 150px">Unknown Angle 1:</td>
              <td>@Html.TextBox("txtSSSAngle1", @angle1, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 2:</td>
              <td>@Html.TextBox("txtSSSAngle2", @angle2, new { @class = "form-control text-right" })</td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>Unknown Angle 3:</td>
              <td>@Html.TextBox("txtSSSAngle3", @angle3, new { @class = "form-control text-right" })</td>
          </tr>
      </table>
    </div>
  11. To execute the application to test it, on the main menu, click Debug -> Start Without Debugging
  12. Click the ASA link:

    Oblique Triangles - ASA

  13. Click the Known Angle 1 text box and type 131
  14. Click the Known Angle 2 text box and type 10
  15. Click the Known Side 1 text box and type 23

    Oblique Triangles - ASA

  16. Click the Find Unknown Values button:

    Oblique Triangles - SSS - The Hosting Window

    Oblique Triangles - ASA

  17. Click the SSS link

    Oblique Triangles - SSS

  18. Click the Known Side 1 text box and type 2.8
  19. Click the Known Side 2 text box and type 4.7
  20. Click the Known Side 3 text box and type 3.5

    Oblique Triangles - SSS

  21. Click the Find Known Values

    Oblique Triangles - SSS - The Hosting Window

    Oblique Triangles - SSS

  22. Close the window and return to your programming environment

Practical LearningPractical Learning: Ending the Lesson


Previous Copyright © 2001-2023, C# Key Saturday 17 December 2022 Next