Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Ember.DataLoader;
- using Ember.Logic;
- using Ember.Models;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace Ember.DataLoader
- {
- internal class Loader
- {
- string[] lines;
- public Loader(string doc)
- {
- lines = File.ReadAllLines(doc);
- }
- public List<EmberPeldany> LoadEmberek()
- {
- List<EmberPeldany> emberek = new List<EmberPeldany>();
- foreach (var line in lines)
- {
- {
- emberek.Add(new EmberPeldany()
- {
- Nev = line.Split(';')[0],
- Eletkor = int.Parse(line.Split(';')[1])
- });
- }
- }
- return emberek;
- }
- }
- }
- namespace Ember.Logic
- {
- public class EmberLogic
- {
- List<EmberPeldany> emberek;
- Loader loader;
- string path;
- public EmberLogic(string path)
- {
- this.path = path;
- Setup();
- }
- public void Setup()
- {
- loader = new Loader(path);
- emberek = loader.LoadEmberek();
- }
- public string EmberekNevei()
- {
- List<string> emberekstringbe = emberek
- .Select(t => t.Nev).ToList();
- string nevek = "";
- foreach (var item in emberekstringbe)
- {
- nevek += item + "\n";
- }
- return nevek;
- }
- public int AdottEmberKora(string nev)
- {
- if (!emberek.Any(t => t.Nev == nev))
- {
- throw new ArgumentException("Nem létező ember név");
- }
- return emberek
- .Where(t => t.Nev == nev)
- .Select(t => t.Eletkor).FirstOrDefault();
- }
- }
- }
- namespace Ember.Models
- {
- public class EmberPeldany
- {
- public int Eletkor { get; set; }
- public string Nev { get; set; }
- }
- }
- namespace Ember
- {
- class Program
- {
- static void Main(string[] args)
- {
- EmberLogic logic = new("emberek.txt");
- Console.WriteLine("Az összes ember neve:");
- Console.WriteLine(logic.EmberekNevei());
- Console.Write("\nAkinek az életkorára kíváncsi vagy: ");
- string nev = Console.ReadLine();
- int eletkor = logic.AdottEmberKora(nev);
- Console.WriteLine($"{nev} életkora: {eletkor} év.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement