Advertisement
callumbinner22

Book class

Apr 6th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace OBJECTORIENTATEDCODE
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Book potter = new Book()
  14.             {
  15.                 author = "JK Rowling",
  16.                 title = "Harry Potter and the Philosiphers stone",
  17.                 Numpages = 223,
  18.                 Cost = 4.99
  19.             };
  20.  
  21.             potter.display();
  22.             potter.Discount();
  23.  
  24.         }
  25.     }
  26.  
  27.  
  28.  
  29.  
  30.     class Book
  31.     {
  32.  
  33.  
  34.  
  35.  
  36.         public string author;
  37.         public string title;
  38.         public int Numpages;
  39.         public double Cost;
  40.  
  41.         public void display()
  42.         {
  43.             Console.WriteLine("Author " + this.author);
  44.             Console.WriteLine("Title " + this.title);
  45.             Console.WriteLine("Number of pages " + this.Numpages);
  46.             Console.WriteLine("Cost £ " + this.Cost);
  47.         }
  48.  
  49.         public void Discount()
  50.         {
  51.             Console.WriteLine(this.Cost * 0.9);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement