Tommy Vidrio
Tommy Vidrio

Reputation: 33

Methods and Loops. Way over my head

So I'm trying to get this Method of GetValidString(). Once I get this method done, the rest of the code should be easy.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ReviewEchProject
{
class Program
{
    //Arrays that can be called upon anytime
    static string[,] employeeInfo = new string[20, 3];  //Used to contain First Name, Last Name, and Title
    static int[] badgeArray = new int[20];  //Used to contain badge number


 //Main method will be used to call upon the other methods
static void Main(string[] args)
    {
        Console.WriteLine("Welcome to the Employee Data Base. Please Type       a letter to accept the command.");
        Console.WriteLine();
        Console.WriteLine("A = Add Employee  E = Edit Employee  S= Search     Employee  X= Exit");
        string userInput = Console.ReadLine().ToUpper();
        switch (userInput)
        {
            case "A":
                AddEmployee();
                break;
            case "E":
                EditEmployee();
                break;
            case "S":
                SearchEmployee();
                break;
            case "X":
                break;
            default:
                Console.WriteLine("Sorry, Invalid Input. Program will now shut down.");
                break;
        }
        Console.WriteLine();
        Console.WriteLine("Have a nice day!");
        Console.ReadLine();
    }



    public static void SearchEmployee()
    {
        Console.WriteLine("I am in the SearchEmployee method");
    }


    public static void EditEmployee()
    {
        Console.WriteLine("I am in the EditEmployee method");
    }


    public static void AddEmployee()
    {
        for (int i = 0; i < badgeArray.Length; i = i + 1)
        {
            if (badgeArray[i] != 0)
            {
                Console.WriteLine("ERROR: Database is full.");
            }


            if (badgeArray[i] == 0)
            {
                int badge = GetEmployeeBadgeNumber();
                badgeArray[i] = badge;
               //Used to create badge number


               //Not sure if done correctly, but call upon three times to place names for each slot
                string firstName = GetValidString();
                employeeInfo[i, 0] = firstName;


                string lastName = GetValidString();
                employeeInfo[i, 1] = lastName;


                string titleName = GetValidString();
                employeeInfo[i, 2] = titleName;


                Console.WriteLine("Database upload ... ... Success.");
            }
        }
    }

    public static int GetEmployeeBadgeNumber()
    {
       //Needs to return an int that is at least 100 an no greater than 999. 
       //This method asks for the value from the user.  
       //Warn the user about this constraint, and stay in a loop until the user gets it right.
        return 100;
    }


    public static string GetValidString()
    {
       //loop that it stays in until the user enters a valid entry, and when the user does enter a valid entry, it should return the value the user enters 
      //ask the user to enter a value with a message that uses the passed in messageString
     //warn the user the input string must be must be at least 3 letters and less than 20. verify the length. if its not acceptable, write error message and loop again
        return "Test";
    }
}
}

Same conflicts apply. I'm thinking for the GetValidString() method, I should use a while loop to make sure that it can loop through everything.

**I am forced to use a 2D Array, so I have to use it.

Upvotes: 0

Views: 56

Answers (1)

Joe Hartzell
Joe Hartzell

Reputation: 357

There is far too much code here to write for you. I will however offer suggestions.

  1. An Employee Class with properties for fName, lName, title, badge would make this easier than using 2D arrays
  2. Create an Array of Employees => Employee[] Employees = new Employee[20]
  3. Your methods would then turn into simple loops

Upvotes: 1

Related Questions