Write a program to show the constructor overloading at the version of constructor in available in a class.

class OverLoad
  {
    int age, num1,num2,num3,sum,e,b,c;
    String name;
    OverLoad(String n,int a) //constructor
    {
      name=n;
      age=a;
    }
    void disp()
     {
      System.out.println("Name of the person  :"+name);
      System.out.println("age  of the person  :"+age);
     }
   
    OverLoad(int e,int b,int c)
    {
     num1=e;
     num2=b;
     num3=c;
    
    }
   
     void show()
     {
       int sum=num1+num2+num3;
       System.out.println("sum  =:"+sum);
     }
  public static void main(String args[])
    {
       OverLoad ob=new OverLoad("kapil" ,19);

      
       ob.disp();
       OverLoad ab=new OverLoad(4,5,6);
       ab.show();
    }
 }
     

     

A electricity board charges the following rates to domestic users to charge large consumption of energy. For first 100 units - 40paise/ unit , for next 200 units – 50paise/ unit , for next or beyond 300 units – 60paise /unit, if the total bill is more than Rs.250 then an additional charge of 15% is added to the bill. Write a program that read the names of the users and number of units consumed and print the charges with names.

class Charge
   {
     public static void main(String[] args)
      {
       float p;
       int units=Integer.parseInt(System.console().readLine("enter the units="));
       String userName=System.console().readLine("entr the user name=");
        if(units<=100)
          {
            p=units*.4f;
            System.out.println("rs="+p);
           }
          else
            {
             if((units>100)&&(units<=300))
             {
                p=(100*.40f)+((units-100)*.50f);
                System.out.println("rs="+p);
             }
            else
               {
                 p=(100*(40/100f))+(200*(50/100f))+((units-300)*(60/100f));
                 System.out.println("rs="+p);
               }
             }
          if(p>250)
             {
               p=p+p*(15/100f);
               System.out.println("Bill="+p);
             }
        System.out.println("userName="+userName+" & Bill="+p);
      }
  }

              
          

Create a class Calculator that has the following features: addition, subtraction, multiplication, division. Create another class named ScientificCalculator that will have the features of Calculator and some other features like: to find square, cube, power, factorial.... Note:Inheritance to complete this task.

class Calculator
  {
   public void calc()
    {
    int add, sub, mul, a, b;
    double div;
    a=Integer.parseInt(System.console().readLine("enter the first no.  :"));
    b=Integer.parseInt(System.console().readLine("enter the second no. :"));
    add=a+b;
    System.out.println("addition of two no.      ="+add);
    sub=a-b;
    System.out.println("substraction of two no.  ="+sub);
    mul=a*b;
    System.out.println("multiplecation of two no.="+mul);
    div=(double)a/b;
    System.out.println("division of two no.      ="+div);
   }
  }
class ScientificCalculator extends Calculator
{
   void scincalc()
   {
    System.out.println("****************values of ScientificCalculator******************");
   int n=Integer.parseInt(System.console().readLine("enter the  no.  :"));
   int sqr=n*n;
   System.out.println("Square  of the no.      ="+sqr);
   int cube=n*n*n;
   System.out.println("cube of the no.="+cube);
   int fact=1;
   for(int j=1;j<=n;j++)
      {
        fact=fact*j;
      }
    System.out.println("factorial of the no.="+fact);
   int d=Integer.parseInt(System.console().readLine("enter the power no.  :"));
   int pow=n;
   for(int i=1;i<d;i++)
     {
     
       pow=pow*n;
     }
  
    System.out.println("power of n to d is ="+pow);
   
  
  }
   public static void main(String args[])
    {
      ScientificCalculator ab=new ScientificCalculator();
      ab.calc();
      ab.scincalc();
      
    }
 }


 

Create a public class named conversion that will have following method:- dollartorupee(),rupeetodollar(),metertokilometer(),kilometertometer(), celsiustofarenhenite(),farehnitetoccelsius().

public class Conversion
 {
  void dollartorupee()
   {
    int doller=Integer.parseInt(System.console().readLine("how many doolor u have"));
    int rupees=doller*55;
    System.out.println("rupees ="+rupees);
   }
  void rupeetodollar()
   {
    int rupees=Integer.parseInt(System.console().readLine("how many rupees u have"));
    double doller=rupees*(1/55f);
    System.out.println("doller ="+doller);
   }
  void metertokilometer()
   {
    int meter=Integer.parseInt(System.console().readLine("meter="));
    double kilometer=meter*(1/1000f);
    System.out.println("kilomiter ="+kilometer);
   }
  void kilometertometer()
   {
    int kilometer=Integer.parseInt(System.console().readLine("kilometer="));
    int meter=kilometer*1000;
    System.out.println("meter ="+meter);
   }
  void celsiustofarenhenite()
   {
    int celsius=Integer.parseInt(System.console().readLine("celsius="));
    double farenhenite=celsius*(9/5f)+32;
    System.out.println("farenhenite="+farenhenite);
   }
  void farenhenitetoccelsius()
   {
    int farenhenite=Integer.parseInt(System.console().readLine("farenhenite="));
    double celsius=(farenhenite-32)*(5/9f);
    System.out.println("celsius="+celsius);
   }
 public static void main(String args[])
  {
    Conversion m=new Conversion();
    m.dollartorupee();
    m.rupeetodollar();
    m.kilometertometer();
    m.metertokilometer();
    m.celsiustofarenhenite();
    m.farenhenitetoccelsius();
  }
}
  
    

Write a program to LCM and HCF of two integers.

class HCM
 {
  int a,b,num,hcd,hcm;
  void lcm()
  {
   a=Integer.parseInt(System.console().readLine("enter the first no.="));
   b=Integer.parseInt(System.console().readLine("enter the 2nd   no.="));
  int m=a*b;
   if(a>b)
   {
     num=a;
   }
   else
   {
     num=b;
    }
  for (int i = 1; i <= num; i++)
     {
        if ((a%i==0) && (b%i==0))
           {
            hcd=i;            
            }
     
     }
         System.out.println("HCF="+hcd);
         hcm=m/hcd;
          System.out.println("LCM="+hcm);
}
public static void main(String[] args)
       {
        HCM ab = new HCM();
        ab.lcm();
        }
}