Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Student ID:20121230
- Student Name: Duval Pearson
- Topic: Assignment 1 Question 2 Money Class
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Money_app{
- class Money{
- protected int dollars { get; private set; }
- protected int cents {get; private set;}
- public Money(int d,c){
- dollars=d;
- cents=c; }
- public static Money operator +(Money x, Money y)
- {
- int cents = x.cents + y.cents;
- int cents = cents / 100;
- int dollars = x.dollars + y.dollars + (cents % 100)
- return new Money(dollars, cents);
- }
- public void Display(){
- Console.WriteLine("Dollars,Cents:{0} {1}",dollars,cents);
- }
- }
- class program {
- static void Main(string[] args){
- //created two objects with some parameters and added them
- Money Money1= new Money(23,50);
- Money Money2= new Money(34,23);
- Console.WriteLine(Money1+Money2;)
- }
- }
- //end of namespace
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement