<%@ page language="vb" runat="server" %>
<script runat="server">
Public Class ScientificCalculator : Inherits Calculator
Public Sub SquareRoot()
Dim root As Double
Dim current As Double = MyBase.CurrentValue
root = Math.Sqrt(current)
MyBase.Clear()
MyBase.Add(root)
End Sub
End Class
Public Class Calculator
Private _current As Double
Public ReadOnly Property CurrentValue As Double
Get
Return _current
End Get
End Property
Public Sub Add(addValue As Double)
_current += addValue
End Sub
Public Sub Subtract(addValue As Double)
_current -= addValue
End Sub
Public Sub Multiply(addValue As Double)
_current *= addValue
End Sub
Public Sub Divide(addValue As Double)
_current /= addValue
End Sub
Public Sub Clear()
_current = 0
End Sub
End Class
Sub Page_Load()
Dim MyCalc As New ScientificCalculator()
Response.Write("<b>Created a new ScientificCalculator object.</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.Add(23)
Response.Write("<br/><b>Added 23 - MyCalc.Add(23)</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.Subtract(7)
Response.Write("<br/><b>Subtracted 7 - MyCalc.Subtract(7)</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.Multiply(3)
Response.Write("<br/><b>Multiplied by 3 - MyCalc.Multiply(3)</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.Divide(4)
Response.Write("<br/><b>Divided by 4 - MyCalc.Divide(4)</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.SquareRoot()
Response.Write("<br/><b>Square root - MyCalc.SquareRoot()</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
MyCalc.Clear()
Response.Write("<br/><b>Cleared - MyCalc.Clear()</b><br/>")
Response.Write("Current Value = " & MyCalc.CurrentValue)
End Sub
</script>