C# Create a Money class that has as data member dollars and cents. Include Incre
ID: 3594880 • Letter: C
Question
C#
Create a Money class that has as data member dollars and cents. Include IncrementMoney and DecrementMoney instance methods. Include constructors that enables the Money class to be instantiated with a single value representing the full dollars / cents amount as well as a constructor that enables you to creates an instance of the class by sending two separate integer values representing the dollars and cent amounts. Include an instance method that returns as a string the number of dollars, quarters, nickels, dimes, and pennies represent by the object’s value. Override the ToString() method to return the monetary amount formatted with currency symbols. Create a second class to test your money class.
Output:
Original Amount – 5 Dollars 36 cents
Enter decrement amount – Enter the full dollar and cent amount 1.0
Decrement Test
Original Amount: $5.36
Amount to Subtract: 1.00
New Dollar Amount: 4.00
New Cent Amount: .36
New Full Amount: $4.36
Press any key to see the next test
Second Test:
Next Money Value: $4.02
Enter Increment amount ( with decimal for cents ).
Enter the full dollar and cent amount: 1.0
Second Test:
Original Amount – 4 dollars 2 cents
Increment test:
Amount to Add: 1.00
New Amount: $5.02
Press any key to see the next test…
Third Test – Input dollars and cents as separate values:
Enter Dollars: 3
Enter Cents as a whole number: 4
Full Dollar Amount:
Amount: $3.04
Press any key to see the next test…
Enter the full dollar and cent amount: 4.50
Dollars: 4
Quarters: 2
Dimes: 0
Nickels: 0
Pennies: 0
Press any key to see the next test…
Last test – Enter the monetary amount as a single value ( with decimal ):
Enter the full dollars and cent amount: 2.01
Dollars:2.00
Cents: .1
Amount: $2.01
Explanation / Answer
This below code will help you to solve the given probelem statement in C#. As of my knowledge i have present the below code. please let me know if it useful ..
public class Money
{
int dollars;
int cents;
public void incrementMoney()
{
}
public void decrementMoney()
{
}
Money(int dollars)
{
dollars = dollars;
cents = dollars;
}
Money(int dollars, int cents)
{
dollars = dollars;
cents = cents;
}
public string toString()
{
int quarter = cents / 25;
int dime = cents / 10;
int nickel = cents / 5;
int penny = cents;
return dollars + quarters + nickels + dimes;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.