Hello, can someone tell me how to solve this?
Define a Person class with 3 fields: Name, Age and DNI. Write an algorithm that allow the user to enter in a console a series of data of the form "NameDocumentAge". Once the entry of data, the program should print in the console a listing the list with the form: No.) Name (Age) DNI.
Example:
Juan Perez (40) 2098745
José García (41) 1965412
a) Using a People arrangement. Before starting loading, the user must enter by console the number of people who will load.
b) Using a arraylist. In this case the user should not enter the amount of people that will be loaded, simply the input process ends with a string empty.
This is what I do:
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace borrador
{
class Program
{
static void Main(string[] args)
{
Console.Write("Ingrese la cantidad de personas que se van a ingresar:");
int x = int.Parse(Console.ReadLine());
string [] personas = new string[x];
Console.WriteLine("Ingrese sus datos con el siguiente formato (Nombre Edad DNI): ");
string datos = Console.ReadLine();
int contador = 0;
while (contador <x)
{
personas[contador] = datos;
Console.WriteLine("siguiente Nombre Edad DNI:");
datos = Console.ReadLine();
contador += 1;
}
Persona programa = new Persona(personas);
Console.ReadLine();
}
}
class Persona
{
public string nombre, edad, dni;
public Persona(string[] datos)
{
for (int i = 0; i < datos.Length; i++)
{
string s=datos[i].Split(" ");
this.nombre=datos(0);
this.edad=datos(1);
this.dni=datos(2);
Console.WriteLine(nombre,edad,dni);
}
}
}
}