kirran

Friday, June 1, 2012

Write a java program to copy the value from variables of one object to another object.

Here I am going to create object t1 and I will copy the a and b values in t1 to t2 and t3.Let us see how it will be

 class Test {
   
    int a,b;
   
    void input()
    {
         a=10;
         b=12;
    }
   
    void output()
   
    {
         System.out.println(" a value is"+a);
         System.out.println("b value is "+b);
    }
   
    void  copy(Test x)
   
    {
        a= x.a;
        b = x.b;
       
        System.out.println(" a value is"+a);
        System.out.println("b value is "+b);
   
    }

    public static void main(String[] args) {
       
        Test t1 = new Test();
        t1.input();
        t1.output();
       
        Test t2 = new Test();
        t2.input();
        t2.copy(t1);
       
        Test t3 = new Test();
        t3.input();
        t3.copy(t2);
       
    }

}

output :

a value is10
b value is 12
 a value is10
b value is 12
 a value is10
b value is 12



Write a program  for current bill including SCNO,METERNO and additional charges.

 package ramam;

import java.util.*;

public class Currentbill {


        int SCNO,METERNO,xtra;
        double Billamount,adj,units,unitcost;
      
        String NAME,PLACE;
   
      
        void input()
        {
          
            System.out.println("APCPDCL");
            System.out.println("ELECTRICITY BILL");
          
            System.out.println("PLEASE ENTER YOUR SCNO,METERNO,UNITS");
            Scanner S = new Scanner(System.in);
          
          
            SCNO = S.nextInt();  
            METERNO= S.nextInt();  
            units = S.nextDouble();  
            unitcost = 3*units ;
          
            System.out.println("units cost is " +unitcost);
          
            Billamount = 0.00;
            adj = 0.00;
          
            NAME = "Ramanathan";
            PLACE = "LB NAGAR ";  
          
        }
      
      
    int  extra()
        {
            int ADDLCHARGES,ENERGYCHRGES,ED;
          
            ADDLCHARGES = 20;
            ENERGYCHRGES = 8;
            ED =0;
          
        return(ADDLCHARGES+ENERGYCHRGES+ED);
          
        }
      void output()
      {
          System.out.println(" your billamount is "+Billamount);
          System.out.println("your adj amount i"+adj);
          System.out.println(" Your unit cost is"+unitcost);
        

   
        
          System.out.println("EMPLOYEE NAME IS"+NAME);
          System.out.println("EMPLOYEE PLACE IS "+PLACE);
        
      }
     
   
   
     void TOTAL(int x)
     {
   
         System.out.println("extra AMOUNT" +x);
         System.out.println("TOTAL AMOUNT" +(Billamount+adj+unitcost+x));
     }
   
   
        public static void main(String[] args) {
          
             Currentbill C = new Currentbill();
          
            C.input();
            C.output();
            int x= C.extra();
   
            C.TOTAL(x);

        }

    }


 Output : 
 APCPDCL
ELECTRICITY BILL
PLEASE ENTER YOUR SCNO,METERNO,UNITS1223
1231
55
units cost is 165.0your billamount is 0.0
your adj amount i0.0
 Your unit cost is165.0
EMPLOYEE NAME ISRamanathan
EMPLOYEE PLACE IS LB NAGAR
extra AMOUNT28
TOTAL AMOUNT193.0

No comments:

Post a Comment