Staticity
Staticity
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 ======================
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 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>
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:
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 Learning: Introducing the Console
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; }
<!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">© 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 Learning: Clearing the Console
@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> </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"> </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> </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> </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"> </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>
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 Learning: Introducing Math Functions
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; }
<!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">© 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 Learning: Getting the Power of a Number
@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> </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"> </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> </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> </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"> </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>
@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> </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"> </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> </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> </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"> </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>
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; }
<!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">© 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>
Practical Learning: Finding the Square Root of a Number
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;
}
}
}
@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> </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>
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);
}
}
@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> </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>
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; } } }
@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> </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>
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; } }
@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> </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>
Practical Learning: Introducing Trigonometry
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; }
<!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">© 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 Learning: Introducing the Sine Value
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 3:</td> <td>@Html.TextBox("txtAASAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 2:</td> <td>@Html.TextBox("txtAASSide2", @side2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </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>
Practical Learning: Introducing Cosines
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 2:</td> <td>@Html.TextBox("txtSASAngle2", @angle2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 3:</td> <td>@Html.TextBox("txtSASSide3", @side3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </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>
@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"> </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"> </td> <td style="width: 150px">Unknown Side 2:</td> <td>@Html.TextBox("txtASASide2", @side2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 3:</td> <td>@Html.TextBox("txtASAAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </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>
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 1:</td> <td>@Html.TextBox("txtSSSAngle1", @angle1, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 2:</td> <td>@Html.TextBox("txtSSSAngle2", @angle2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </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>
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; }
<!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">© 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 Learning: Introducing Data Writing
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 3:</td> <td>@Html.TextBox("txtAASAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 2:</td> <td>@Html.TextBox("txtAASSide2", @side2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 3:</td> <td>@Html.TextBox("txtAASSide3", @side3, new { @class = "form-control text-right" })</td> </tr> </table> </div>
Practical Learning: Using a Namespace
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 2:</td> <td>@Html.TextBox("txtSASAngle2", @angle2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 3:</td> <td>@Html.TextBox("txtSASSide3", @side3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 3:</td> <td>@Html.TextBox("txtSASAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> </table> </div>
Practical Learning: Using a Namespace
@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"> </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"> </td> <td style="width: 150px">Unknown Side 2:</td> <td>@Html.TextBox("txtASASide2", @side2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 3:</td> <td>@Html.TextBox("txtASAAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Side 3:</td> <td>@Html.TextBox("txtASASide3", @side3, new { @class = "form-control text-right" })</td> </tr> </table> </div>
@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"> </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"> </td> <td style="width: 150px">Unknown Angle 1:</td> <td>@Html.TextBox("txtSSSAngle1", @angle1, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 2:</td> <td>@Html.TextBox("txtSSSAngle2", @angle2, new { @class = "form-control text-right" })</td> </tr> <tr> <td> </td> <td>Unknown Angle 3:</td> <td>@Html.TextBox("txtSSSAngle3", @angle3, new { @class = "form-control text-right" })</td> </tr> </table> </div>
Practical Learning: Ending the Lesson
|
|||
Previous | Copyright © 2001-2023, C# Key | Saturday 17 December 2022 | Next |
|