Advertisement
damesova

ClassesAndObjects

Oct 4th, 2022
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. //Клас КОЛА:
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace CarsProject
  10. {
  11.     public class Car
  12.     {
  13.         private string brand;
  14.         private string model;
  15.         private string year;
  16.         private string color;
  17.         private double price;
  18.  
  19.         public Car(string carBrand,
  20.             string carModel,
  21.             string carYear,
  22.             string carColor,
  23.             double carPrice)
  24.         {
  25.             this.brand = carBrand;
  26.             this.model = carModel;
  27.             this.year = carYear;
  28.             this.color = carColor;
  29.             this.price = carPrice;
  30.         }
  31.  
  32.         public void printInfo(Car car)
  33.         {
  34.             Console.WriteLine("Brand: {0}\nModel: {1}\nPrice: {2}", car.brand, car.model, car.price);  
  35.         }
  36.  
  37.     }
  38. }
  39.  
  40. //Главна програма:
  41.  
  42. namespace CarsProject
  43. {
  44.     public class Program
  45.     {
  46.         static void Main(string[] args)
  47.         {
  48.             Car pesho = new Car(
  49.                 "Merc", "G65", "2001", "Yellow", 1000
  50.                 );
  51.  
  52.             Car gosho = new Car(
  53.                 "VW", "Golf 4", "2004", "Red", 2000
  54.                 );
  55.  
  56.  
  57.             pesho.printInfo(pesho);
  58.             Console.WriteLine();
  59.             gosho.printInfo(gosho);
  60.            
  61.         }
  62.     }
  63. }
  64.  
  65.  
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement