From eb560ac9126305a901ba7d7d4c1a43a9a227dde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Rudolf?= Date: Tue, 20 Oct 2026 12:13:53 +0200 Subject: [PATCH] Objektumok --- Objektumok/Objektumok.sln | 25 ++++++++++ Objektumok/Objektumok/Auto.cs | 47 ++++++++++++++++++ Objektumok/Objektumok/Objektumok.csproj | 10 ++++ Objektumok/Objektumok/Program.cs | 39 +++++++++++++++ Objektumok/Objektumok/Szemely.cs | 65 +++++++++++++++++++++++++ 5 files changed, 186 insertions(+) create mode 100644 Objektumok/Objektumok.sln create mode 100644 Objektumok/Objektumok/Auto.cs create mode 100644 Objektumok/Objektumok/Objektumok.csproj create mode 100644 Objektumok/Objektumok/Program.cs create mode 100644 Objektumok/Objektumok/Szemely.cs diff --git a/Objektumok/Objektumok.sln b/Objektumok/Objektumok.sln new file mode 100644 index 0000000..446858b --- /dev/null +++ b/Objektumok/Objektumok.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36401.2 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Objektumok", "Objektumok\Objektumok.csproj", "{34FB1ABA-DC53-40A0-ACD5-6FE7C2840568}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {34FB1ABA-DC53-40A0-ACD5-6FE7C2840568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {34FB1ABA-DC53-40A0-ACD5-6FE7C2840568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34FB1ABA-DC53-40A0-ACD5-6FE7C2840568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {34FB1ABA-DC53-40A0-ACD5-6FE7C2840568}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1D214405-CF0B-4D65-9547-E65E9AC721D7} + EndGlobalSection +EndGlobal diff --git a/Objektumok/Objektumok/Auto.cs b/Objektumok/Objektumok/Auto.cs new file mode 100644 index 0000000..fb3c454 --- /dev/null +++ b/Objektumok/Objektumok/Auto.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Objektumok +{ + public class Auto + { + + + //property=változó+beállító függvény+lekérdező függvény egyben + public string Marka { get; set; } + public string Tipus { get; set; } + public int FutottKm { get; set; } + + private int gyartasiev; + public int GyartasiEv { + get { return gyartasiev; } + set + { + if (value>1980) + { + gyartasiev = value; + } else + { + throw new ArgumentException("Hibás gyártási év!"); + } + } + } + + + public Auto(string marka, string tipus, int futottKm, int gyartasiEv) + { + Marka = marka; + Tipus = tipus; + FutottKm = futottKm; + GyartasiEv = gyartasiEv; + } + + public Auto() + { + + } + } +} diff --git a/Objektumok/Objektumok/Objektumok.csproj b/Objektumok/Objektumok/Objektumok.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/Objektumok/Objektumok/Objektumok.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Objektumok/Objektumok/Program.cs b/Objektumok/Objektumok/Program.cs new file mode 100644 index 0000000..004fd45 --- /dev/null +++ b/Objektumok/Objektumok/Program.cs @@ -0,0 +1,39 @@ +namespace Objektumok +{ + internal class Program + { + static void Main(string[] args) + { + Szemely szemely = new Szemely("Kiss","Géza","Orosháza",1999); + + szemely.SetVezeteknev("Kósa"); + + Console.WriteLine(szemely.GetVezeteknev()); + + szemely.SetSzuletesiEv(2001); + + Console.WriteLine(szemely.Eletkor()); + + + Console.WriteLine(szemely.ToString()); + + Auto auto1= new Auto(); + + Auto auto2 = new Auto { + Marka="Opel", + Tipus="Insignia", + GyartasiEv=2010, + FutottKm=226000 + }; + + Auto auto3 = new Auto("Seat","Ibiza",216000,1976); + + //Objektum példányok hozzáadása listához + List autok = new List(); + autok.Add(auto1); + autok.Add(auto2); + autok.Add(auto3); + autok.Add(new Auto("Skoda", "Octavia", 323000, 2010)); + } + } +} diff --git a/Objektumok/Objektumok/Szemely.cs b/Objektumok/Objektumok/Szemely.cs new file mode 100644 index 0000000..10bcf39 --- /dev/null +++ b/Objektumok/Objektumok/Szemely.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Objektumok +{ + public class Szemely + { + // mezők/fields, adattag, osztály változó + string vezeteknev; + string keresztnev; + string telepules; + int szuletesiev; + + //konstruktor függvény + //speciális metódus, amely példányosításkor automatikusan lefut + //a neve meg kell hogy egyezzen az osztály nevével + //nincs visszatérési értéke, és nem void + + + //paraméteres konstruktor + public Szemely(string vezeteknev,string keresztnev,string telepules,int szuletesiev) + { + this.vezeteknev = vezeteknev; + this.keresztnev = keresztnev; + this.telepules = telepules; + this.szuletesiev = szuletesiev; + } + + public int Eletkor() + { + return DateTime.Now.Year - szuletesiev; + } + + public void SetVezeteknev(string vezeteknev) + { + if (vezeteknev.Length < 3) + { + throw new ArgumentException("Túl rövid a név!"); + } else + { + this.vezeteknev = vezeteknev; + } + } + + public string GetVezeteknev() { + return vezeteknev; + } + + public void SetSzuletesiEv(int szuletesiev) + { + if (szuletesiev>1920) + { + this.szuletesiev = szuletesiev; + } + else + { + throw new ArgumentException("Hibás év!"); + } + } + + } +}