Advertisement
nein_yards

solutions + demos

Jan 13th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. Class Str
  2. Private str As String
  3. Sub New(str As String)
  4. Me.str = str
  5. End Sub
  6. Sub setString(str As String)
  7. Me.str = str
  8. End Sub
  9. Sub printString()
  10. Console.WriteLine(str.ToUpper())
  11. End Sub
  12. End Class
  13.  
  14. Class Rectangle
  15. Private length As Decimal
  16. Private width As Decimal
  17. Sub New(length As Integer, width As Integer)
  18. Me.length = length
  19. Me.width = width
  20. End Sub
  21. Function getArea()
  22. Return length * width
  23. End Function
  24. End Class
  25.  
  26. Class Circle
  27. Private radius As Decimal
  28. Sub New(radius As Decimal)
  29. Me.radius = radius
  30. End Sub
  31. Function getArea()
  32. Return 3.14 * radius * radius
  33. End Function
  34. Function getCircumference()
  35. Return 2 * 3.14 * radius
  36. End Function
  37. End Class
  38.  
  39. Class Operation
  40. Private a As Integer
  41. Private b As Integer
  42. Sub New(a As Integer, b As Integer)
  43. Me.a = a
  44. Me.b = b
  45. End Sub
  46. Function power()
  47. Dim multTotal As Integer = 1
  48. For i = 1 To b
  49. multTotal *= a
  50. Next
  51. Return multTotal
  52. End Function
  53. End Class
  54.  
  55. Class Customer
  56. Private customerNumber As Integer
  57. Private customerName As String
  58. Private price, qty, discount, totalPrice, netPrice As Integer
  59. 'note, all currency in lowest denomination (eg cents)
  60. 'to prevent floating point rounding error
  61. Sub New(customerNumber As Integer, customerName As String)
  62. Me.customerNumber = customerNumber
  63. Me.customerName = customerName
  64. qty = 0
  65. price = 0
  66. discount = 0
  67. totalPrice = 0
  68. netPrice = 0
  69. End Sub
  70. Sub calDiscount()
  71. totalPrice = price * qty
  72. If totalPrice >= 50000 Then
  73. discount = totalPrice * 25 * 0.01
  74. ElseIf totalPrice >= 25000 Then
  75. discount = totalPrice * 15 * 0.01
  76. Else
  77. discount = totalPrice * 10 * 0.01
  78. End If
  79. netPrice = totalPrice - discount
  80. End Sub
  81. Sub input(price, qty)
  82. Me.price = price
  83. Me.qty = qty
  84. calDiscount()
  85. End Sub
  86. Sub show()
  87. Console.WriteLine("Customer number: " & customerNumber)
  88. Console.WriteLine("Customr name: " & customerName)
  89. Console.WriteLine("Total price: " & totalPrice)
  90. Console.WriteLine("Discount: " & discount)
  91. Console.WriteLine("Net price: " & netPrice)
  92. End Sub
  93. End Class
  94.  
  95. Sub Main()
  96. Dim name As Str = New Str("Taufiq")
  97. name.printString()
  98. Dim rectangle As Rectangle = New Rectangle(3, 4)
  99. Console.WriteLine(rectangle.getArea())
  100. Dim circle As Circle = New Circle(5)
  101. Console.WriteLine(circle.getArea)
  102. Console.WriteLine(circle.getCircumference)
  103. Dim func As Operation = New Operation(2, 3)
  104. Console.WriteLine(func.power())
  105. Dim customer As New Customer(12, "Taufiq")
  106. customer.input(200, 5)
  107. customer.show()
  108. Console.ReadLine()
  109. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement