From 5a787865320f2a5f49f6c1e8a97141a8c18213e0 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 22 Jun 2026 12:59:28 -0300 Subject: [PATCH] Done. --- main.py | 6 ++- txt.txt | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 txt.txt diff --git a/main.py b/main.py index 4187a4c..caa2b21 100644 --- a/main.py +++ b/main.py @@ -7,4 +7,8 @@ media3 = Movie("Dune", 2011, "R", 81) media1.print_details() media2.print_details() -media3.print_details() \ No newline at end of file +media3.print_details() + +comparison = media2.compare_to(media3) + +print(comparison) \ No newline at end of file diff --git a/txt.txt b/txt.txt new file mode 100644 index 0000000..ed2778d --- /dev/null +++ b/txt.txt @@ -0,0 +1,115 @@ +public class Media +{ + public string Title { get; private set; } + public int Year { get; private set; } + + public Media(string title, int year) + { + Title = title; + Year = year; + } + + public virtual void PrintDetails() + { + Console.WriteLine($"MEDIA: {Title}, {Year}"); + } +} + + + +public class Movie : Media, IComparable +{ + public string ParentalRating { get; private set; } + public int Rating { get; private set; } // derived from imdbRating * 10 + + public Movie(string title, int year, string parentalRating, double imdbRating) : base(title, year) + { + ParentalRating = parentalRating; + Rating = (int)(imdbRating * 10); + } + + public override bool Equals(object obj) + { + if (obj == null) + { + return false; + } + + if (obj is Movie other) + { + return this.Title == other.Title && + this.Year == other.Year && + this.ParentalRating == other.ParentalRating && + this.Rating == other.Rating; + } + + return false; + } + + public int CompareTo(Movie other) + { + if (other == null) + { + return 1; + } + + if(this.Rating > other.Rating) + { + return 1; + } + else if(this.Rating < other.Rating) + { + return -1; + } + return 0; + } + + public override int GetHashCode() + { + int hash = 17; + foreach (char c in Title) + { + hash = hash * 31 + c; + } + hash = hash * 31 + Year; + foreach (char c in ParentalRating) + { + hash = hash * 31 + c; + } + hash = hash * 31 + Rating; + return (Math.Abs(hash) % 1000) / 100; + } + + public override void PrintDetails() + { + Console.WriteLine($"Movie: {base.Title}, {base.Year}, Parental Rating = {ParentalRating}, IMDB Rating = {(double)Rating / 10}"); + } + + public override string ToString() + { + return $"Movie: {base.Title}, {base.Year}, Parental Rating = {ParentalRating}, IMDB Rating = {(double)Rating / 10}"; + } +} + +public class Program +{ + public static void Main(string[] args) + { + Media media1 = new Media("Star Wars", 1977); + + Media media2 = new Movie("Drive", 2011, "R", 7.9); + + Movie movie1 = new Movie("Dune", 2021, "R", 8.1); + + media1.PrintDetails(); + + media2.PrintDetails(); + + movie1.PrintDetails(); + } +} + +OUTPUT: +MEDIA: Star Wars, 1977 +Movie: Drive, 2011, Parental Rating = R, IMDB Rating = 7.9 +Movie: Dune, 2021, Parental Rating = R, IMDB Rating = 8.1 \ No newline at end of file