The program I wrote works, and prints fine. It creates two objects fine. One object is to be created using the no-arg default constructor, and the other is to be created from the non-default constructor. The only difference is I am supposed to use the set keyword for Author to create a default value. So that when I go to create the object with the wrong author name it will change it using the set keyword.
When I enter in the wrong value for Book1.Author for the non-default constructor, it changes both Author names in both objects. How do I only allow it to change the author name in my Book1 object?
using System;
namespace Book
{
public class Book
{
private string _Author;
private string _Title;
private string _Keywords;
private string _publicationDate;
private string _ISBN;
public Book()
{
Author = "";
}
public Book(string title, string author, string publicationDate, string keywords, string isbn)
{
Title = title;
Author = author;
Keywords = keywords;
PublicationDate = publicationDate;
ISBN = isbn;
}
public string Title { get => _Title; set => _Title = value; }
public string Author { get => _Author; set => _Author = "Mary Delamater and Joel Murach, "; }
public string Keywords { get => _Keywords; set => _Keywords = value; }
public string PublicationDate { get => _publicationDate; set => _publicationDate = value; }
public string ISBN { get => _ISBN; set => _ISBN = value; }
public override string ToString()
{
return Title + Author + PublicationDate + "Keywords: " + Keywords + "ISBN " + ISBN;
}
}
}
using System;
namespace Book
{
class Program
{
static void Main(string[] args)
{
Book Book1 = new Book("murach's ASP.NET Core MVC, ", "Mary Delamater and Joel Murach, ", "January 2020, ", "C#, Programming, MVC, ASP.NET, Core, Beginner", "978-1-943872-49-7");
Console.WriteLine(Book1.ToString());
Book Book2 = new Book();
Book2.Title = "C# In Depth, ";
Book2.Author = "John Skeet, ";
Book2.PublicationDate = "March 23, 2019, ";
Book2.Keywords = "C#, InDepth";
Book2.ISBN = "9781617294532";
Console.WriteLine(Book2.ToString());
}
}
}