Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication7
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. BookInfo book1 = new BookInfo();// Makes room in memory
  23. BookInfo book2 = new BookInfo();
  24. BookInfo book3 = new BookInfo();
  25.  
  26.  
  27.  
  28.  
  29. book1.ISBN = 878444555;/// Information about each book. Infomation is sent to boolean
  30. book1.Title = "History";
  31. book1.Author = " Richard-Gifts, Susan";
  32. book1.Price = 15;
  33.  
  34. book2.ISBN = 878444555;
  35. book2.Title = "Spanish";
  36. book2.Author = "Swinn, Peter";
  37. book2.Price = 25;
  38.  
  39. book3.ISBN = 776112945;
  40. book3.Title = "English";
  41. book3.Author = "Quarter, Lynn";
  42. book3.Price = 85;
  43.  
  44.  
  45.  
  46. /// Displays results in label.
  47.  
  48. lblResults.Text += "ISBN: " + book1.ISBN + " - " + book1.Title + " by : " + book1.Author + " will cost " + book1.Price.ToString() + "\n";
  49. lblResults.Text += "ISBN: " + book2.ISBN.Equals(book1.ISBN) + " This book has the same ISBN as Book 1\n";
  50. lblResults.Text += "ISBN: " + book3.ISBN + " - " + book3.Title + " by : " + book3.Author + " will cost " + book3.Price.ToString() + "\n";
  51.  
  52.  
  53. }
  54.  
  55. }
  56. }
  57.  
  58. class BookInfo /// Books information class
  59. {
  60. private int isbn;
  61. private string title;
  62. private string author;
  63. protected double price;
  64.  
  65. public int ISBN
  66. {
  67. get
  68. {
  69. return isbn;
  70. }
  71. set
  72. {
  73. isbn = value;
  74. }
  75. }
  76. public string Title
  77. {
  78. get
  79. {
  80. return this.title;
  81. }
  82. set
  83. {
  84. this.title = value;
  85. }
  86. }
  87. public string Author
  88. {
  89. get
  90. {
  91. return this.author;
  92. }
  93. set
  94. {
  95. this.author = value;
  96. }
  97. }
  98. public virtual double Price
  99. {
  100. get
  101. {
  102. return price;
  103. }
  104. set
  105. {
  106. price = value;
  107. }
  108. }
  109. public override bool Equals(object book2) ///This determines if book1 and 2 have the same ISBN True or False.
  110. {
  111. bool equal;
  112. if (this.GetType() != book2.GetType())
  113. equal = false;
  114. else
  115. {
  116. BookInfo check = (BookInfo)book2;
  117. if (ISBN == check.ISBN)
  118. {
  119. equal = true;
  120. }
  121. else
  122. equal = false;
  123. }
  124. return equal;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement