Advertisement
joemch

AbstractOOP

Sep 22nd, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.56 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Sub Main()
  4.     'instatiate a customer name the object BigSpender..
  5.     'instatiate an employee name the object SalesMan
  6.     ' try to instatiate a person
  7.  
  8.     'Make  sure you do all the tasks below before doing this.
  9.     ' assign fictional details to your Salesman
  10.  
  11.     Console.ReadLine()
  12.     End Sub
  13.  
  14. End Module
  15. MustInherit Class Person  'and abstract class
  16.   Protected Name As String
  17.   Protected Address As String
  18.   Protected City As String
  19.   Protected County As String
  20.   Protected PostCode As String
  21.  
  22.   MustOverride Sub PrintName()
  23.   ' add abstract methods to set the values for each property
  24.  
  25.   Sub Print() ' this isn't an abstarct method but access the abstact method which is overridden in the sub(now base) classes
  26.     PrintName()
  27.     Console.WriteLine(Address)
  28.     Console.WriteLine(City & ", " & County & " " & PostCode)
  29.   End Sub
  30. End Class
  31.  
  32. Class Customer
  33.   Inherits Person
  34.  
  35.   Overrides Sub PrintName()
  36.     Console.Write("Customer ")
  37.     Console.WriteLine(Name)
  38.   End Sub
  39.  
  40.   'create setter and getter methods for each of the inherited properties
  41.  
  42.   Private CustomerID As Integer
  43. End Class
  44.  
  45. Class Employee
  46.   Inherits Person
  47.  
  48.   Overrides Sub PrintName()
  49.     Console.Write("Employee ")
  50.     Console.WriteLine(Name)
  51.   End Sub
  52.   ' create a method that calculates salary using the formula 10000+(200*yearsService)+(0.05*sales)  .... you will need to either hards code or input sales and years service for teating
  53.  
  54.   Private Salary As Integer
  55.   Private Sales As Integer
  56.   Private YearsService As Integer
  57.  
  58. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement