JAVA PROGRAM TO ADD AMOUNT IN YOUR PIGGY BANK

/* suppose u have a piggie bank with an initial amount of $50 and u have to add some more amount to it .
 create a class "addamount" with an data member named "amount" with an initial  value of $50 . now make two constructor of this class--
1. without any parameter--no amount will be added to the piggie bank.
2.  having a parameter which is the amount will be added to piggie bank.
then , create object of addamount class and display final amount in piggie bank...
*/

PROGRAM CODE----

import java.util.Scanner;class AddAmount {   double amount=50.0;    public AddAmount (){   amount=50.0;}    public AddAmount (double a){   amount=50.0+a;}
void show(){    System.out.println("total amount is "+amount);}}
class TotalAmount{     double extra_amount;   public static void main(String a[]){
    Scanner ob= new Scanner(System.in);     System.out.println("enter value if u want to add in your piggy bank");


       double extra_amount = ob.nextDouble(); AddAmount  amt= new AddAmount(extra_amount);      amt.show();}
}


 OUTPUT OF ABOVE PROGRAM--



ABOUT ::



  • IN THIS PROGRAM, YOU HAVE A PIGGY  BANK WITH 50 RUPEES... 
  • ASK THE USER ,, ABOUT HOW MANY RUPEES THEY  WANT TO ADD IN PIGGY BANK .THEN,,,ADD MONEY IN TO PIGGY BANK AND PRINT TOTAL AMOUNT..







Comments