Answer to Question #298183 in C# for Aaa

Question #298183

Create an application that will take 5 employees data and print the data.take a skill name and print all the employee who have skill

1
Expert's answer
2022-02-16T04:45:22-0500
using System;


public class Employee
{
    public string name;
    public int age;
    public string skill;
    
    public Employee(string name, int age, string skill)
    {
        this.name = name;
        this.age = age;
        this.skill = skill;
    }
    
    public void Print()
    {
        Console.WriteLine($"Name: {name}");
        Console.WriteLine($"Age: {age}");
        Console.WriteLine($"Skill: {skill}");
    }
}




public class HelloWorld
{
    public static void Main(string[] args)
    {
        Employee[] employees = new Employee[5];
        
        for(int i = 0; i < employees.Length; i++)
        {
            Console.WriteLine($"Number employee: {i + 1}");
            employees[i] = new Employee("", 0, "");
            Console.Write("Enter name: ");
            employees[i].name = Console.ReadLine();
            Console.Write("Enter age: ");
            employees[i].age = int.Parse(Console.ReadLine());
            Console.Write("Enter skill: ");
            employees[i].skill = Console.ReadLine();
        }
        
        for(int i = 0; i < employees.Length; i++)
        {
            Console.WriteLine($"Number employee: {i + 1}");
            employees[i].Print();
        }
        
        Console.Write("Enter skill employee: ");
        string nameSkill = Console.ReadLine();
        
        for(int i = 0; i < employees.Length; i++)
        {
            if(employees[i].skill == nameSkill)
            {
                Console.WriteLine($"Number employee: {i + 1}");
                employees[i].Print();
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS