I have this code, to which I am asked to add two more variables to the Mycar class belonging to the owner. I already did that part, everything like OwnerName and City, I did. What they ask me is to add a method to the class that allows it to display the owner's data
namespace tarea1labprog4
{
class Program
{
static void Main(string[] args)
{
String model;
String color;
int year;
String NombrePropietario;
String Ciudad;
Console.WriteLine("Digite el modelo : ");
model = Console.ReadLine();
Console.WriteLine("Digite el color: ");
color = Console.ReadLine();
Console.WriteLine("Digite el año : ");
year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Digite el nombre del propietario: ");
NombrePropietario= Console.ReadLine();
Console.WriteLine("Digite ciudad: ");
Ciudad= Console.ReadLine();
Mycarro Carrito = new Mycarro (model, color, year, NombrePropietario, Ciudad);
Carrito.Salida();
Console.ReadKey();
}
}
public class Mycarro
{
String model;
String color;
int year;
String NombrePropietario;
String Ciudad;
public Mycarro( String model, String color, int year , String NombrePropietario , String Ciudad)
{
this.model = model;
this.color = color;
this.year = year;
this.Nombre.Propietario = NombrePropietario<
this.Ciudad = Ciudad;
}
public void Salida()
{
Console.WriteLine("Datos Requeridos: \n " + model + "" +"\n " + color + " " +"\n " + year + "" + "\n" + NombrePropietario + "" + "\n" + Ciudad );
}
}
}
Create a method in the class
Mycarro
calledgetPropietario()
by calling the method
getPropietario()
you will be able to obtain its data.If what you want is just to display the owner's data, it would be something like this.