Forgive me for asking what some might think are stupid questions. I am trying to read the code below and make sense out of it.
Why is novel.title used in the main. I understand where I get the title from but why does novel.title used. The other one is what is holding the title information that was entered by the user. Same questions with author, and level.
using System;
using System.Collections.Generic;
using System.Text;
namespace assignment6
{
public class Book
{
protected string title;
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
protected string author;
public string Author
{
get
{
return author;
}
set
{
author = value;
}
}
public void showBook()
{
Console.WriteLine("The Book you entered is " + title + " by " + author);
}
public Book(string booktyp1, string booktyp2)
{
Console.WriteLine("You will enter data for a " + booktyp1 + " book indicating the " + booktyp2 + " book.");
Console.WriteLine();
}
}
public class Fiction : Book
{
private int level;
public int Level
{
get
{
return level;
}
set
{
level = value;
}
}
public void showFiction()
{
showBook();
Console.WriteLine("Reading level is " + level);
}
public Fiction()
: base("Fiction", "reading level")
{
}
}
public class NonFiction : Book
{
private int pages;
public int Pages
{
get
{
return pages;
}
set
{
pages = value;
}
}
public void showNonFiction()
{
showBook();
Console.WriteLine(pages + " pages");
}
public NonFiction()
: base("NonFiction", "Number of pages")
{
}
}
public class assignment6
{
public static void Main(string[] args)
{
char choice;
Console.Write("Do you want Fiction (F) or Non-Fiction (N)? -->");
choice = Convert.ToChar(Console.ReadLine().ToUpper());
switch (choice)
{
case 'F':
{
Fiction novel = new Fiction();
Console.Write("Enter the book title-->");
novel.Title = Console.ReadLine();
Console.Write("Enter the book author-->");
novel.Author = Console.ReadLine();
Console.Write("Enter the reading level-->");
novel.Level = Convert.ToInt32(Console.ReadLine());
novel.showFiction();
break;
}
case 'N':
{
NonFiction manual = new NonFiction();
Console.Write("Enter the book title-->");
manual.Title = Console.ReadLine();
Console.Write("Enter the book author-->");
manual.Author = Console.ReadLine();
Console.Write("Enter the number of pages-->");
manual.Pages = Convert.ToInt32(Console.ReadLine());
manual.showNonFiction();
break;
}
default:
{
Console.WriteLine("You made an inappropriate entry -- closing program");
break;
}
}
}
}
}
I am sure everyone here know how new I am to programming. I can say this I love it when it works, I hate it when it doesnt and makes me want to quiet.