Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions tdd-oop-inheritance.CSharp.Main/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,19 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Article {
public string title;

bool onLoan = false;

public Article(string title) {
this.title = title;
public class Article :InventoryItem, Item
{
public Author _author;
public Article(string title, Author author) {
this.Title = title;
_author = author;
}

public bool isOnLoan() {
return onLoan;
public Article(string title)
{
this.Title = title;
_author = new Author(string.Empty,string.Empty,string.Empty);
}

public string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}

this.onLoan = false;

return "item has been checked in";
}

public string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
public Author Author { get { return _author; } }
}
}
28 changes: 28 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class Author
{
private string _name;
private string _adress;
private string _website;
public Author(string name, string adress, string website)
{
_name = name;
_adress = adress;
_website = website;
}

public string Name { get { return _name; } }
public string Adress { get { return _adress; } }
public string Website { get { return _website; } }


}
}
33 changes: 9 additions & 24 deletions tdd-oop-inheritance.CSharp.Main/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,22 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Book {
public class Book : InventoryItem, Item
{
public string title;

bool onLoan = false;
public Author _author;

public Book(string title) {
this.title = title;
}
_author = new Author(string.Empty, string.Empty, string.Empty);

public bool isOnLoan() {
return onLoan;
}

public string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}

this.onLoan = false;

return "item has been checked in";
public Book(string title, Author author)
{
this.title = title;
_author = author;
}

public string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
public Author Author { get { return _author; } }
}
}
52 changes: 52 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/InventoryItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using tdd_oop_inheritance.CSharp.Main;

namespace tdd_oop_inheritance.CSharp.Main
{
public class InventoryItem: Item

{
private string _title = "";
private bool onLoan = false;

public bool isOnLoan()
{
return onLoan;
}

public string checkIn()
{

if (!this.isOnLoan())
{
return "item is not currently on loan";
}

this.onLoan = false;

return "item has been checked in";
}

public string checkOut()
{
if (this.isOnLoan())
{
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";

}


public string Title { get { return _title; } set { _title = value; } }

}
}
22 changes: 22 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public interface Item
{
public string Title { get; set; }

public string checkIn() {
return string.Empty;
}
public string checkOut()
{
return string.Empty;
}
}
}
85 changes: 26 additions & 59 deletions tdd-oop-inheritance.CSharp.Main/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,24 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Library {
List<Article> articles = new List<Article>();
List<Book> books = new List<Book>();
List<Newspaper> newspapers = new List<Newspaper>();
public class Library:InventoryItem
{
private Dictionary<int,Item> inventory = new Dictionary<int, Item>();

public void addToStock(Article item) {
this.articles.Add(item);

public void addToStock(Item item) {
this.inventory.Add(inventory.Count,item);
}

public void addToStock(Book item) {
this.books.Add(item);
}

public void addToStock(Newspaper item) {
this.newspapers.Add(item);
}

// The following methods may contain code that you are unfamiliar with. The strange syntax of article -> something
// is called a lambda expression (https://www.w3schools.com/java/java_lambda.asp)
public string checkInArticle(string title) {

List<Article> filtered = (List<Article>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}

return filtered[0].checkIn();
}

public string checkOutArticle(string title) {
List<Article> filtered = (List<Article>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
public string checkIn(Item item) {
List<Item> filtered = new List<Item>();
foreach (Item item2 in this.inventory.Values)
{
if (item2.Title.Equals(item.Title)) { filtered.Add(item2); }
}



return filtered[0].checkOut();
}

public string checkInBook(string title) {
List<Book> filtered = (List<Book>)this.books.Where(book => book.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
Expand All @@ -56,34 +32,25 @@ public string checkInBook(string title) {
return filtered[0].checkIn();
}

public string checkOutBook(string title) {
List<Book> filtered = (List<Book>)this.books.Where(book => book.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}

return filtered[0].checkOut();
}

public string checkInNewspaper(string title) {
List<Newspaper> filtered = (List<Newspaper>)this.newspapers.Where(newspaper => newspaper.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
public string checkOut(Item item)
{
List<Item> filtered = new List<Item>();
foreach (Item item2 in this.inventory.Values)
{
if (item2.Title.Equals(item.Title)) { filtered.Add(item2); }
}

return filtered[0].checkIn();
}

public string checkOutNewspaper(string title) {
List<Newspaper> filtered = (List<Newspaper>)this.newspapers.Where(newspaper => newspaper.title.Equals(title));
if (filtered.Count() < 1)
{
return "item is not part of the library's collection";
}

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
return filtered[0].checkOut();
}

return filtered[0].checkOut();
public Dictionary<int,Item> getInventory { get => inventory; }
}
}
}

23 changes: 9 additions & 14 deletions tdd-oop-inheritance.CSharp.Main/Newspaper.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class Newspaper
public class Newspaper : InventoryItem,Item
{
public string title;

Boolean onLoan = false;


public Newspaper(string title) {
this.title = title;
}

public bool isOnLoan() {
return onLoan;
this.Title = title;
}

public string checkIn() {
public new string checkIn()
{ return "newspapers are not available for loan"; }

public new string checkOut() {
return "newspapers are not available for loan";
}

public string checkOut() {
return "newspapers are not available for loan";
}

}
}
Loading