fork download
  1. //Money class
  2.  
  3. class Money
  4. {
  5.  
  6. //variable declarations
  7. int dollars,cents;
  8.  
  9. //constructor
  10.  
  11. public Money()
  12. {
  13. dollars=0;
  14. cents=0;
  15. }
  16.  
  17. //constructor with arguments
  18. public Money(int d,int c)
  19. {
  20. dollars=d;
  21. cents=c;
  22. }
  23. //increment method
  24.  
  25. public void incrementMoney(int d,int c)
  26. {
  27. dollars+=d;
  28. cents+=c;
  29. if(cents>=100)
  30. {
  31. dollars++;
  32. cents-=100;
  33. }
  34. }
  35.  
  36. //decrement method
  37. public void decrementMoney(int d,int c)
  38. {
  39. dollars-=d;
  40. cents-=c;
  41. if(cents<0)
  42. {
  43. dollars--;
  44. cents+=100;
  45. }
  46. }
  47.  
  48. //toString overload method
  49. public override string toString()
  50. {
  51. return dollars+"."+cents+" dollars";
  52. }
  53. }
  54.  
  55. //main class
  56.  
  57. class TestMoney
  58. {
  59. public static void main(String [] args)
  60. {
  61. Money m=new Money();
  62. m=new Money(5,25);
  63. Console.WriteLine(m.toString());
  64. m.incrementMoney(4,90);
  65. Console.WriteLine(m.toString());
  66. m.decrementMoney(2,25);
  67. Console.WriteLine(m.toString());
  68.  
  69. }
  70. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(49,24): error CS0115: `Money.toString()' is marked as an override but no suitable method found to override
prog.cs(59,25): error CS0246: The type or namespace name `String' could not be found. Are you missing `System' using directive?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty