/**
Money is an unit that has 2 parts, Rupees and Paise, where 100 Paise=1 Rupee.
Design a class named Money whose details are as follows:
Class Name : Money
Data member:
int rs, ps : integer to store the value of Rupees and paise.
Member methods:
Money(…..) : parameterized constructor to initialize member data
void fnShow() : to show the member data as Money [Rs 819.75]
Money fnAdd(Money m1, Money m2) :
Add m1 and m2. Store the result in corresponding member data and return it.
Specify the class Money, giving the details of the above member data and methods.
Also write the main() to create objects and call the other methods accordingly to
enable the task of the adding 2 units on Money.
*/
import java.util.Scanner;
public class Money
{
int rs,ps;
Money(int rs,int ps)
{
this.rs=rs;
this.ps=ps;
}
void fnShow()
{
int k=0;
if(ps>=100)
{
k=ps/100;
ps=ps%100;
}
rs=rs+k;
System.out.println("Money Rs "+rs+"."+ps);
}
Money fnAdd(Money m1,Money m2)
{
Money sum = new Money(0,0);
sum.rs = m1.rs + m2.rs;
sum.ps = m1.ps + m2.ps;
return sum;
}
public static void main(String args[])
{
Money x = new Money(340,78);
x.fnShow();
Money y = new Money(188,188);
y.fnShow();
x=x.fnAdd(x,y);
x.fnShow();
}
}
Money is an unit that has 2 parts, Rupees and Paise, where 100 Paise=1 Rupee.
Design a class named Money whose details are as follows:
Class Name : Money
Data member:
int rs, ps : integer to store the value of Rupees and paise.
Member methods:
Money(…..) : parameterized constructor to initialize member data
void fnShow() : to show the member data as Money [Rs 819.75]
Money fnAdd(Money m1, Money m2) :
Add m1 and m2. Store the result in corresponding member data and return it.
Specify the class Money, giving the details of the above member data and methods.
Also write the main() to create objects and call the other methods accordingly to
enable the task of the adding 2 units on Money.
*/
import java.util.Scanner;
public class Money
{
int rs,ps;
Money(int rs,int ps)
{
this.rs=rs;
this.ps=ps;
}
void fnShow()
{
int k=0;
if(ps>=100)
{
k=ps/100;
ps=ps%100;
}
rs=rs+k;
System.out.println("Money Rs "+rs+"."+ps);
}
Money fnAdd(Money m1,Money m2)
{
Money sum = new Money(0,0);
sum.rs = m1.rs + m2.rs;
sum.ps = m1.ps + m2.ps;
return sum;
}
public static void main(String args[])
{
Money x = new Money(340,78);
x.fnShow();
Money y = new Money(188,188);
y.fnShow();
x=x.fnAdd(x,y);
x.fnShow();
}
}