2016-10-30 1 views
0

Also ich versuche, diese Methode von GetValidString() zu bekommen. Sobald ich diese Methode fertig habe, sollte der Rest des Codes einfach sein.Methoden und Loops. Way über meinen Kopf

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"; 
    } 
} 
} 

Es gelten die gleichen Konflikte. Ich denke für die GetValidString() Methode, sollte ich eine while-Schleife verwenden, um sicherzustellen, dass es durch alles durchlaufen kann.

** Ich bin gezwungen, ein 2D-Array zu verwenden, also muss ich es verwenden.

+2

Sie müssen genauer sein: Was * genau * haben Sie Probleme mit? Wir können nicht einfach den ganzen Code anschauen und herausfinden, was falsch ist. Erstelle ein [MCVE]. –

+0

"Ich habe es geschafft, die Methoden zu rufen, aber ich kann nicht einmal auf die Methoden zurückgreifen" - hat dieser Satz keinen kleinen inneren Widerspruch ..? – obe

+0

mein Denkprozess, wenn ich Fragen wie diese anschaue: 'if (this.QuestionIsHomeworkRelated) return;' – Benj

Antwort

1

Es gibt viel zu viel Code hier, um für Sie zu schreiben. Ich werde jedoch Vorschläge machen.

  1. Ein Mitarbeiter der Klasse mit Eigenschaften für fName, lName, Titel, würde Abzeichen machen dies einfacher als ein Array von Mitarbeiter 2D-Arrays
  2. erstellen mit =>Employee[] Employees = new Employee[20]
  3. Ihre Methoden würde dann wiederum in einfache Schleifen