I am attempting to make an employee class and falling short somewhere. This shouls include three things... first name as sting, last name as string, and monthly salary as integer. its to have a constructor that initializes the three variables. the property for the monthly salary hould ensure that its value remains positive, if an attempt is made to assign a negative value, throw an excption. this should also show the capabilities of the class employee. im to create tw employee objects and display each objects yearly salary. then give them both a 10% raise and display eah emloyees yearly salary again.
this is what i have. it is taking the inputs, but its not calculating anything nor is it outputting anything. someone please help?
Sub Main()
Dim firstName As String
Dim lastName As String
Dim monthlySalary As Integer
Console.WriteLine("Enter Employee 1's First Name:") 'prompts user to enter employee 1's first name
firstName =
Console.ReadLine() 'gets employee 1's first name from user
Console.WriteLine("Enter Employee 1's Last Name:") 'prompts user to enter employee 1's last name
lastName =
Console.ReadLine() 'gets employee 1's last name from user
Console.WriteLine("Enter Employee 1's Monthly Salary:") 'prompts user to enter employee 1's monthly salary
monthlySalary =
Console.ReadLine() 'gets employee 1's monthly salary from user
Console.WriteLine("Enter Employee 2's First Name:") 'prompts user to enter employee 2's first name
firstName =
Console.ReadLine() 'gets employee 2's first name from user
Console.WriteLine("Enter Employee 2's Last Name:") 'prompts user to enter employee 2's last name
lastName =
Console.ReadLine()
Console.WriteLine("Enter Employee 2's Monthly Salary:")
monthlySalary =
Console.ReadLine()
End Sub
Public Class Employee
Private firstName As String ' employee first name
Private lastName As String ' employee last name
Private employee1MonthlySalary As Integer = 5000 ' employee 1 monthly salary
Private employee2MonthlySalary As Integer = 4000 ' employee 2 monthly salary
Public Sub New(ByVal first As String, ByVal last As String)
firstName = first
lastName = last
End Sub
Public ReadOnly Property First() As String
Get
Return firstName
End Get
End Property
Public ReadOnly Property Last() As String
Get
Return lastName
End Get
End Property
Public Function Employee()
Dim salary1 As Integer ' Employee 1 Yearly Salary calculation
Dim salary2 As Integer ' Employee 2 Yearly Salary calculation
Dim raise1Salary As Integer ' Employee 1 Yearly Salary with 10% raise
Dim raise2Salary As Integer ' Employee 2 Yearly Salary with 10% raise
salary1 = employee1MonthlySalary * 12
salary2 = employee2MonthlySalary * 12
raise1Salary =
CInt(employee1MonthlySalary * 1.1)
raise2Salary =
CInt(employee2MonthlySalary * 1.1)
If employee1MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
Console.WriteLine("Employee 1's salary amount must be greater than zero.", "Out of Range")
End If
If employee2MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
Console.WriteLine("Employee 2's salary amount must be greater than zero.", "Out of Range")
End If
Dim employee1 As New Employee("John", "Doe")
Console.WriteLine("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & salary1 & vbCrLf)
Dim employee2 As New Employee("Jane", "Doe")
Console.WriteLine("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & salary2 & vbCrLf)
Console.WriteLine(vbCrLf & "Yearly salary adjusted for 10% increase" & vbCrLf)
Console.WriteLine("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & raise1Salary & vbCrLf)
Console.WriteLine("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & raise2Salary & vbCrLf)
End Function
End Class
End
Module
this is what i have. it is taking the inputs, but its not calculating anything nor is it outputting anything. someone please help?
Sub Main()
Dim firstName As String
Dim lastName As String
Dim monthlySalary As Integer
Console.WriteLine("Enter Employee 1's First Name:") 'prompts user to enter employee 1's first name
firstName =
Console.ReadLine() 'gets employee 1's first name from user
Console.WriteLine("Enter Employee 1's Last Name:") 'prompts user to enter employee 1's last name
lastName =
Console.ReadLine() 'gets employee 1's last name from user
Console.WriteLine("Enter Employee 1's Monthly Salary:") 'prompts user to enter employee 1's monthly salary
monthlySalary =
Console.ReadLine() 'gets employee 1's monthly salary from user
Console.WriteLine("Enter Employee 2's First Name:") 'prompts user to enter employee 2's first name
firstName =
Console.ReadLine() 'gets employee 2's first name from user
Console.WriteLine("Enter Employee 2's Last Name:") 'prompts user to enter employee 2's last name
lastName =
Console.ReadLine()
Console.WriteLine("Enter Employee 2's Monthly Salary:")
monthlySalary =
Console.ReadLine()
End Sub
Public Class Employee
Private firstName As String ' employee first name
Private lastName As String ' employee last name
Private employee1MonthlySalary As Integer = 5000 ' employee 1 monthly salary
Private employee2MonthlySalary As Integer = 4000 ' employee 2 monthly salary
Public Sub New(ByVal first As String, ByVal last As String)
firstName = first
lastName = last
End Sub
Public ReadOnly Property First() As String
Get
Return firstName
End Get
End Property
Public ReadOnly Property Last() As String
Get
Return lastName
End Get
End Property
Public Function Employee()
Dim salary1 As Integer ' Employee 1 Yearly Salary calculation
Dim salary2 As Integer ' Employee 2 Yearly Salary calculation
Dim raise1Salary As Integer ' Employee 1 Yearly Salary with 10% raise
Dim raise2Salary As Integer ' Employee 2 Yearly Salary with 10% raise
salary1 = employee1MonthlySalary * 12
salary2 = employee2MonthlySalary * 12
raise1Salary =
CInt(employee1MonthlySalary * 1.1)
raise2Salary =
CInt(employee2MonthlySalary * 1.1)
If employee1MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
Console.WriteLine("Employee 1's salary amount must be greater than zero.", "Out of Range")
End If
If employee2MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
Console.WriteLine("Employee 2's salary amount must be greater than zero.", "Out of Range")
End If
Dim employee1 As New Employee("John", "Doe")
Console.WriteLine("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & salary1 & vbCrLf)
Dim employee2 As New Employee("Jane", "Doe")
Console.WriteLine("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & salary2 & vbCrLf)
Console.WriteLine(vbCrLf & "Yearly salary adjusted for 10% increase" & vbCrLf)
Console.WriteLine("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & raise1Salary & vbCrLf)
Console.WriteLine("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & raise2Salary & vbCrLf)
End Function
End Class
End
Module