Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace zad1 {
- //Polimorfizm, wywołując metodę Pole() automatycznie policzy dla dobrej figury
- abstract class Figura {
- public abstract int Pole();
- }
- class Kwadrat : Figura {
- int a;
- public Kwadrat(int a) {
- this.a = a;
- }
- public override int Pole() {
- return a * a;
- }
- }
- class Prostokat : Figura {
- int a, b;
- public Prostokat(int a, int b) {
- this.a = a;
- this.b = b;
- }
- public override int Pole() {
- return a * b;
- }
- }
- //Low coupling - mała zależność między MovieFan, MovieStore, Movie
- class MovieFan {
- public void PickAMovie(string movieTitle, MovieStore ms) {
- List<string> titles = ms.GetAvailableTitles();
- if (titles.Contains(movieTitle)) {
- Console.WriteLine("We got this!");
- } else {
- Console.WriteLine("Oops");
- }
- }
- }
- class MovieStore {
- List<Movie> availableMovies;
- public MovieStore() {
- availableMovies = new List<Movie>();
- }
- public List<string> GetAvailableTitles() {
- List<string> res = new List<string>();
- foreach (var movie in availableMovies) {
- res.Add(movie.title);
- }
- return res;
- }
- }
- class Movie {
- public string title, genre;
- int yearOfProduction;
- public Movie(string title, string genre, int yearOfProduction) {
- this.title = title;
- this.genre = genre;
- this.yearOfProduction = yearOfProduction;
- }
- }
- class User {
- string username;
- List<Movie> movies;
- public User(string username) {
- this.username = username;
- movies = new List<Movie>();
- }
- //Użytkownik ma swoje ulubione filmy, w dodatku "agreguje" je, więc to on tworzy obiekty Movie
- public void AddMovieToFavourites(string title, string genre, int yearOfProduction) {
- Movie movie = new Movie(title, genre, yearOfProduction);
- movies.Add(movie);
- }
- //Użytkownik ma listę filmów, więc ma wiedzę ile ich jest
- public int GetNumOfFavoouriteMovies() {
- return movies.Count;
- }
- public void PrintFavourites() {
- foreach (var movie in movies) {
- Console.WriteLine($"{movie.title}, {movie.genre}");
- }
- }
- }
- class Program {
- static void Main(string[] args) {
- User user = new User("igor");
- user.AddMovieToFavourites("Mulan", "animowany", 1998);
- user.PrintFavourites();
- Figura kwadrat = new Kwadrat(10);
- Console.WriteLine(kwadrat.Pole());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement