Created
October 19, 2023 23:43
-
-
Save jpolivra/be1c40bd7a6f8a555580a44289718307 to your computer and use it in GitHub Desktop.
Make a class of a vehicle, the class must receive the name, brand, year and plate. The class should have a method responsable by showing the car information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace abstract_data_types; | |
class Program | |
{ | |
class Vehicle { | |
private string _Name; | |
public string Name | |
{ | |
get { return _Name; } | |
set { _Name = value; } | |
} | |
private string _Brand; | |
public string Brand | |
{ | |
get { return _Brand; } | |
set { _Brand = value; } | |
} | |
private string _Year; | |
public string Year | |
{ | |
get { return _Year; } | |
set { _Year = value; } | |
} | |
private string _Plate; | |
public string Plate | |
{ | |
get { return _Plate; } | |
set { _Plate = value; } | |
} | |
public void ReadData() { | |
Console.Clear(); | |
Console.Write("Input car name......:"); | |
_Name = Console.ReadLine(); | |
Console.Write("Input car brand.....:"); | |
_Brand = Console.ReadLine(); | |
Console.Write("Input car year.......:"); | |
_Year = Console.ReadLine(); | |
Console.Write("Input car plate......:"); | |
_Plate = Console.ReadLine(); | |
Console.ReadKey(); | |
} | |
public void ShowData() { | |
Console.WriteLine("Car Information:"); | |
Console.WriteLine($"Name: {_Name}"); | |
Console.WriteLine($"Brand: {_Brand}"); | |
Console.WriteLine($"Year: {_Year}"); | |
Console.WriteLine($"Plate: {_Plate}"); | |
Console.WriteLine(); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Vehicle[] Vehicles = new Vehicle[5]; | |
for(int i = 0; i < 5; i++) { | |
Vehicle x = new Vehicle(); | |
x.ReadData(); | |
Vehicles[i] = x; | |
} | |
Console.Clear(); | |
foreach(Vehicle x in Vehicles) | |
{ | |
x.ShowData(); | |
} | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment