Answer to Question #336624 in C# for SITHEMBELE

Question #336624

. 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


1
Expert's answer
2022-05-04T12:39:13-0400
    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();
        }


    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS