Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Assignment Program Description In this assignment, you will develop a Console Application related to a simple library system. You must develop code for all

C# Assignment

Program Description

In this assignment, you will develop a Console Application related to a simple library system.

You must develop code for all the following classes as described.

Create a new project called A3_YourLastNameYourFirstName in MIcrosoft Visual Studio.

2. Add a class called Customer to the project by right-clicking on the project in the Solutions Explorer and then selecting Add > New Item > Class

Copy the code from Customer.cs file provided to you into this class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace A3

{

class Customer

{

private int id;

private string name;

public int Id

{

get { return id; }

}

public string Name

{

get { return name; }

set { name = value; }

}

public Customer(string name, int id)

{

this.id = id; this.name = name;

}

public string ToString()

{

return String.Format("{0,-5}{1,-10}", id, name);

}

}

}

Add a class called Book and add code for the following:private attributes:

int catalogNumber books catalog number

string title books title

string authors books authors

Customer c - reference to the customer to who the book is issued, if at all.

public properties:

CatalogNumber with only the get part

Public methods:

Book(string title, string authors, int catalogNo) constructor that initializes the title, author and catalog number attributes to the values passed.

string ToString() - returns a string containing the books catalog number, title, authors of the book followed by check-out information. If the book is not checked out the check-out information should be Available; otherwise it should say Checked-out to Customer followed by the id of the customer to whom it is checked out to. See sample output for an example.

bool CheckOut(Customer c): issues the book to the customer c if the book is not already checked out and returns true. But if the book is already checked out, it returns false.

bool CheckIn(): checks-in the book to the library if the book is checked out and returns true. But if the book was not checked out, it returns false.

Add a class called Library and add the code for:private attributes:

customerArray which is an array of Customers of size 5

bookArray which is an array of Books of size 5

public methods:

bool AddNewCustomer(string customerName): if the number of customers already added is less than the size of the customerArray , this method will create a new Customer object with the given name and unique id (the first customer should get an id of 1, the second customer should get an id of 2, and so on.), and add it to the customerArray. This method will return true if the customer was successfully added else it will return false. You may have to add private attributes to the Library class to generate unique customer ids.

bool AddNewBook(string bookTitle, string bookAuthor): if the number of books already added is less than the size of the bookArray, this method will create a new Book object with the given title, author and a unique catalogNumber (the first book should get a catalog number of 101, the second book should get catalog number of 102, and so on.), and add it to the bookArray. This method will return true if the book was successfully added else it will return false. You may have to add private attributes to the Library class to generate unique book catalog numbers.

string ToString( ): will return a string which has information about all the customers of the library, each customers information in a new line followed by the information about all the books of the library, each books information in a new line. It should use the ToString() method of Customer and Book class. See sample output for exact format.

5. Copy the code in the Main() method from the attached file Program.cs to the Main() method of your project. The sample output for this Main method is given below.

Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace A3

{

class Program

{

static void Main(string[] args)

{

Customer c1 = new Customer("Tom", 1);

Customer c2 = new Customer("Mary", 2);

Book b1 = new Book("Java by Example", "Deitel", 1);

Book b2 = new Book("C# by Example", "Murach", 2);

Console.WriteLine("-------Testing ToString()------------- ");

Console.WriteLine(c1.ToString());

Console.WriteLine(c2.ToString());

Console.WriteLine();

Console.WriteLine(b1.ToString());

Console.WriteLine(b2.ToString());

Console.WriteLine();

Console.WriteLine("-------Testing CheckOut()------------- ");

Console.WriteLine("b1.CheckOut(c1): " + b1.CheckOut(c1));

Console.WriteLine("b1.CheckOut(c2): " + b1.CheckOut(c2));

Console.WriteLine();

Console.WriteLine(b1.ToString());

Console.WriteLine(b2.ToString());

Console.WriteLine();

Console.WriteLine("-------Testing CheckIn()------------- ");

Console.WriteLine("b1.CheckIn: " + b1.CheckIn());

Console.WriteLine("b2.CheckIn: " + b2.CheckIn());

Console.WriteLine();

Console.WriteLine(b1.ToString());

Console.WriteLine(b2.ToString());

Console.WriteLine();

Console.WriteLine("-------Testing AddNewCustomer()------------- ");

Library library = new Library();

Console.WriteLine("Add Customer Fred: " + library.AddNewCustomer("Fred"));

Console.WriteLine("Add Customer Bob: " + library.AddNewCustomer("Bob"));

Console.WriteLine("Add Customer Kyle: " + library.AddNewCustomer("Kyle"));

Console.WriteLine();

Console.WriteLine("-------Testing AddNewBook()------------- ");

Console.WriteLine("Add Book Learning C#: " + library.AddNewBook("Learning C#", "Liberty"));

Console.WriteLine("Add Book Introduction to C#: " + library.AddNewBook("Introduction to C#", "Deitel"));

Console.WriteLine("Add Book Advanced C#: " + library.AddNewBook("Advanced C#", "Murach"));

Console.WriteLine();

Console.WriteLine("-------Testing Library.ToString()------------- ");

Console.WriteLine(library.ToString());

Console.WriteLine("-------Testing AddNewCustomer()------------- ");

Library library1 = new Library();

Console.WriteLine("Add Customer C1: " + library1.AddNewCustomer("C1"));

Console.WriteLine("Add Customer C2: " + library1.AddNewCustomer("C2"));

Console.WriteLine("Add Customer C3: " + library1.AddNewCustomer("C3"));

Console.WriteLine("Add Customer C4: " + library1.AddNewCustomer("C4"));

Console.WriteLine("Add Customer C5: " + library1.AddNewCustomer("C5"));

Console.WriteLine("Add Customer C6: " + library1.AddNewCustomer("C6"));

Console.WriteLine();

Console.WriteLine("-------Testing AddNewCustomer()------------- ");

Console.WriteLine("Add Book B1: " + library1.AddNewBook("B1", "A1"));

Console.WriteLine("Add Book B2: " + library1.AddNewBook("B2", "A1"));

Console.WriteLine("Add Book B3: " + library1.AddNewBook("B3", "A1"));

Console.WriteLine("Add Book B4: " + library1.AddNewBook("B4", "A1"));

Console.WriteLine("Add Book B5: " + library1.AddNewBook("B5", "A1"));

Console.WriteLine("Add Book B6: " + library1.AddNewBook("B6", "A1"));

Console.WriteLine();

Console.ReadLine();

}

}

}

image text in transcribed

Sample Output Testing ToString Tom Mary Java by Example C# by Example Deitel Murach Available Available Testing Checkout 1.Checkout c1: True 1.Checkout c2): False Java by Example by Exanple De itel Murach Checked out to Customer 1 Available Testing CheckIn 1.CheckIn: True CheckIn: False De itel Murach Java by Example Available Available anple Testing AddNewCustoner dd Customer FredTrue Add Customer Bob: True dd Custoner Kyle True Testing AddNewBook dd Book B1: True Add Book B2: True Add Book B3:True Add Book B4: True Add Book B5: True dd Book B6: False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions