-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.cs
93 lines (80 loc) · 2.39 KB
/
Item.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace LibrarySystem
{
abstract class Item
{
public string title { get; set; }
public string date_borrowed { get; set; }
public string borrower_name { get; set; }
public Item(string title, string date_borrowed = null, string borrower_name = null)
{
this.title = title;
this.date_borrowed = date_borrowed;
this.borrower_name = borrower_name;
}
public bool Borrowed()
{
if (borrower_name == null)
return true;
else
return false;
}
public bool Can_be_borrowed_by(Member name)
{
if (name.num_borrowed >= 1)
{
//Console.WriteLine("The item can NOT be borrowed");
return false;
}
else
{
//Console.WriteLine("The item can be borrowed");
return true;
}
}
public bool Borrow_item_by(Member name)
{
if (borrower_name == null)
{
if (Can_be_borrowed_by(name) == true)
{
Console.WriteLine($"The item has been successfully borrowed to {name.name}");
name.BorrowItem();
return true;
}
else
{
Console.WriteLine($"The item can't be borrowed to {name.name}");
return false;
}
}
else
{
Console.WriteLine("The item has not been successfully borrowed");
return false;
}
}
public void Return_item(Member name)//problem
{
name.ReturnItem();
borrower_name = null;
Console.WriteLine("The item has been successfully returned");
}
public override string ToString()
{
if (borrower_name != null)
{
return $"{title} is on loan to {borrower_name}.";
}
else
{
return $"{title} is not on loan.";
}
}
}
}