. Create class representing a book, assume that this book has, title, author edition. Include all constractors, mutator and accessor methods. This class should override both toString() and equals() methods
internal class Program
{
class Book
{
public string Title { get; private set; }
public string AuthorEdition { get; private set; }
public Book()
{
}
public Book(string title, string authorEdition)
{
Title = title;
AuthorEdition = authorEdition;
}
public override bool Equals(object obj)
{
if ((obj == null) || !GetType().Equals(obj.GetType()))
return false;
Book book = (Book)obj;
return (Title == book.Title) && (AuthorEdition == book.AuthorEdition);
}
public override string ToString()
{
return $"Title: {Title}, Author Edition: {AuthorEdition}";
}
}
static void Main(string[] args)
{
Book book = new Book("A", "B");
Console.WriteLine($"{book} == {new Book("A", "B")} = {book.Equals(new Book("A", "B"))}");
Console.WriteLine($"{book} == {new Book("B", "A")} = {book.Equals(new Book("B", "A"))}");
Console.WriteLine(book);
Console.ReadKey();
}
}
Comments
Leave a comment