Guest User

Untitled

a guest
Jul 5th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Harjoituskoe
  7. {
  8.     class Program //tehtävä 2
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int nopeus = 100;
  13.             Auto lada = new Auto(130);
  14.             kuormaauto scania = new kuormaauto(110, 15);
  15.           if (scania.asetanopeus(nopeus)) Console.WriteLine("onnistui");
  16.            if (lada.asetanopeus(nopeus)) Console.WriteLine("onnistui");
  17.             scania.tiedot();
  18.             lada.tiedot();
  19.            
  20.         }
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. //______________________________
  27.  
  28.  
  29.  
  30. namespace Harjoituskoe
  31. {
  32.     class Auto
  33.     {
  34.         int x = 0;
  35.         int y = 0;
  36.  
  37.         public Auto(int maxnopeus)
  38.         {
  39.  
  40.             x = maxnopeus;
  41.  
  42.         }
  43.  
  44.        public bool asetanopeus(int nopeus)
  45.         {
  46.            
  47.  
  48.             if (y < x)
  49.             {
  50.                 y = nopeus;
  51.             } return true;
  52.  
  53.         }
  54.  
  55.         public virtual void tiedot()
  56.         {
  57.             Console.WriteLine("Auto");
  58.             Console.WriteLine("Max nopeus"+x);
  59.             Console.WriteLine("Nopeus" + y);
  60.  
  61.  
  62.         }
  63.     }
  64. }
  65.  
  66.  
  67. //___________________________________
  68.  
  69. namespace Harjoituskoe
  70. {
  71.     class kuormaauto:Auto
  72.     {
  73.        
  74.         int z;
  75.  
  76.         public kuormaauto(int x, int y)
  77.             : base(maxnopeus)
  78.         {
  79.  
  80.  
  81.  
  82.         }
  83.  
  84.      
  85.  
  86.         public override void tiedot()
  87.         {
  88.             Console.WriteLine("Kuormaauto");
  89.             Console.WriteLine("Lastauskyky"+z);
  90.             base.tiedot();
  91.  
  92.  
  93.         }
  94.  
  95.  
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment