Sean
July 21, 2008using System;
using System.Collections.Generic;
using System.Text;public class Book
{
public enum BookType
{
Undefined,
Fiction,
NonFiction,
History,
Science
}
public enum StatusType
{
Undefined,
Available,
Borrowed
}private string author;
private BookType bookType;
private int pages;
private StatusType status;
private string title;public Book()
{
this.title = “”;
this.author = “”;
this.status = StatusType.Available;
}public Book(BookType type, string title, string author)
{
this.title = “”;
this.author = “”;
this.status = StatusType.Available;
this.bookType = type;
this.title = title;
this.author = author;
}public void Borrow()
{
if (this.status == StatusType.Available)
{
this.status = StatusType.Borrowed;
}
else
{
Console.WriteLine(”Book is already borrowed”);
}
}public void Return()
{
if (this.status == StatusType.Borrowed)
{
this.status = StatusType.Available;
}
else
{
Console.WriteLine(”Book is currently available”);
}
}public override string ToString()
{
return string.Format(”Type: {0}, Title: {1}, Author: {2}, Pages: {3}”, new object[] { this.Type, this.Title, this.Author, this.Pages });
}public string Author
{
get
{
if (this.author.Length < = 0)
{
return "Unknown";
}
return this.author;
}
set
{
if (!new System.Text.RegularExpressions.Regex(@"\d").IsMatch(value))
{
this.author = value;
}
}
}public bool IsBorrowed
{
get
{
return (this.status == StatusType.Borrowed);
}
}public int Pages
{
get
{
return this.pages;
}
set
{
this.pages = value;
}
}public string Title
{
get
{
return this.title;
}
set
{
this.title = value;
}
}public BookType Type
{
get
{
return this.bookType;
}
set
{
this.bookType = value;
}
}public string Value
{
get
{
return string.Format("Type: {0}, Title: {1}, Author: {2}, Pages: {3}", new object[] { this.Type, this.Title, this.Author, this.Pages });
}
}
}

