We help IT Professionals succeed at work.

Array in a arraylist

74 Views
Last Modified: 2017-04-22
This is for homework and I'm not looking for a straight up answer, but I need clear help in the right direction.

I have an arraylist that contains several "employees" with name, id, pay, and then an array of hours worked each day of the week. I can print everything except the days of the week. I have looked at many msdn pages and various website, but I have not found how to handle this.
Comment
Watch Question

Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Hi John;

If you have a DateTime object for the hours worked then you can use the ToString method to display the name of the day the date represents something like this.
Dim dateName As String = DateTimeObj.ToString("XXX") '' returns the 3 character name for the day
Dim dateName As String = DateTimeObj.ToString("XXXX") '' For the complete name of the day

Open in new window

Note that the XXX or the XXXX is a alpha character. See this MSDN page for help to find out which character.
Custom Date and Time Format Strings
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
If Fernando's answer doesn't solve your problem, then please post HOW you are storing the employee data.  What kind of structure and/or variable types are you using here?

Author

Commented:
Here is my code:

Module Module1
    Public Class clsEmployee
        Public Property strName As String
        Public Property intID As Integer
        Public Property dblPayrate As Double
        '  Public Property arrHours(6) As Integer

        Public Sub New(ByVal Name As String, ByVal ID As Integer, ByVal Payrate As Double) ', ByVal Hours As Array)
            Me.strName = Name
            Me.intID = ID
            Me.dblPayrate = Payrate
            ' Me.arrHours = Hours
        End Sub

        Public Overrides Function toString() As String
            Return String.Format("{0} {1} {2} {3}", strName, intID, dblPayrate)
        End Function
    End Class

    Public Class ArrayListOfEmployees
        Implements IEnumerable

        Private arrEmployees As New ArrayList()

        Public Sub AddEmployee(ByRef AnEmployee As clsEmployee)
            arrEmployees.Add(AnEmployee)
        End Sub

        Public Sub ClearEmps()
            arrEmployees.Clear()
        End Sub

        Public ReadOnly Property count() As Integer
            Get
                Return arrEmployees.Count
            End Get
        End Property

        Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
            Return arrEmployees.GetEnumerator()
        End Function
    End Class

    Sub Main()
        Dim myEmps As New ArrayListOfEmployees
               Dim Hours(6) As Integer


        myEmps.AddEmployee(New clsEmployee("Sue", 103, 15.25, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Scott", 105, 15.0, {10, 10, 0, 10, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("Bill", 106, 12.0, {8, 8, 8, 8, 9, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Tina", 107, 16.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Ron", 109, 15.5, {0, 0, 9, 9, 9, 9, 9}))
        myEmps.AddEmployee(New clsEmployee("Barb", 110, 13.0, {0, 10, 0, 10, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("Cathy", 111, 14.5, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Al", 112, 15.0, {10, 10, 10, 10, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Dave", 133, 15.5, {0, 0, 8, 8, 8, 8, 8}))
        myEmps.AddEmployee(New clsEmployee("Haley", 134, 16.5, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Drew", 136, 12.25, {10, 10, 0, 0, 10, 10, 0}))
        myEmps.AddEmployee(New clsEmployee("John", 137, 13.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Mary", 138, 14.0, {8, 8, 8, 8, 8, 0, 0}))
        myEmps.AddEmployee(New clsEmployee("Ann", 139, 15.0, {0, 0, 0, 10, 10, 10, 10}))
        myEmps.AddEmployee(New clsEmployee("Chuck", 140, 15.0, {0, 8, 8, 8, 8, 8, 0}))

             
        For Each anEmp In myEmps
            Console.WriteLine(anEmp.ToString())
        Next

        Console.ReadLine()
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
The assignment wants me to place the {numbers} into an array and get the sum. And then print all of the employee info line by line
Ark
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the help, but I feel kinda dumb with it being that easy
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
@Ark please note that this is a school assignment and experts should not be posting complete code samples.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Hi John;

The original question as you stated, "I can print everything except the days of the week."', I ask you the following question in one of my last post, "How does the assignment you were given want you to determine the day of the week? Is the 7 element array the index of that array going to determine the day of the week? For example index 0 = Sunday, 1 = Monday, .... 6 = Saturday?", in order to help you please answer the question.
Ark
CERTIFIED EXPERT

Commented:
Hi Fernando! I don't send complete code for the "blank" questions on homework. But author shown [almost] complete code with small errors in data types so I just corrected them.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
@Ark, OK
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Both gave a solution.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.