Advertisement
damesova

CarsProject

Oct 3rd, 2022
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. //Класа Car:
  2.  
  3. namespace CarsProject
  4. {
  5.     public class Car
  6.     {
  7.         private string brand;
  8.         private string model;
  9.         private string year;
  10.         private string color;
  11.         private double price;
  12.  
  13.         public Car(string carBrand,
  14.             string carModel,
  15.             string carYear,
  16.             string carColor,
  17.             double carPrice)
  18.         {
  19.             this.brand = carBrand;
  20.             this.model = carModel;
  21.             this.year = carYear;
  22.             this.color = carColor;
  23.             this.price = carPrice;
  24.         }
  25.  
  26.         public void printInfo(Car car)
  27.         {
  28.             Console.WriteLine("Brand: {0}\nModel: {1}\n", car.brand, car.model);  
  29.         }
  30.  
  31.     }
  32. }
  33.  
  34.  
  35. //Главен клас:
  36.  
  37. namespace CarsProject
  38. {
  39.     public class Program
  40.     {
  41.         static void Main(string[] args)
  42.         {
  43.             Car car1 = new Car(
  44.                 "Merc", "G65", "2001", "Yellow", 1000
  45.                 );
  46.  
  47.             Car car2 = new Car(
  48.                 "VW", "Golf 4", "2004", "Red", 2000
  49.                 );
  50.  
  51.  
  52.             car1.printInfo(car1);
  53.             Console.WriteLine();
  54.             car2.printInfo(car2);
  55.            
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement