2016-10-30 9 views
0

私はGetValidString()のこのメソッドを取得しようとしています。このメソッドを完成させたら、残りのコードを簡単にする必要があります。メソッドとループ。私の頭の上の道

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

同じ矛盾が適用されます。私はGetValidString()メソッドを考えているので、whileループを使用してすべてをループできることを確認する必要があります。

**私は、2次元アレイを使用するように強制していますので、私はそれを使用する必要があります。

+2

より具体的にする必要があります:*正確に*あなたは問題がありますか?私たちはこのコードをすべて見て、何が間違っているのか理解できません。 [MCVE]を作成します。 –

+0

"私は電話する方法を手に入れましたが、方法を呼び出すことさえできません" - この文は小さな内部矛盾を持っていませんか? – obe

+0

このような質問を見たときに私の思考プロセスは: '場合(this.QuestionIsHomeworkRelated)リターン;' – Benj

答えて

1

あなたのために書くにはあまりにも多くのコードがここにあります。私はしかし、提案を提供します。 fNameを、LNAME、タイトルのプロパティを持つ

  1. アン従業員クラス、バッジはあなたの方法は、単純なループに変わるだろう従業員の配列を作成します。=>Employee[] Employees = new Employee[20]
  2. 2D配列
  3. を使用するよりも、これは簡単になるだろう
関連する問題