Turn Desktop View Off
by Dinesh Thakur

 

import java.io.*;

           class addr
              {
                   int qt;
                  float pr;
                  void addition(stockadd  m, stockadd n)
                    {
                         qt=m.qty+n.qty;
                         pr=m.price+n.price;
                         System.out.println("Total quantity is :"+qt);
                         System.out.println("Total price is:"+pr);
                    }
              };
                        class stockadd
                           {
                               BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
                               String h;
                               int qty;
                               float price;
                               stockadd()
                               throws IOException
                                    {
                                         System.out.println("Enter Quantity  ");
                                         h=bf.readLine();
                                         qty=Integer.parseInt(h);
                                         System.out.println("Enter price  ");
                                         h=bf.readLine();
                                         price=Float.parseFloat(h);
                                    }
                                          void showdata()
                                              {
                                                   System.out.println("Quantity :"+qty);
                                                   System.out.println("price  :"+price);
                                              }
                                                    public static void main(String args[])throws IOException
                                                        {
                                                             System.out.println("Enter details of first stock : ");
                                                             stockadd u=new stockadd();
                                                             System.out.println("Enter details of second stock : ");
                                                             stockadd v=new stockadd();
                                                             System.out.println("The detail of first stock is :");
                                                             u.showdata();
                                                             System.out.println("The details of second stock is :");
                                                             v.showdata();
                                                             System.out.println("The details of stock after addition is:");
                                                             addr w=new addr();
                                                             w.addition(u,v);
                                                         }
                         }

Adding the Contents of Two objects by passing objects as parameter.