Advertisement
Guest User

Attempt 1

a guest
Mar 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. /*
  2.  Student ID:20121230
  3.  Student Name: Duval Pearson
  4.  Topic: Assignment 1 Question 2 Money Class
  5.  
  6.   */
  7.  
  8. using System;
  9.  
  10. using System.Collections.Generic;
  11.  
  12. using System.Linq;
  13.  
  14. using System.Text;
  15.  
  16. namespace Money_app{
  17.    
  18.     class Money{
  19.    
  20.     protected int dollars { get; private set; }
  21.     protected int cents {get; private set;}
  22.    
  23.  public Money(int d,c){
  24.     dollars=d;
  25.     cents=c; }
  26.  
  27.  
  28.  
  29.  
  30. public static Money operator +(Money x, Money y)
  31. {
  32.    int cents = x.cents + y.cents;
  33.    int cents = cents / 100;
  34.    int dollars = x.dollars + y.dollars + (cents % 100)
  35.    return new Money(dollars, cents);
  36. }
  37.  
  38. public void Display(){
  39.  
  40.   Console.WriteLine("Dollars,Cents:{0} {1}",dollars,cents);
  41.  
  42. }
  43.  
  44.  
  45. }
  46.  
  47. class program {
  48.    
  49.      static void Main(string[] args){
  50.          //created two objects with some parameters and added them
  51.         Money Money1= new Money(23,50);
  52.         Money Money2= new Money(34,23);
  53.         Console.WriteLine(Money1+Money2;)
  54.         }
  55.    
  56.    
  57.    
  58.    
  59.     }
  60.  
  61.  
  62.  
  63.  
  64. //end of namespace
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement