Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp12
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             KulkuValine kv = new KulkuValine("auto", "Honda", 2014, 18190f);
  14.             kv.TulostaTiedot();
  15.  
  16.             Auto a = new Auto("maasto", "Honda", 2014, 18190f, 143, "Civic", 4);
  17.             a.TulostaTiedot();
  18.  
  19.             Auto b = new Auto("työkone", "Caterpillar", 2014, 28190f, 500, "Nostelija 3000", 2);
  20.             b.TulostaTiedot();
  21.         }
  22.     }
  23.  
  24.  
  25.     class KulkuValine
  26.     {
  27.         protected string tyyppi;
  28.         protected string merkki;
  29.         protected int vuosimalli;
  30.         protected float hinta;
  31.  
  32.         public KulkuValine (string tyyppi, string merkki, int vuosimalli, float hinta)
  33.         {
  34.             this.tyyppi = tyyppi;
  35.             this.merkki = merkki;
  36.             this.vuosimalli = vuosimalli;
  37.             this.hinta = hinta;
  38.         }
  39.  
  40.         public virtual void TulostaTiedot ()
  41.         {
  42.             Console.WriteLine(tyyppi + ", " + merkki + ", " + vuosimalli + ", " + hinta);
  43.         }
  44.     }
  45.  
  46.     class Auto : KulkuValine
  47.     {
  48.         protected int koneenKoko;
  49.         protected string malli;
  50.         protected int ovienLkm;
  51.  
  52.         public Auto (string tyyppi, string merkki, int vuosimalli, float hinta, int koneenKoko, string malli, int ovienLkm) : base (tyyppi, merkki, vuosimalli, hinta)
  53.         {
  54.             this.koneenKoko = koneenKoko;
  55.             this.malli = malli;
  56.             this.ovienLkm = ovienLkm;
  57.         }
  58.  
  59.         public override void TulostaTiedot ()
  60.         {
  61.             Console.WriteLine(tyyppi + ", " + merkki + ", " + vuosimalli + ", " + hinta + ", " + koneenKoko + ", " + malli + ", " + ovienLkm);
  62.         }
  63.  
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement