Advertisement
Guest User

AutoBEP

a guest
May 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace mlodyApp
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<Auto> lista = new List<Auto>();
  12.  
  13.             lista.Add(new Auto(1.4F, "Opel"));
  14.             lista.Add(new Auto(1.9F, "Passat"));
  15.             lista.Add(new Auto(1.5F, "Mazda"));
  16.             lista.Add(new Auto(4.5F, "Dodge"));
  17.  
  18.             lista[0].setPojemnosc(1.5F);
  19.             lista[1].setPojemnosc(0.5F);
  20.             IEnumerable<Auto>lista2 = lista.Where(x=>{
  21.                 if(x.getPoj()>2.0F){
  22.                     return true;
  23.                 }else{
  24.                     x.Info();
  25.                     return false;
  26.                 }
  27.             });
  28.             foreach (var auto in lista2)
  29.             {
  30.                 Console.WriteLine("Samochod {0} ma silnik o pojemności {1} litra i spełnia warunki wyszukiwania",auto.marka,auto.getPoj());
  31.             }
  32.         }
  33.     }
  34.  
  35.  
  36.     class Auto : Pojazd
  37.     {
  38.         public string marka;
  39.          public Auto(float poj, string m) : base(poj)
  40.         {
  41.             marka = m;
  42.         }
  43.  
  44.         public override void Info()
  45.         {
  46.             base.Info();
  47.             Console.WriteLine(marka);
  48.         }
  49.     }
  50.  
  51.  
  52.  
  53.     class Pojazd
  54.     {
  55.         private float pojemnoscSilnika;
  56.         // private float pojemnoscSilnika;
  57.         public Pojazd(float poj)
  58.         {
  59.             pojemnoscSilnika=poj;
  60.         }
  61.  
  62.         public void setPojemnosc(float bep)
  63.         {
  64.             if(bep > 1.0F)
  65.             {
  66.                 this.pojemnoscSilnika = bep;
  67.             }
  68.             else
  69.             {
  70.                 Console.WriteLine("To nie traficar");
  71.             }
  72.         }
  73.         public float getPoj(){
  74.             return pojemnoscSilnika;
  75.         }
  76.         public virtual void Info()
  77.         {
  78.             Console.WriteLine("Moja pojemnosc to {0}",this.pojemnoscSilnika);
  79.         }
  80.     }
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement