daily pastebin goal
88%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim io As New InputOutput(Val(TextBox1.Text))
  5.  
  6.         Dim num = New ParseDecimalToRoman()
  7.         num.Interpret(io)
  8.  
  9.         TextBox2.Text = io.Output
  10.     End Sub
  11. End Class
  12.  
  13. Public MustInherit Class Terminals
  14.  
  15.     Inherits RomanExpression
  16.  
  17.     Public Overrides Sub Interpret(ByVal value As InputOutput)
  18.  
  19.         While value.Input - 9 * Multiply() >= 0
  20.  
  21.             value.Output += NineStrings()
  22.  
  23.             value.Input -= 9 * Multiply()
  24.  
  25.         End While
  26.  
  27.         While value.Input - 5 * Multiply() >= 0
  28.  
  29.             value.Output += FiveStrings()
  30.  
  31.             value.Input -= 5 * Multiply()
  32.  
  33.         End While
  34.  
  35.         While value.Input - 4 * Multiply() >= 0
  36.  
  37.             value.Output += FourStrings()
  38.  
  39.             value.Input -= 4 * Multiply()
  40.  
  41.         End While
  42.  
  43.         While value.Input - Multiply() >= 0
  44.  
  45.             value.Output += OneStrings()
  46.  
  47.             value.Input -= Multiply()
  48.  
  49.         End While
  50.  
  51.     End Sub
  52.  
  53.     Public MustOverride Function OneStrings() As String
  54.     Public MustOverride Function FourStrings() As String
  55.     Public MustOverride Function FiveStrings() As String
  56.     Public MustOverride Function NineStrings() As String
  57.     Public MustOverride Function Multiply() As Integer
  58. End Class
  59.  
  60. Public Class InputOutput
  61.  
  62.     Private intIn As Integer
  63.     Private strOut As String
  64.  
  65.     Public Sub New(ByVal intInput As Integer)
  66.  
  67.         Me.intIn = intInput
  68.  
  69.     End Sub
  70.  
  71.     Public Property Input() As Integer
  72.  
  73.         Get
  74.  
  75.             Return intIn
  76.  
  77.         End Get
  78.  
  79.         Set(ByVal value As Integer)
  80.  
  81.             intIn = value
  82.  
  83.         End Set
  84.  
  85.     End Property
  86.  
  87.     Public Property Output() As String
  88.  
  89.         Get
  90.  
  91.             Return strOut
  92.  
  93.         End Get
  94.  
  95.         Set(ByVal value As String)
  96.  
  97.             strOut = value
  98.  
  99.         End Set
  100.  
  101.     End Property
  102.  
  103. End Class
  104.  
  105. Public MustInherit Class RomanExpression
  106.  
  107.     Public MustOverride Sub Interpret(ByVal value As InputOutput)
  108.  
  109. End Class
  110.  
  111. Class Ones
  112.  
  113.     Inherits Terminals
  114.  
  115.     Public Overrides Function OneStrings() As String
  116.  
  117.         Return "I"
  118.  
  119.     End Function
  120.  
  121.     Public Overrides Function FourStrings() As String
  122.  
  123.         Return "IV"
  124.  
  125.     End Function
  126.  
  127.     Public Overrides Function FiveStrings() As String
  128.  
  129.         Return "V"
  130.  
  131.     End Function
  132.  
  133.     Public Overrides Function NineStrings() As String
  134.  
  135.         Return "IX"
  136.  
  137.     End Function
  138.  
  139.     Public Overrides Function Multiply() As Integer
  140.  
  141.         Return 1
  142.  
  143.     End Function
  144.  
  145. End Class
  146.  
  147. Class Tens
  148.  
  149.     Inherits Terminals
  150.  
  151.     Public Overrides Function OneStrings() As String
  152.  
  153.         Return "X"
  154.  
  155.     End Function
  156.  
  157.     Public Overrides Function FourStrings() As String
  158.  
  159.         Return "XL"
  160.  
  161.     End Function
  162.  
  163.     Public Overrides Function FiveStrings() As String
  164.  
  165.         Return "L"
  166.  
  167.     End Function
  168.  
  169.     Public Overrides Function NineStrings() As String
  170.  
  171.         Return "XC"
  172.  
  173.     End Function
  174.  
  175.     Public Overrides Function Multiply() As Integer
  176.  
  177.         Return 10
  178.  
  179.     End Function
  180.  
  181. End Class
  182.  
  183. Class Hundreds
  184.  
  185.     Inherits Terminals
  186.  
  187.     Public Overrides Function OneStrings() As String
  188.  
  189.         Return "C"
  190.  
  191.     End Function
  192.  
  193.     Public Overrides Function FourStrings() As String
  194.  
  195.         Return "CD"
  196.  
  197.     End Function
  198.  
  199.     Public Overrides Function FiveStrings() As String
  200.  
  201.         Return "D"
  202.  
  203.     End Function
  204.  
  205.     Public Overrides Function NineStrings() As String
  206.  
  207.         Return "CM"
  208.  
  209.     End Function
  210.  
  211.     Public Overrides Function Multiply() As Integer
  212.  
  213.         Return 100
  214.  
  215.     End Function
  216.  
  217. End Class
  218.  
  219. Class Thousands
  220.  
  221.     Inherits Terminals
  222.  
  223.     Public Overrides Function OneStrings() As String
  224.  
  225.         Return "M"
  226.  
  227.     End Function
  228.  
  229.     Public Overrides Function FourStrings() As String
  230.  
  231.         Return "MV"
  232.  
  233.     End Function
  234.  
  235.     Public Overrides Function FiveStrings() As String
  236.  
  237.         Return "V"
  238.  
  239.     End Function
  240.  
  241.     Public Overrides Function NineStrings() As String
  242.  
  243.         Return "MX"
  244.  
  245.     End Function
  246.  
  247.     Public Overrides Function Multiply() As Integer
  248.  
  249.         Return 1000
  250.  
  251.     End Function
  252.  
  253. End Class
  254.  
  255. Class TenThousands
  256.  
  257.     Inherits Terminals
  258.  
  259.     Public Overrides Function OneStrings() As String
  260.  
  261.         Return "X|"
  262.  
  263.     End Function
  264.  
  265.     Public Overrides Function FourStrings() As String
  266.  
  267.         Return "XL|"
  268.  
  269.     End Function
  270.  
  271.     Public Overrides Function FiveStrings() As String
  272.  
  273.         Return "L|"
  274.  
  275.     End Function
  276.  
  277.     Public Overrides Function NineStrings() As String
  278.  
  279.         Return "XC|"
  280.  
  281.     End Function
  282.  
  283.     Public Overrides Function Multiply() As Integer
  284.  
  285.         Return 10000
  286.  
  287.     End Function
  288.  
  289. End Class
  290.  
  291. Class HundredThousands
  292.  
  293.     Inherits Terminals
  294.  
  295.     Public Overrides Function OneStrings() As String
  296.  
  297.         Return "C|"
  298.  
  299.     End Function
  300.  
  301.     Public Overrides Function FourStrings() As String
  302.  
  303.         Return "CD|"
  304.  
  305.     End Function
  306.  
  307.     Public Overrides Function FiveStrings() As String
  308.  
  309.         Return "D|"
  310.  
  311.     End Function
  312.  
  313.     Public Overrides Function NineStrings() As String
  314.  
  315.         Return "CM|"
  316.  
  317.     End Function
  318.  
  319.     Public Overrides Function Multiply() As Integer
  320.  
  321.         Return 100000
  322.  
  323.     End Function
  324.  
  325. End Class
  326.  
  327. Public Class ParseDecimalToRoman
  328.  
  329.     Inherits RomanExpression
  330.  
  331.     Private AllExpressions As New List(Of RomanExpression)() _
  332.        From { _
  333.        New HundredThousands(), _
  334.        New TenThousands(), _
  335.        New Thousands(), _
  336.        New Hundreds(), _
  337.        New Tens(), _
  338.        New Ones() _
  339.     }
  340.  
  341.     Public Overrides Sub Interpret(ByVal value As InputOutput)
  342.  
  343.         For Each reExp As RomanExpression In AllExpressions
  344.  
  345.             reExp.Interpret(value)
  346.  
  347.         Next
  348.  
  349.     End Sub
  350.  
  351. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top