Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

OOP, OOPS Concept in Java:-

Object-oriented programming structure, It is used to create real-world based applications using dynamic memory allocation, security, reusability, and extend-ability features.



Rules for OOP'S:-

1 Class and Object:-

Class:-   It is used to define the characteristics of an object using data member and member function.

we can define multiple objects definitions using a class but all objects should be related to each other.

class Classname
{
      Data member;

      Member Function;

       Constructor;

       Static Block;

       Initializes block;

       Property;

       class Classname{}

       Object
 

}


Object:-  

It is a real-world entity that has an identity, state, and behavior. for example, Electronics is the class
 which has multiple objects such as Laptop, Mobile, Television, Camera, etc.


How We Create Real-world Java Program?


1  Business Class:- this class contain only object definition


2 Executable Class:- 
 this class contains main() to call any other class object.


Program Explanation Of Student Class:-

Business Class:-

import java.util.Scanner;
class Student
{
   int no;
   String sname;
   Scanner sc = new Scanner(System.in);
   void accept()
   {
      System.out.println("enter rno");
      rno=sc.nextInt();
      System.out.println("enter name");
      sname=sc.next(); 
       

   }
   void display()
   {
       System.out.println("rno is "+rno);
       System.out.println("name is "+sname); 
   }

}


Executable Class:-


class StudentMain
{
    public static void main(String args[])
    {
        Student obj = new Student();
        obj.accept();
        obj.display();
        Student obj1 = new Student();
        obj1.accept();
        obj1.display();     

    }

}

For Multiple Object using Student Object Array:-
 

import java.util.Scanner;
class Student
{
   int no;
   String sname;
   Scanner sc = new Scanner(System.in);
   void accept(int rno, String sname)
   {
      this.rno=rno;
      this.sname=sname;
    }
   void display()
   {
       System.out.println("rno is "+rno);
       System.out.println("name is "+sname); 
   }

}


 
class StuMain
{
    public static void main(String args[])
    {
        int num,r;
        String n;
        System.out.println("enter number of students");
        Scanner sc = new Scanner(System.in);
        num=sc.nextInt();        
        Student obj[]= new Student[num];
        for(int i=0;i<num;i++)
        {
             System.out.println("Enter element for "+i+" index");
             obj[i]=new Student();
             System.out.println("enter rno");
             r=sc.nextInt();
             System.out.println("enter name");
             n=sc.next();
             obj[i].accept(r,n);
            
        }
        System.out.println("Student information is ");
       for(int i=0;i<num;i++)
       {
            obj[i].display();
       }

    }

}



ASSIGNMENT:-

CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY.

MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENTS AND FIND MAX 
OBTAINED MARKS,  Aggregate marks.

Solution 

import java.util.Scanner;
class Marks
{

   int mark[];
   float per=0,total;
   String sub[];
   void enterSubjectMarks(String sub[],int mark[])
   {
        this.sub = sub;
        this.mark = mark;
        
 
   }

   void calculateMarks()
   {
     for(int i=0;i<mark.length;i++)
      {
          total = total+mark[i];
      } 
      per = total/mark.length;
      System.out.println("Percentage is "+per);

   }

  

   


}


class MainMark
{

    public static void main(String args[])
    {
       Scanner sc = new Scanner(System.in);
       String sub[] = {"physics","chemistry","maths","english","hindi"};
       System.out.println("Enter number of students");
       Marks obj[] = new Marks[sc.nextInt()];
       float ag=0;
       for(int i=0;i<obj.length;i++)
       {
             obj[i] = new Marks();
             int marks[] = new int[5];
            
             System.out.println("Enter Record for student " + (i+1));
             for(int j=0;j<5;j++)
             {
                     System.out.println("Enter marks for "+sub[j]);
                     marks[j] = sc.nextInt();

             }  
            obj[i].enterSubjectMarks(sub,marks);
            obj[i].calculateMarks(); 
            ag+=obj[i].per;
            

       }   
       System.out.println("Agreegate pecentage is " + ag/obj.length);
    }


}

Q ATM Program with unlimited users, first admin add users with pin, amount and account then user module loaded ask pin three times and perform all operation.

Customer Class

import java.util.Scanner;
class Customer {
  int pin;
  int amount;
  String account;
  void accept(int pin,int amount, String account)
  {
  this.pin=pin;
  this.amount=amount;
  this.account=account;
  }
  
  
}


class Bank {

public static void main(String[] args) {
int num,p,a;
String account1;
System.out.println("Welcome in Admin Module");  
System.out.print("Enter number of users");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
Customer cust[] = new Customer[num];
for(int i=0;i<num;i++)
{
System.out.print("Enter pincode");
p=sc.nextInt();
System.out.print("Enter amount");
a=sc.nextInt();
System.out.print("Enter account");
account1=sc.next();
cust[i] = new Customer();
cust[i].accept(p, a, account1);
}
System.out.println("Welcome in Customer module");
boolean b=false;
int custindex=0;
               
                for(int j=0;j<3;j++)
                {
                    
                System.out.print("Enter pincode");
int pin=sc.nextInt();
System.out.print("Enter account");
String ac=sc.next();
for(int i=0;i<num;i++)
{
                        
//System.out.print(cust[i].pin + " "+cust[i].account);
if(cust[i].pin == pin && cust[i].account.equals(ac))
{
b=true;
custindex=i;     
break;
}
}

               if(b)
               break;

               }
               
if(b)
{
while(b)
{
System.out.println("\nPress c for Credit \n Press d for Debit \n 

Press b for Check balance \n Press e for exit");
char ch = sc.next().charAt(0);
switch(ch)
{
case 'c':
System.out.println("Enter amount for credit");
cust[custindex].amount+=sc.nextInt();
break;
case 'd':
System.out.println("Enter amount for debit");
cust[custindex].amount-=sc.nextInt();
break;
case 'b':
System.out.println("Current balance is ");
System.out.print("Balance is "+cust[custindex].amount);
break;
case 'e':
System.exit(0);
}
}
}
else
{
System.out.println("Invalid Pin code and Account no, all attempt 

completed");
}
               
             

}

}


Component of Class in Java:-

1 Data member or Variable:-

It is called variable and constant of class, it is used to declare attribute of Object 
We can declare two different types of the attribute, class type attribute will be declared by static data members of the class.
The instance attribute will be declared by the dynamic data members of the class.

Static Data Member:-

It will allocate memory at compile-time and declare by static keyword. Static Data Member will be called by Classname.

static datatype variable-name = value

it is used to create a shared variable for multiple users in real-world applications.

all local variables which will be declared under main() or any other static method then it will be static.

if we want to declare a global static variable underclass then we use the static keyword.

static datatype identifier=value;

static int x=100;


class Staticdemo
{
   static int x=10;   //global static
   static int y=20;
   public static void main(String args[])
   {
      int z=22;      //local static
      x=100;
       
      System.out.println(x+y);

   } 



}

class StaticExample
{
    static int x,y,z;
    static void addition()
    {
           x=100;
           y=200;
           z=x+y;
           System.out.println(z);
    }

    public static void main(String args[])
    {
          addition();

   }

}

Static Example With Different Class:-

class Staticdemo
{
   static int x=10;
   static int y=20;
   


}

class StaticMain
{
public static void main(String args[])
   {
      int z=22;
      Staticdemo.x=100;
       
      System.out.println(Staticdemo.x+Staticdemo.y);

   } 

}





Another Example of Static:-

class StaticExample
{
    static int x=100,y=209,z;
    static void addition()
    {
          
           x=100;
           y=200;
           int x=20;
           z=x+y;
           System.out.println(z);
    }

   

}

class StaticMain
{
     public static void main(String args[])
    {
          StaticExample.addition();
           System.out.println(StaticExample.x);

     }


}

2  Instance variable or Dynamic variable or non-static variable:-


This type of variable will allocate memory at run time and it will be called by Object.

If we want to allocate different memory for different user's then we use the instance variables.

class Classname
{
      datatype identifier;
      

}


when we declare any variable under the instance method or underclass then it will be a dynamic variable. static keyword not allowd under instance method.


class A
{
      int x,y;

}


Explanation by program 

class DynamicDemo
{
    int x,y;
    public static void main(String args[])
    {
        DynamicDemo obj = new DynamicDemo();
        obj.x=100;
        obj.y=200;
        System.out.println(obj.x+obj.y);

    }   


}

Another Example:-

class StaticExample
{
     int x=100,y=209,z;
     void addition()
    {
          
           x=100;
           y=200;
           int x=20;
           z=x+y;
           System.out.println(z);
    }

   

}

class StaticMain
{
     public static void main(String args[])
    {
          StaticExample ram = new StaticExample();
         
          ram.addition();
           System.out.println(ram.x);

          StaticExample shyam = new StaticExample();
          
          shyam.addition();
          shyam.x=300;
           System.out.println(shyam.x);

     }


}

2 Member function or Method:-

Member function or method both are the same according to object orientation terminology we will tell member function to the method.


It is used to define data members of a class using the member function. if data member will be static
then we create a static member function and if data members will be dynamic then we will create a dynamic member function.

because we should never access data members directly, it should be defined by member function for security concern.


class A
{
   static int a,b=3,c; //static,class
   int x=10,y=20,z;  //instance,dynamic
   static void additionFunction()
   {
        a=1000;
        b=2000;
        c=a+b;
        System.out.println(c);
   } 
   void subFunction()
    {
        x=100;
        y=200;
        z=x-y;
        System.out.println(z);
        
    }
   public static void main(String ram[])
   {
       A obj= new A();  //new --> dynamic memory allocation 
       obj.additionFunction();
       obj.subFunction();
       
   }

}


type of member function:-



1 static member function


   static returntype methodname()
   {

   }


it will be called by Class name

Complete Explanation of static component of class:-

class StaticDemo
{
    private static int x,y;
    static void addition()
    {
       x=100;
       y=200;
       System.out.println(x+y);

    }  
    

}

class Staticmain
{
   public static void main(String args[])
    {
          StaticDemo.addition();
        

    }   


}

common interview question for the static method:-


when we call static data member or static member function using object then what will be the output?


It will be successful to compile and execute and provide proper output but data not assigned into runtime memory it will be assigned into compile-time memory. it is not the prefered way to call static because unwanted memory will be created.














2 dynamic member function
  
   returntype methodname()
   {

   }

It will be called by the object

Example of dynamic:-
class DynamicDemo
{
    private int x,y;
    void addition()
    {
       x=100;
       y=200;
       System.out.println(x+y);

    }  
    public static void main(String args[])
    {
        DynamicDemo obj = new DynamicDemo();
        obj.addition();
        

    }   


}

Type of Member Function According to Parameters:-

1 Default:-


We can not pass any value from the calling function to the called function. Input will be defined under the function block.


Type of Default Function:-

1.1 With Return Type:-

it will return output data that can be used by any other program.

AccessSpecifier Datatype  Methodname()
{
  
       return  output;

}

public int fun()
{
    return 10;
}


public static int  fun()
{
    return 10;
}


1.2 Without Return Type:-

We can not return any output data from the calling function to called function.

Input and output both will be defined under the function block.


acessspecifier  void functionname()
{


}


public void fun()
{
   int a=100;
   int b=200;
  System.out.println(a+b);

}

public static void fun()
{
    int a=100;
   int b=200;
  System.out.println(a+b);
}



2 Parametrized:-

using this we can pass value from calling function to called function using a parameter.

parameter identifier is called arguments.


With Return Type:-

accessspecifier  returntype methodname(datatype arguments)
{


}

Without Return Type

access specifier  void method name(datatype arguments)
{


}


Complete Explanation of Method:-


class MethodExample
{
    int a,b;
    void fun1()
    {
       a=10;
       b=20;
       System.out.println(a+b);
        
    }

    int fun2()
    {
         a=100;
         b=20;
         return a-b;

    } 
    void fun3(int a,int b)
    {
         System.out.println(a+b);
    } 
   
    int fun4(int a,int b)
    {
         return a+b;
    } 


}

class Methodmain
{
   public static void main(String args[])
   {
        MethodExample obj = new MethodExample();
        obj.fun1();
        int res = obj.fun2();
        System.out.println(res); 
        obj.fun3(100,20);
        int res1 = obj.fun4(100,2);
        System.out.println(res1); 
           

   }


}


Example of Static and Dynamic member function in Single Class:-

class MF
{
   private static int a,b;
   private int x,y;
   
   static void addition()
   {
       MF o = new MF();
       a=100;  
       b=200;
       o.x=100;
       o.y=200;
       System.out.println("static addition"+(a+b));
       System.out.println("dynamic addition"+(o.x+o.y));
      
   } 
    void sub()
   {
    
       MF.a=10;  
       MF.b=20;
       x=100;
       y=200;
       System.out.println("static addition"+(MF.a+MF.b));
       System.out.println("dynamic addition"+(x+y));
      
   } 

  


}
class MFMain
{
     public static void main(String args[])
     {
       MF.addition();
       MF obj2 = new MF();
       obj2.sub();
       
     }

} 




How to pass an array as a parameter and return multiple values in java?

class Ope
{
  int sum; 
  
   void add(int a[])    //param array
   {
        sum=0;
        for(int s:a)
        {
           sum+=s; // sum = sum+s
        } 
        System.out.println(sum);
   } 
   int[] divide()   // multiple value return
   {
        int arr[] = {3,4,5,6,6,7,8,9};   
        return arr;
   } 


}


class OpeMain
{
    public static void main(String ram[])
    {
         Ope obj = new Ope();
         int arr[] = {2,3,4,5,56,67,89};
         obj.add(arr);
         int arr1[] = obj.divide();
         for(int i:arr1)
         {
                 System.out.println(i);
         }
        

    }

}


2) Parametrized Jagged Array Example?

import java.util.Scanner;
class A
{
   void jArr(int arr[][])
   {
         for(int i=0;i<arr.length;i++)
         {
             for(int j=0;j<arr[i].length;j++)
             {
                      System.out.print(arr[i][j] + " ");
             }
            System.out.println();         

         }
   }

}


class Amain
{
    public static void main(String args[])
    {
        int arr[][]=new int[2][];
        arr[0] = new int[5];
        arr[1] = new int[2];
        for(int i=0;i<arr.length;i++)
         {
               for(int j=0;j<arr[i].length;j++)
                 {
                      System.out.println("Enter element for "+i+j+ "index");
                      arr[i][j]=new Scanner(System.in).nextInt();
                 }

         } 
       
        A obj = new A();
        obj.jArr(arr);

    }

}



Assignment:-

1) WAP to perform addition and matrix multiplication using param array with return type?

2) WAP to count total prime elements on the jagged array and show max prime elements using param array with return type

Solution of Jagged Array:-

public class ParamJaggedArray {
int c=0;
int max=0;
void checkPrime(int arr[][])
{
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr[i].length;j++)
{
int k;
for(k=2;k<arr[i][j];k++)
{
if(arr[i][j]%k==0){
break;
}
}
if(arr[i][j]==k) {
if(max<arr[i][j])
{
max=arr[i][j];
}
System.out.println(arr[i][j] + " ");
}
}
}
System.out.println("Max is "+max);
}

public static void main(String[] args) {
ParamJaggedArray obj = new ParamJaggedArray();
int arr[][] = {{1,2,3},{6,8},{23,67,12}};

obj.checkPrime(arr);
}
}


3 Constructor:-

It is used to initialize dynamic data members of a class, Constructor name, and class name will be the same.

A constructor has no user define a return type, it will be the return address of class type.

when we compile any class then the constructor block will be created automatically.

Actual class:-

class A
{


}

After compilation

class A
{
     A()
    {


   }

}

Note:-  Default Constructor by default present into class. it will be called when we create an Object.


TYPE   OF CONSTRUCTOR:-

1)  Default or no parameter:-

    The default constructor has also two different type

   1)  Class type default Constructor or implicit default

   2)  User define default Constructor

    we can not pass any value from an object

2) Parameterized constructor

   we can pass parameters using object

   2.1)  One parameter, Two Parameters,...

  2.2)   Reference param or Object Param,.......

Example of Constructor with the complete program:-

class ConsDemo
{
   int a,b;
   ConsDemo()
   {
      a=100;
      b=200;
   }  
  ConsDemo(int a,int b)
   {
       this.a=a;
       this.b=b;
   }  

   ConsDemo(ConsDemo obj)
   {
       this.a=obj.a;
       this.b=obj.b; 

   } 
   void display()
   {
      System.out.println(a*b);
   }

}
class ConsMain
{
     public static void main(String args[])
     {
          ConsDemo obj = new ConsDemo();
          obj.display();
          ConsDemo obj1 = new ConsDemo(10,20);
          obj1.display();
          ConsDemo obj2 = new ConsDemo(obj1);
          obj2.display(); 

      }


}


Another Example of Constructor:-

class Consdemo
{
     int a;
     Consdemo()
     {
         a=2;
     } 
     Consdemo(int a)
     {
        this.a=a;
     }

    Consdemo(Consdemo obj)
    {
       this.a=obj.a;

    }
    void displaySquare()
    {
        System.out.println("square is "+a*a);
    }

public static void main(String args[])
{
    Consdemo obj = new Consdemo();
    obj.displaySquare();
    Consdemo obj1 = new Consdemo(12);
    obj1.displaySquare();
    Consdemo obj2 = new Consdemo(obj1);  //obj2=obj
    obj2.displaySquare();
    
}

}


Another Example using a static variable:-

 
4 Static Block:-

It is used to initialize static data members of the class. The static block will be called before main() but the constructor will be called after main()  when we create an object.

static block is also called an anonymous block on Java program?



class StaticBlockExample
{
   static int a,b;
   static
   {
      a=100;
      b=200; 
      System.out.println("Static Block");

   }
   static void display()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
      StaticBlockExample.display();
   
   } 



}


Another Program of Static Block to UnderStand:-

class Stblock
{
    static int a=10;
    static
    {
      a=5;
    }
    public static void main(String args[])
    {
       System.out.println(a);
    }
     static
    {
      a=1;
    }
}
 


5 Init Block:-

This block is used to initialize any data member before the constructor means if the program has a static block, constructor, and init block then the first static then main(), init, and after that constructor will be called.


Complete Program with an explanation of StaticBlock, Init, Constructor, and main()

Init block will never call without object creation because it will always call before the constructor.


class StaticBlockExample
{
   static int a,b;
   int x,y;
   {
       System.out.println("INIT");
      x=10;
      y=20;
   }
   StaticBlockExample()
   {
      System.out.println("CONSTRUCTOR");
      System.out.println(x+y);
   }
    

   static
   {
      a=100;
      b=200; 
      System.out.println("Static Block");

   }
   static void display()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
      System.out.println("Main");
      //StaticBlockExample obj = new StaticBlockExample();
     // StaticBlockExample.display();
   
   } 



}


Example of Init Block and Constructor:-

class A
{
  int a,b;

  {
     a=100;
     b=200;
     
   }
   
   A()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
       A obj = new A();
   }

   
  {
     a=10;
     b=20;
    

  }

}


.....................................................................................................................................


Another Program for Static Block, Init Block, Constructor?


class Stblock
{
    static int a=10;
    int b=200;
    Stblock()
    {
      System.out.println("Default Constructor"+b);
    }
    {
         b=5;
    }
    static
    {
      a=5;
    }
    public static void main(String args[])
    {
       System.out.println(a);
       Stblock obj = new Stblock();
      
    }
     static
    {
      a=1;
    }
}



6 Properties

7 Inner class

8 Object





2 Data Abstraction and Data Encapsulation:-

Abstraction means Data hiding, it is used to hide non-essential details and show only essential details in an application.

Abstraction is used to provide security and accessibility options in the project.

In Java programming language we can implement data abstraction using three different ways.

1) Using Access Specifier:-

1.1 private:-  it is used to provide accessibility only in the same class. we can not access private data members into another class in the same package and different packages.

class A
{
   private int a;
   private void fun()
   {

   }

}
note:-  outer class never will be private in java because the class-default scope is the "default" modifier.




1.2 default:- 

 it is used to provide accessibility in the same package all classes.

  int b;
  void fun1()
  {

  }

if we do not write any access modifier then "default" will be considered



3 protected:-  


it can be accessed in other package classes but inheritance is required. without inheritance, it is similar to the default.

protected int a;
protected void fun2()
{

}

4 public:- it can be accessed in other projects and the cross packages also, it has more strength as compared to other access specifiers.

  public int a;
  public void fun3()
  {

  }


2) Using Abstract Class


3) Using Interface


Data Encapsulation:- Binding of data in a single unit, encapsulation is used to protect the direct accessibility of data members, it provides accessibility of data members using member function.



class A
{
    public int a=10,b=20;  //not encapsulated
     int a=100,b=200;    // wrong 
   
}
class A
{
    private int a,b;  //encapsulation
    void fun()  //fun() encapsulate a and b
    {
     a=10;
     b=20;
    }


}


note:-  these rules of oops is used to provide security and accessibility option in the program.


Live example of ATM Operation using data abstraction and data encapsulation:-

import java.util.Scanner;
class Bank
{
   int bal=5000;
   Scanner sc  = new Scanner(System.in);
   private void credit(int amt)
   {
      bal+=amt;  
 
   }

   private void debit(int amt)
   {
      bal-=amt;
   }

   private void checkbalance()
   {
       System.out.println("balance is "+bal);
   }
   
   private int accept()
     {
         System.out.println("Enter amount");
         int amt = sc.nextInt();
         return amt;
     }

   void login(int pin)
   {
       if(pin==1234)
        {
            while(true)
            {
          System.out.println("press c for credit \n press d 

for debit \n press b for balance \n press e for balance");
            char ch = sc.next().charAt(0);
            switch(ch)
            {
            case 'c':
            credit(accept());
            break;
            case 'd':
            debit(accept());
            break;
            case 'b': 
            checkbalance();
            break;
            case 'e': 
            System.exit(0);
            break;
            default:
            System.out.println("wrong choice");
            break; 
            }
            }

        }

   }
   

}


class Customer
{
   public static void main(String args[])
   {
         Bank obj = new Bank();
      // obj.credit(1200);
         System.out.println("Enter pin code");
         int pin = obj.sc.nextInt();
         obj.login(pin);
   }

}

Polymorphism:-


Poly means many and "morphism" means forms using this we can increase the usability of function and operator in the program.

Polymorphism is used to provide overloading and overriding features.

Java does not support operator overloading because we can not re-define the operator definition.


We can reduce the extra memory space of the program using polymorphism.


Type of Polymorphism:-

1 Static Polymorphism:-  it will perform the operation at compile time hence it is also early binding.

1.1 function overloading:-

We will create the same name function only the parameters will be different, constructor is the best example of function overloading,

println() is the best example of function overloading.

package p1;

public class Operation {
  void add(int a,int b)
  {
      System.out.print(a+b);
  }
  void add(int a,float b)
  {
      System.out.print(a+b);
  }
  void add(float a,int b)
  {
      System.out.print(a+b);
  }
  void add(float a,float b)
  {
      System.out.print(a+b);
  }
  public static void main(String args[])
  {
      Operation obj = new Operation();
   //   obj.add(100,200);
     obj.add(100.2F,200.2F);
  }
}

2 Dynamic Polymorphism:-  it will perform the operation at runtime using inheritance.

2.1 function overriding


Create the Same name method from base class to derived class only functionality will be different.

note:-  function name  and return type should be the same from base class to derived class 

class A
{
    void fun()
    {

    }

}
class  B extends A
{
  void fun()  //correct
    {

    }
 
  int fun()  //wrong
    {

    }




1 using Abstract class:-  

We have been discussed this topic below.


2 using interface:-   

We have been discussed this topic below. 


3 using normal class


A complete example of Overriding:-

class Exam
{
   public void boardInfo()
   {
         System.out.println("RGPV");   
   }
   public void examPattern()
   {
        System.out.println("Number System");
   }

}
class Examnew extends Exam
{
   public void examPattern(String s)
   {
        System.out.println("Grade System"+s);
   }
   public void examPattern()
   {
         System.out.println("Grade System");
   }

    public static void main(String args[])
     {

        // Exam obj = new Examnew();
        // Exam obj = new Exam();
         Examnew obj = new Examnew();
         obj.boardInfo();
         obj.examPattern();
      }

}






Program Explanation:-
................................................................................................................................

class SI
{
    float p,r,t,si;
    void accept(float p,float r,float t)
    {
        System.out.println("FLOAT,FLOAT,FLOAT"); 
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,int r,int t)
    {
        System.out.println("INT,INT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,float r,int t)
    {
        System.out.println("INT,FLOAT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,float r,float t)
    {
        System.out.println("INT,FLOAT,FLOAT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(float p,int r,int t)
    {
        System.out.println("FLOAT,INT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }

    void calcsi()
    {

        si = (p*r*t)/100;
    }
    void add()
    {
       si = (p+r+t);
    } 

    void display()
    {

       System.out.println(si);
    } 

}
class SIMain
{
     public static void main(String args[])
     {
        SI obj = new SI();
        obj.accept(2,35.45F,4);
        obj.calcsi();
        obj.display(); 
       
     }



}


...............................................................................................................................................................


Class and Object Related Program to Calculate Simple Interest?
.......................................................................................................................
class SI
{
    float p,r,t,si;
    void accept(float p,float r,float t)
    {
        this.p=p;
        this.r=r;
        this.t=t;
    }

    void calcsi()
    {

        si = (p*r*t)/100;
    }
    void add()
    {
       si = (p+r+t);
    } 

    void display()
    {

       System.out.println(si);
    } 

}
class SIMain
{
     public static void main(String args[])
     {
        SI obj = new SI();
        obj.accept(12000.2F,2.2F,2.2F);
        obj.calcsi();
        obj.display(); 
        SI obj1 = new SI();
        obj1.accept(12000.2F,2.2F,2.2F);
        obj1.add();
        obj1.display(); 

     }


}

..............................................................................................................................................................

Inheritance:-
.............................................................................................................................................................

It means re-usability, using this concept of oops we can adopt the features of the base(parent) class to derived(child) class and reduces common code from an application.

Type of Inheritance:-


1 Single:-  Base class to derived class

Base   class or Parent class both will be the same


Derived class or Child class both will same.


2 Multilevel:-    Base class to derived class to sub derived


Base


Derived


Sub-Derived



3 Hierarchical:-     

it will provide inheritance using tree structure from base class to subderived1,subderived2

                                                          Base


          Derived1                                                             Derived2






Example of Single Inheritance:-

class Admin
{
    int aid;
    String aname; 
    void accept(int aid, String aname)
    {
       this.aid = aid;
       this.aname=aname;

    }
    void display()
    {
       System.out.println("aid "+aid+" name is "+aname);

    }

}

class Employee extends Admin
{
     int salary;
     void accept1(int salary)
     {
        this.salary=salary;
     }
     void display1()
     {
       System.out.println("Salary is "+salary);
     }

}

class EmpMain
{
    public static void main(String args[])
    {
       System.out.println("Employee Info");
       Employee obj = new Employee();
       obj.accept(1001,"emp");
       obj.accept1(12000);
       obj.display();
       obj.display1();
       System.out.println("Admin Info");
       Admin obj1 = new Admin();
       obj1.accept(1000,"admin");
       obj1.display();
       

    }


}


Practical Explanation of Multilevel Inheritance using Admin---> EMP--->  OtherStaff?




public class Admin {
int aid;
String sname;
void accept(int aid,String sname)
{
    this.aid=aid;
    this.sname=sname;
}
void display()
{
    System.out.print("id is "+aid);
    System.out.print("name is "+aid);
}

}
 


......................................


public class Employee extends Admin {
int salary;
void accept1(int salary)
{
    this.salary=salary;
   
}
void display1()
{
    System.out.print("Salary is "+salary);
   
}

}
.....................................


public class OtherStaff extends Employee{
    int bonus;
    void accept2(int bonus1)
    {
        bonus=bonus1;
    }
    void display2()
    {
        System.out.println("Bonus is "+bonus);
    }
   

}
EmpMain Class for Accessbility:-


package p1;

public class EmpMain {

    public static void main(String[] args) {
       
        System.out.println("Employee Information");
        //Employee obj = new Employee();
        OtherStaff obj= new OtherStaff();
        obj.accept(1001,"manish kumar");
        obj.accept1(12000);
        obj.display();
        obj.display1();
        System.out.println("\nAdmin Information");
        //Admin obj1 = new Admin();
        //Employee obj1 = new Employee();
        OtherStaff obj1= new OtherStaff();
        obj1.accept(1000, "admin");
        obj1.display();
       
        System.out.println("\nOtherStaff Information");
        OtherStaff obj2 = new OtherStaff();
        obj2.accept(1002, "other staff");
        obj2.accept1(6000);
        obj2.accept2(100);
        obj2.display();
        obj2.display1();
        obj2.display2();
       

    }

}
 


Example of Hierarchical Inheritance:-


Admin is the base class and it has two different subclasses, Employee and other staff.


Practical Explanation of Admin Base Class, Employee Derived Class, and Other Staff derived class.




public class Admin {
int aid;
String sname;
void accept(int aid,String sname)
{
    this.aid=aid;
    this.sname=sname;
}
void display()
{
    System.out.print("id is "+aid);
    System.out.print("name is "+aid);
}

}
 


......................................


public class Employee extends Admin {
int salary;
void accept1(int salary)
{
    this.salary=salary;
    
}
void display1()
{
    System.out.print("Salary is "+salary);
    
}

}
.....................................


public class OtherStaff extends Admin{
    int bonus;
    void accept2(int bonus1)
    {
        bonus=bonus1;
    }
    void display2()
    {
        System.out.println("Bonus is "+bonus);
    }
    

}

....................................................................................................................................
Main Class Code in Java:-


public class EmpMain {

    public static void main(String[] args) {
        
        System.out.println("Employee Information");
        Employee obj = new Employee();
      
        obj.accept(1001,"manish kumar");
        obj.accept1(12000);
        obj.display();
        obj.display1();
        System.out.println("\nAdmin Information");
        //Admin obj1 = new Admin();
        //Employee obj1 = new Employee();
        OtherStaff obj1= new OtherStaff();
        obj1.accept(1000, "admin");
        obj1.display();
        
        System.out.println("\nOtherStaff Information");
        OtherStaff obj2 = new OtherStaff();
        obj2.accept(1002, "other staff");
      
        obj2.accept2(100);
        obj2.display();
    
        obj2.display2();
        

    }



ASSIGNMENT  OF INHERITANCE?


Area of Triangle, Rectangle, Circle using possible Inheritance?


Class Addition, Subtraction, Multiplication, Division using possible Inheritance?


Abstract class in Java:-
............................................................................................


It is the special class of JAVA which is used to contain a set of abstract methods to hide actual details.

we can not create an object of an abstract class, it will be extended by Child class.

abstract class use function overriding by default because all abstract methods must be defined.
we will use the abstract keyword to declare an abstract class and abstract method.

abstract method:-   "it is the special method in java which has the only declaration, it does not contain method body"

the abstract method only will be declared under abstract class and interface in java.




Syntax of Abstract Class:-

 abstract class Classname


       static variable;   
      instance variable;
       abstract access-specifier return-type method-name();
       accessspecifier returntype methodname()
      {

      }
     
   main();

}


 We can create the only reference for abstract class, not object.


note:-  abstract class contain main() but we can not create an object of abstract class but another class object can be created.






Advantage of an abstract class:-

1)  Data abstraction:-   abstract class provides class-level data abstraction.


2) Data Contract:-  all methods of an abstract class must be defined by the child class. it is used to provide a high-level design approach for project development.



Simple Example of Abstract class:-

package scsbranch1;

abstract class Ope {
abstract public void add();
abstract public void multi();

}

class Operation extends Ope
{

@Override
public void add() {
// TODO Auto-generated method stub
}

@Override
public void multi() {
// TODO Auto-generated method stub
}
}


Example of Abstract class:-


abstract class Bank
{
     String s;
     public void info()
     {
       s="SBI";
       System.out.println("welcome in "+s);
     }
     abstract void credit(int amt);
     abstract void debit(int amt);
     abstract void checkbalance();     

}


class BankTransaction extends Bank
{

void checkbalance()
{
System.out.println("balance ");
}

void debit(int amt)
{
System.out.println("debit amount is "+amt);
}

void credit(int amt)
{
System.out.println("credit amount is  "+amt);
}

public static void main(String args[])
{
  // Bank obj = new BankTransaction();  //ok

     BankTransaction obj = new BankTransaction();  //ok

//    Bank obj = new Bank();   // not ok
  
   obj.info();
   obj.credit(12000);

}
  
}

Another Example of Abstract class?

for example, if we want to create a device then how many features will be implemented in the Mobile class that will be declared by Abstract class and it must be implemented by Child class.


abstract class MyDevice
{
   void deviceInfo()
    {
      System.out.println("welcome in mobile device ");
    }
   abstract void camera();
   abstract void multimedia();
   abstract void calling();

}


class Mobile extends MyDevice   //concrete class
{
void calling()
{
System.out.println("calling ");
}
void multimedia()
{
System.out.println("multimedia");
}

void camera()
{
System.out.println("camera ");
}
public static void main(String ar[])
{

  MyDevice obj = new Mobile();
  obj.calling();
  obj.multimedia();

}
}

An abstract class is used to implement a design pattern in java project where we use the top layer, middle layer, and user layer, top layer is used to declare a set of methods and the middle layer will implement it that can be possible with abstract class and interface.




.....................................................................................................................................................................
Final Class:-
.....................................................................................................................................................................

This is a special class that can not be inherited.

final class A
{

}

class B extends A  //error because the final can not be inherited
{

}

Note:-  final is the modifier of Java which is used to restrict the variable to override value, restrict method from function overriding, and restrict class for inheritance.


final int a=10;
final void display()
{

}



a final variable can not be overridden, a final method can  not be override and final class can not be inherited




Interface:-

It is a pure abstract class because Interface only contains a set of abstract methods.

but now interface some features have been modified now we can write the default method and static method under the interface.



this feature has been added in JDK 1.8.


The interface not contain any protected, default private dynamic method, and constructor.




It is also used to declare a set of abstract method which will be implemented by the Middle Layer of The project.



Interface Support Multiple Inheritance because we can implement two interfaces in One class.


Syntax of Interface:-


interface Interfacename
{

default void methodName()    #default method
{

}

static void fun()    #static method
{

}


void methdoname();  #abstract method
 

}


no need to write abstract and public keyword, it will be by default public and abstract:-


interface I
{
int a=10;  //final variable
default void methodName()  //default
{
  System.out.println("default");
}

static void fun()  //static
{
System.out.println("fun");
}
void fun1();  //abstract

}



interface I1
{
  void fun2();
}


class A implements I, I1      #multiple inheritance 
{
   public void fun1()
   {
      System.out.println("fun1");
   }
   public void fun2()
   {
      System.out.println("fun2");
   }
  public static void main(String args[])
  {
      I obj = new A();
      obj.methodName();
      I.fun();
      I1 obj1 = new A();
      obj1.fun2();
    
  }

}




Latest Example of Interface and class

interface Area
{
   final int a=10;
   static void fun()
   {
      System.out.println("Static");
   }
   default void fun2()
   {
      System.out.println("default");
   }
   void triangle();
   void rectangle();
}
interface Maths
{
   void multi();
}
class A
{

}
class B
{

}
class Impl extends A implements Area, Maths
{
   public void multi()
  {
    System.out.print("TAREA");
  }
  public void triangle()
  {
    System.out.print("TAREA");
  }
  public void rectangle()
  {
    System.out.print("RAREA");
  }
public static void main(String args[])
  {
     Area obj = new Impl();
     obj.triangle();
     obj.rectangle();
  }
}


Modified Example:-

interface Area
{
   final int a=10;
   static void fun()
   {
      System.out.println("Static");
   }
   default void fun2()
   {
      System.out.println("default");
   }
   void triangle();
   void rectangle();
}
interface Maths extends Area
{
   void multi();
}
abstract class A
{

}
class B
{

}
class Impl extends A implements Maths
{
   public void multi()
  {
    System.out.print("TAREA");
  }
  public void triangle()
  {
    System.out.print("TAREA");
  }
  public void rectangle()
  {
    System.out.print("RAREA");
  }
public static void main(String args[])
  {
     Area obj = new Impl();
     obj.triangle();
     obj.rectangle();
  }
}


Example of Inhertitance:-

interface Idevice
{
   static void deviceInfo()
   {
      System.out.println("Device info");

   }

   default void deviceColor(String color)
   {
     System.out.println("Color is "+color);
   }

 void deviceSpeed();
   

}

interface A extends Idevice
{
    
}
class ISales
{
    void hireTeam()
    {
       System.out.println("hire team");
    }

}
class Mydevice extends ISales implements Idevice
{
 public void deviceMileage()
  {
    System.out.println("Milege");
  }
 public  void deviceSpeed()
  {
    System.out.println("speed");
  }
   public  void hireTeam()
  {
    System.out.println("Sales");
  }
}

class Client
{
   public static void main(String ram[])
  {
        Idevice obj = new Mydevice();
        obj.deviceSpeed();
        Idevice.deviceInfo();
        obj.deviceColor("RED");
        

  }

}

68 Comments

POST Answer of Questions and ASK to Doubt

  1. program of employee

    import java.util.Scanner;
    class Emp
    {
    Scanner sc=new Scanner(System.in);
    int empid,sal;
    String name,job;
    void accept()
    {
    System.out.println("Enter Employee Id");
    empid=sc.nextInt();
    System.out.println("Enter Employee Name");
    name=sc.next();
    System.out.println("Enter Employee Job");
    job=sc.next();
    System.out.println("Enter Employee Salary");
    sal=sc.nextInt();
    }
    void display()
    {
    System.out.println(empid);
    System.out.println(name);
    System.out.println(job);
    System.out.println(sal);
    }
    }
    class Empmain
    {
    public static void main(String args[])
    {
    Emp e=new Emp();
    e.accept();
    e.display();

    }
    }

    ReplyDelete
  2. import java.util.Scanner;
    class Marksheet
    {
    private int roll,ph,ch,eh,mh,total;
    private String name;
    void get(int roll,String name,int ph,int ch,int eh,int mh)
    {
    this.roll=roll;
    this.name=name;
    this.ph=ph;
    this.ch=ch;
    this.eh=eh;
    this.mh=mh;
    total=ph+ch+eh+mh;
    }
    void show()
    {
    System.out.println();
    System.out.println("Roll no = "+roll);
    System.out.println("Name = "+name);
    System.out.println();
    System.out.println("Physics Score= "+ph+"/100");
    System.out.println("Chemistry Score= "+ch+"/100");
    System.out.println("English Score = "+eh+"/100");
    System.out.println("Maths Score = "+mh+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");
    System.out.println();
    }


    }

    class Markmain
    {
    public static void main(String args[])
    {
    int r,x,i,p,c,e,m;
    String nm;
    Scanner sc =new Scanner(System.in);
    System.out.println("Enter number of students = ");
    x=sc.nextInt();
    Marksheet s[] = new Marksheet[x+1];
    for(i=1;i<x+1;i++)
    {
    System.out.println("Enter records for "+i+" student");
    s[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    r=sc.nextInt();
    System.out.println("Enter name = ");
    nm=sc.next();
    System.out.println("Enter Marks in Physics = ");
    p=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    c=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    e=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    m=sc.nextInt();
    s[i].get(r,nm,p,c,e,m);
    }
    for(i=1;i<x+1;i++)
    {
    s[i].show();
    }
    }
    }

    ReplyDelete
  3. CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY

    import java.util.Scanner;

    public class EmployImformation {
    int empid;
    String name;
    float salary;
    void accept()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the emp id");
    empid =sc.nextInt();
    System.out.println("enter the name");
    name=sc.next();
    System.out.println("enter the Salary");
    salary=sc.nextFloat();
    }
    void display()
    {
    System.out.println("emp id =" + empid);
    System.out.println("emp name =" + name);
    System.out.println("emp salary =" + salary);


    }

    }
    public class EmployImformationMain {

    public static void main(String[] args) {
    EmployImformation obj=new EmployImformation();
    obj.accept();
    obj.display();

    }

    }

    ReplyDelete
  4. MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX
    OBTAINED MARKS.

    import java.util.Scanner;

    public class Marksheet {
    int m1,m2,m3,m4,m5;
    String s1,s2,s3,s4,s5;
    Scanner sc=new Scanner(System.in);
    void calcMarks()
    {
    System.out.println("enter sbject name and marks");
    s1=sc.next();
    m1=sc.nextInt();
    System.out.println("enter subject and marks");
    s2=sc.next();
    m2=sc.nextInt();
    System.out.println("enter subject and marks");
    s3=sc.next();
    m3=sc.nextInt();
    System.out.println("enter subject and marks");
    s4=sc.next();
    m4=sc.nextInt();
    System.out.println("enter subject and marks");
    s5=sc.next();
    m5=sc.nextInt();
    if((m1>=0&&m1<=100)&&(m2>=0&&m2<=100)&&(m3>=0&&m3<=100)&&(m4>=0&&m4<=100)&&(m5>=0&&m5<=100))
    {
    int c=0;
    int mark=0;
    String sub="";
    String dist="";
    if(m1>=75)
    dist+=s1+"";
    if(m2>=75)
    dist+=s2+"";
    if(m3>=75)
    dist+=s3+"";
    if(m4>=75)
    dist+=s4+"";
    if(m5>75)
    dist+=s5+"";

    if(m1<33)
    {
    mark=m1;
    sub+=s1+" ";
    c++;
    }


    if(m2<33)
    {
    sub+=s2+" ";
    mark=m2;
    c++;

    }

    if(m3<33)
    {
    sub+=s3+" ";
    mark=m3;
    c++;
    }


    if(m4<33)
    {
    sub+=s4+" ";
    mark=m4;
    c++;
    }

    if(m5<33)
    {
    sub+=s5+"";
    mark=m5;
    c++;
    }

    if (c==0||(c==1 && mark>=28))
    {
    float res;
    if(c==0)
    res=(m1+m2+m3+m4+m5)/5;
    else
    res=(m1+m2+m3+m4+m5+(33-mark))/5;
    if(res>=33&&res<45)
    System.out.println("pass with third division");
    else if(res<60)
    System.out.println("pass with second division");
    else
    System.out.println("pass with first division");
    if(c==1)
    System.out.println("note:-you are pass by grace and grace mark is" +(33-mark)+"grace subject is "+sub);
    if(dist!="")
    System.out.println("distinction sub name is"+dist);


    }

    else if(c==1)
    System.out.println("try again you are supplementri" +sub);
    else
    System.out.println("sry you have faild" +sub);
    }





    else

    {
    System.out.println("invalid marks");
    }





    }



    public static void main(String[] args) {

    Marksheet obj=new Marksheet();
    obj.calcMarks();
    }

    }


    ReplyDelete
  5. public class Overriding {
    public void boardInfo()
    {
    System.out.println("RGPV");
    }
    public void examPattern()
    {
    System.out.println("Number System");
    }

    }
    class Examnew extends Overriding
    {
    public void examPattern(String s)
    {
    System.out.println("Grade System"+s);
    }
    public void examPattern()
    {
    System.out.println("Grade System");
    }

    public static void main(String args[])
    {

    // Exam obj = new Examnew();
    // Exam obj = new Exam();
    Examnew obj = new Examnew();
    obj.boardInfo();
    obj.examPattern();
    }

    }






    ReplyDelete
  6. # addition program using oops

    import java.util.*;
    class Op
    {
    int a;
    int b;
    int c;


    void num(int a,int b)
    {
    this.a=a;
    this.b=b;
    }

    void add()
    {
    c=a+b;
    System.out.println(c);
    }

    void sub()
    {
    c=a-b;
    System.out.println(c);
    }
    void multi()
    {
    c=a+b;
    System.out.println(c);
    }
    void div()
    {
    c=a+b;
    System.out.println(c);
    }

    }







    import java.util.*;
    class OpR
    {
    public static void main(String arg[])
    {
    Op o=new Op();

    while(true)
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("enter ch");
    char s=sc.next().charAt(0);
    Scanner c=new Scanner(System.in);
    System.out.print("enter number 1"+ " ");
    int a=c.nextInt();
    Scanner c2=new Scanner(System.in);
    System.out.print("enter number 2"+ " ");
    int b=c2.nextInt();
    o.num(a,b);
    if(s=='+')
    {
    o.add();
    }
    if(s=='-')
    {
    o.sub();
    }
    if(s=='*')
    {
    o.multi();
    }
    if(s=='/')
    {
    o.div();
    }
    }
    }
    }

    ReplyDelete
  7. import java.util.Scanner;
    class Marksheet
    {
    int rollno,phno,chno,ehno,mhno,total;
    String suname;
    void getdata()
    {
    this.rollno=rollno;
    this.suname=suname;
    this.phno=phno;
    this.chno=chno;
    this.ehno=ehno;
    this.mhno=mhno;
    total=phno+chno+ehno+mhno;
    }
    void display()
    {

    System.out.println("Roll no = "+rollno);
    System.out.println("Name = "+suname);
    System.out.println("Physics Score= "+phno+"/100");
    System.out.println("Chemistry Score= "+chno+"/100");
    System.out.println("English Score = "+ehno+"/100");
    System.out.println("Maths Score = "+mhno+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");

    }


    }

    public class Main {

    public static void main (String[] args) {
    int rollno,mathno,phyno,engno,cheno,size;
    String suname;

    Scanner sc=new Scanner(System.in);
    System.out.println("how many student");
    size=sc.nextInt();
    Marksheet mark[] =new Marksheet[size];
    for(int i=1;i<size;i++)
    {
    System.out.println("Enter records for "+i+" student");
    mark[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    rollno=sc.nextInt();
    System.out.println("Enter name = ");
    suname=sc.next();
    System.out.println("Enter Marks in Physics = ");
    phyno=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    cheno=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    engno=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    mathno=sc.nextInt();
    mark[i].getdata();
    }
    for(int i=1;i<size;i++)
    {
    mark[i].display();
    }

    }
    }

    ReplyDelete
  8. import java.util.Scanner;
    class Marksheet
    {
    int rollno,phno,chno,ehno,mhno,total;
    String suname;
    void getdata()
    {
    this.rollno=rollno;
    this.suname=suname;
    this.phno=phno;
    this.chno=chno;
    this.ehno=ehno;
    this.mhno=mhno;
    total=phno+chno+ehno+mhno;
    }
    void display()
    {

    System.out.println("Roll no = "+rollno);
    System.out.println("Name = "+suname);
    System.out.println("Physics Score= "+phno+"/100");
    System.out.println("Chemistry Score= "+chno+"/100");
    System.out.println("English Score = "+ehno+"/100");
    System.out.println("Maths Score = "+mhno+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");

    }


    }

    public class Main {

    public static void main (String[] args) {
    int rollno,mathno,phyno,engno,cheno,size;
    String suname;

    Scanner sc=new Scanner(System.in);
    System.out.println("how many student");
    size=sc.nextInt();
    Marksheet mark[] =new Marksheet[size+1];
    for(int i=1;i<size+1;i++)
    {
    System.out.println("Enter records for "+i+" student");
    mark[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    rollno=sc.nextInt();
    System.out.println("Enter name = ");
    suname=sc.next();
    System.out.println("Enter Marks in Physics = ");
    phyno=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    cheno=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    engno=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    mathno=sc.nextInt();
    if(mathno<33)
    {
    System.out.println("you have a supply mantry");
    }
    if(phyno<33)
    {
    System.out.println("better luck next time you are failed ");
    }

    mark[i].getdata();
    }
    for(int i=1;i<size+1;i++)
    {
    mark[i].display();
    }

    }
    }

    ReplyDelete
  9. class BankofIndia
    {
    String custmername,acotype;
    int acono,bal,amt;
    importScanner sc=new Scanner(System.in);

    void BankOfindia( String custmername,String acotype,int acotype,int acono)
    {
    this.custmername=custmername;
    this.acono=acono;
    this.bal=bal;
    this.acotype=acotype;

    }
    int Deposit()
    {
    System.out.println("Enter ammount to deposit");
    amt=sc.nextInt();
    if(amt<0)
    {
    System.out.println("invalid ammount");
    return 1;
    }
    bal=bal+amt;
    return 0;
    }

    int Withdraw()
    {
    System.out.println("your balance is" +bal);
    System.out.println("enter ammount to withdraw");
    amt=sc.nextInt();
    if(bal<amt)
    {
    System.out.println("not suufiecient balance in your account");
    return 1;
    }
    if(amt<0)
    {
    System.out.println("invalid balance");
    return 1;

    }
    bal=bal-amt;
    return 0;
    } void display()
    {
    System.out.println("custmer name: "+custmername);
    System.out.println("Account no: "+acono);
    System.out.println("balance: "+bal);

    }


    }
    public class Main
    {
    public static void main(String[] args) {
    System.out.println("welcome the bankOf India");
    System.out.println("enter your name: "+custmername);
    custmername=sc.next();
    System.out.println("enter your Account no: "+acono);
    acono=sc.nextInt();
    System.out.println("enter your Account type: "+acotype);
    acotype=sc.next();
    System.out.println("enter initial balance: "+bal);
    bal=sc.next();
    BanoOfIndia boi=new BankOfIndia(cusname,anum,actype,bal);
    int menu;
    System.out.println("menu");
    System.out.println("1.Deposit Amount");
    System.out.println("2.Withdraw Amount");
    System.out.println("3.Display Information");
    System.out.println("4.Exit");
    boolean exit=true;
    do
    {
    System.out.println("enter your choice");
    menu=sc.nextInt();
    switch(menu)
    {
    case 1:
    boi.deposit();
    break;
    case 2:
    boi.withdraw;
    break;
    case 3:
    boi.display;
    break;
    case 4:
    exit=true;
    break;
    }
    while(!exit);
    }



    }

    ReplyDelete
  10. import java.util.Scanner;
    class Employe
    {

    int empid,empsal;
    String empname,job;
    void getdata()
    {
    Scanner sc=new Scanner(System.in);

    System.out.println("enter the emplye name");
    empname=sc.next();
    System.out.println("enter ihe employe id");
    empid=sc.nextInt();
    System.out.println("enter the employe salary");
    empsal=sc.nextInt();
    System.out.println("enter the employe job titie");
    job=sc.next();


    }
    void display()
    {
    System.out.println("welcome in our company");
    System.out.println("employe name is: "+ empname);
    System.out.println("your salary is: "+ empsal);
    System.out.println("your id is: " + empid);
    System.out.println("your job title is: " + job);

    }
    }
    class Main
    {
    public static void main(String args[] )
    {
    Employe e[]=new Employe[5];
    for(int i=0;i<5;i++)
    {
    System.out.println("employe record of"+i+"number");
    e[i]=new Employe();
    e[i].getdata();
    }
    for(int i=1;i<5;i++)
    {
    e[i].display();
    }
    }
    }

    ReplyDelete
  11. public class Main
    {
    public static void main(String[] args)
    {
    int a[][]={{1,2,3},{3,3,3},{4,4,4}};
    int b[][]={{1,1,1},{2,2,2},{3,3,3}};
    int c[][]=new int [3][3];
    for(int i=0;i<3;i++)
    {
    for(int j=0;j<3;j++)
    {
    c[i][j]=0;
    for(int k=0;k<3;k++)
    {
    c[i][j]=a[i][k]*b[k][j]+c[i][j];
    System.out.print(c[i][j]+" ");
    }
    System.out.println();
    }

    }
    }

    }

    ReplyDelete

  12. // Wap to create array object??
    import java.util.Scanner;
    class Student
    {
    int rollno;
    String name;
    void accept()
    {
    System.out.print("enter Roll no=");
    Scanner sc=new Scanner(System.in);
    rollno=sc.nextInt();
    System.out.print("enter name=");
    sc.nextLine();
    name=sc.nextLine();
    }
    void display()
    {
    System.out.println("roll no= "+rollno + ",name= "+name);
    }


    }
    class StudentMain
    {
    public static void main(String...args)
    {
    System.out.print("Enter no. of object you wants to create=");
    Scanner sc=new Scanner(System.in);

    int s=sc.nextInt();
    Student[] obj=new Student[s];

    for(int i=0;i<s;i++)
    {
    obj[i]=new Student();
    obj[i].accept();
    obj[i].display();
    }

    }

    }

    ReplyDelete
  13. kinjal singh sirohiFebruary 18, 2021 at 6:17 PM

    //wap to Manage multiple students records using single object?
    import java.util.Scanner;
    class Studentrecords
    {
    public static void main (String args[])
    { int sno=3;
    Student obj[]=new Student[sno];
    for(int i=0;i<sno;i++)
    {

    obj[i]=new Student();

    obj[i].accept();
    obj[i].display();
    }
    }}
    class Student{int rno,sno;
    String sname;
    void accept()
    {

    Scanner sc=new Scanner(System.in);

    System.out.println("enter roll no");
    rno=sc.nextInt();
    System.out.println("enter name of student");
    sname=sc.next();
    }
    void display()
    {
    System.out.println("Students record is"+ rno + ","+ sname);
    }
    }

    ReplyDelete
  14. //Multiple Data store in one object

    // Abhishek chauhan


    import java.util.Scanner;
    class Abhishek
    {
    int rollno;
    String name;
    void accept()
    {
    System.out.print("enter Roll no=");
    Scanner sc=new Scanner(System.in);
    rollno=sc.nextInt();
    System.out.print("enter name=");
    sc.nextLine();
    name=sc.nextLine();
    }
    void display()
    {
    System.out.println("roll no= "+rollno + ",name= "+name);
    }


    }
    class Abhi
    {
    public static void main(String...args)
    {
    System.out.print("Enter no. of object =");
    Scanner sc=new Scanner(System.in);

    int s=sc.nextInt();
    Abhishek[] obj=new Abhishek[s];

    for(int i=0;i<s;i++)
    {
    obj[i]=new Abhishek();
    obj[i].accept();
    obj[i].display();
    }

    }

    }

    ReplyDelete
  15. //CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY.
    import java.util.Scanner;
    class Employee
    {
    int empid;
    String name;
    String job;
    int salary;
    void accept()
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter Employee ID=");
    empid=sc.nextInt();
    System.out.print("Enter Employee Name=");
    name=sc.next();
    System.out.print("Enter Employee Job Type=");
    job=sc.next();
    System.out.print("Enter Employee Salary=");
    salary=sc.nextInt();
    }
    void display()
    {
    System.out.println("Employee ID is="+empid);
    System.out.println("Employee Name is="+name);
    System.out.println("Employee Job Type is="+job);
    System.out.println("Employee Salary is="+salary);
    System.out.println("....................................");
    }
    }

    class EmployeeMain
    {
    public static void main(String...args)
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter number of Employees=");
    int s=sc.nextInt();
    Employee obj[]=new Employee[s];
    for(int i=0;i<s;i++)
    {
    obj[i]=new Employee();
    obj[i].accept();
    }
    for(int i=0;i<s;i++)
    {
    obj[i].display();
    }
    }

    }

    ReplyDelete
  16. // MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX
    //OBTAINED MARKS, Aggregate marks.

    // ADITYA BAGHEL

    import java.util.*;
    class Student
    {
    int roll_no, maths,physics,chemistry,hindi,english,percentage,marks=0;
    String name;
    float aggregate;
    Scanner sc=new Scanner(System.in);
    void show()
    {
    System.out.println("enter roll no");
    roll_no=sc.nextInt();
    System.out.println("enter Name");
    name=sc.next();
    System.out.println("enter Maths marks");
    maths=sc.nextInt();
    System.out.println("enter chemistrry marks");
    chemistry=sc.nextInt();
    System.out.println("enter Physics marks");
    physics=sc.nextInt();
    System.out.println("enter Hindi marks");
    hindi=sc.nextInt();
    System.out.println("enter English marks");
    english=sc.nextInt();
    }
    void max()
    {
    int Marks[]={maths,physics,chemistry,hindi,english};
    for(int i=0;i<5;i++)
    {

    if(marks<Marks[i])
    {
    marks=Marks[i];
    }
    }
    }
    void average()
    {
    aggregate=(float)(maths+chemistry+physics+hindi+english)/5;
    }
    void display()
    {
    System.out.println("Roll no is="+roll_no);
    System.out.println("Name is="+name);
    System.out.println("Maths marks is is="+maths);
    System.out.println("Chemistry marks is="+chemistry);
    System.out.println("Physics marks is="+physics);
    System.out.println("Hindi marks is="+hindi);
    System.out.println("English marks is="+english);
    System.out.println("Maximum marks among all Subject is="+marks);
    System.out.println("Percentage is="+aggregate);

    }
    }
    class Marksheet
    {
    static public void main(String ar[])
    {
    Student s=new Student();
    System.out.println("ENter size of student");
    int x=s.sc.nextInt();
    Student array[]=new Student[x];
    for(int i=0;i<x;i++)
    {
    array[i]=new Student();
    array[i].show();
    array[i].max();
    array[i].average();


    }
    for(int i=0;i<x;i++)
    {
    array[i].display();
    }

    }
    }

    ReplyDelete
  17. //MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX OBTAINED MARKS,Aggregate marks.
    //kinjal singh sirohi
    import java.util.Scanner;
    class Marksheet
    {
    int r,p,c,e,m,h,total;
    String name;
    void information(int r,String name,int p,int c,int e,int m,int h)
    {
    this.r=r;
    this.name=name;
    this.p=p;
    this.c=c;
    this.e=e;
    this.m=m;
    this.h=h;
    total=p+c+e+m+h;
    }
    void display()
    {

    System.out.println("roll no= "+r);
    System.out.println("Name = "+name);
    System.out.println("Physics= "+p+"/100");
    System.out.println("Chemistry= "+c+"/100");
    System.out.println("English= "+e+"/100");
    System.out.println("Maths= "+m+"/100");
    System.out.println("Hindi= "+h+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/500");
    System.out.println();
    }
    }
    class Marksheetmain
    {
    public static void main(String args[])
    {
    int r,stu,i,p,c,e,m,h;
    String name;
    Scanner sc =new Scanner(System.in);
    System.out.println("Enter number of students =");
    stu=sc.nextInt();
    Marksheet obj[] = new Marksheet[stu+1];
    for(i=1;i<stu+1;i++)
    {
    System.out.println("Enter information for students"+i+" student");
    obj[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    r=sc.nextInt();
    System.out.println("Enter name = ");
    name=sc.next();
    System.out.println("Enter Marks in Physics = ");
    p=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    c=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    e=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    m=sc.nextInt();
    System.out.println("Enter Marks in Hindi = ");
    h=sc.nextInt();
    obj[i].information(r,name,p,c,e,m,h);
    }
    for(i=1;i<stu+1;i++)
    {
    obj[i].display();
    }
    }
    }

    ReplyDelete
  18. //MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX OBTAINED MARKS, Aggregate marks.

    import java.util.Scanner;
    class Marksheet
    { int i=0;
    double sum=0;
    int max=0;
    int arr[]=new int[5];
    Scanner sc=new Scanner(System.in);
    void accept()
    {
    for(i=0;i<5;i++)
    {
    if(i==0)System.out.print("Enter Physics marks=");
    if(i==1)System.out.print("Enter Chemistry marks=");
    if(i==2)System.out.print("Enter Maths marks=");
    if(i==3)System.out.print("Enter English marks=");
    if(i==4)System.out.print("Enter Physical Education marks=");
    arr[i]=sc.nextInt();
    }
    }
    void display()
    {
    for(i=0;i<5;i++)
    {

    sum+=arr[i];
    if(max<arr[i]) max=arr[i];
    }
    System.out.println("Maximum Marks is "+max);
    System.out.println("Aggregate is "+(sum/5.0));
    System.out.println(".............................");
    }

    }

    class MarksheetMain
    {

    public static void main(String...args)
    {
    int i=0;
    Marksheet obj[]=new Marksheet[5];
    for(i=0;i<5;i++)
    {
    System.out.println("Enter Marks of Student "+(i+1));
    obj[i]=new Marksheet();
    obj[i].accept();
    }
    for(i=0;i<5;i++)
    {
    System.out.println(" Marksheet of Student "+(i+1));
    obj[i].display();
    }
    }
    }

    ReplyDelete
  19. //AKSHAY JANGDE

    import java.util.*;
    class Employee
    {
    int empid,empsalary;
    String empname,empjob;
    Scanner sc=new Scanner(System.in);

    void accept()
    {
    System.out.println("Enter employee id");
    empid=sc.nextInt();

    System.out.println("Enter employee salary");
    empsalary=sc.nextInt();

    System.out.println("Enter employee name");
    empname=sc.next();

    System.out.println("Enter employee job");
    empjob=sc.next();
    }

    void display()
    {
    System.out.println("employee id is "+empid);
    System.out.println("employee salary is "+empsalary);
    System.out.println("employee name is "+empname);
    System.out.println("employee job is "+empjob);

    System.out.println();
    }
    }
    class EmployeeMain
    {
    public static void main(String[]args)
    {

    Employee e1=new Employee();
    System.out.println("Employee number of empl");
    int size = e1.sc.nextInt();

    Employee arr[]= new Employee[size];

    for(int i=0;i<size;i++)
    {
    arr[i]=new Employee();
    arr[i].accept();
    }
    for(int i=0;i<size;i++)
    {
    arr[i].display();
    }

    }
    }

    ReplyDelete
  20. How to pass multiple parameters and return multiple values using single function?

    WAP to sort the array without sorting the actual array?


    class MultipleArr
    {
    int [] display(int arr[])
    {

    int arr1[] = new int[arr.length];
    for(int i=0;iarr1[j])
    {
    int temp = arr1[i];
    arr1[i]=arr1[j];
    arr1[j]=temp;
    }
    }

    }

    return arr1;

    }



    }

    class ArrMain
    {
    public static void main(String args[])
    {
    MultipleArr obj = new MultipleArr();
    int arr[] = {12,11,45,56,6,89};
    int arr1[]=obj.display(arr);
    for(int i=0;i<arr.length;i++)
    {
    System.out.println("Actual array is "+arr[i] + " Sorted Array is "+arr1[i]);
    }


    }

    }

    ReplyDelete
  21. import java.util.Scanner;
    class Marks
    {
    int mark[];
    float per = 0,total;
    String sub[];

    void enterSubjectMarks(String sub[],int mark[])
    {
    this.sub = sub;
    this.mark = mark;
    }

    void calculateMarks()
    {
    for(int i=0;i<mark.length;i++)
    {
    total = total+mark[i];
    }
    per = total/mark.length;
    System.out.println("Percentage=" +per);
    }
    }

    class MarkMain
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    String sub[] = {"Physics","Chemistry","Math","Hindi","English"};
    System.out.println("Enter number of students");
    Marks obj[] = new Marks[sc.nextInt()];
    float ag=0;
    for(int i=0;i<obj.length;i++)
    {
    obj[i] = new Marks();
    int marks[] = new int[5];

    System.out.println("Enter record for students" +(i+1));
    for(int j=0;j<5;j++)
    {
    System.out.println("Enter marks for " +sub[j]);
    marks[j] = sc.nextInt();
    }
    obj[i].enterSubjectMarks(sub,marks);
    obj[i].calculateMarks();
    ag+=obj[i].per;
    }
    System.out.println("Aggreagte percentage=" +ag/obj.length);
    }
    }

    ReplyDelete
  22. Khushboo Sendre

    import java.util.Scanner;
    class Marks
    {
    int mark[];
    float per = 0,total;
    String sub[];

    void enterSubjectMarks(String sub[],int mark[])
    {
    this.sub = sub;
    this.mark = mark;
    }

    void calculateMarks()
    {
    for(int i=0;i<mark.length;i++)
    {
    total = total+mark[i];
    }
    per = total/mark.length;
    System.out.println("Percentage=" +per);
    }
    }

    class MarkMain
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    String sub[] = {"Physics","Chemistry","Math","Hindi","English"};
    System.out.println("Enter number of students");
    Marks obj[] = new Marks[sc.nextInt()];
    float ag=0;
    for(int i=0;i<obj.length;i++)
    {
    obj[i] = new Marks();
    int marks[] = new int[5];

    System.out.println("Enter record for students" +(i+1));
    for(int j=0;j<5;j++)
    {
    System.out.println("Enter marks for " +sub[j]);
    marks[j] = sc.nextInt();
    }
    obj[i].enterSubjectMarks(sub,marks);
    obj[i].calculateMarks();
    ag+=obj[i].per;
    }
    System.out.println("Aggreagte percentage=" +ag/obj.length);
    }
    }

    ReplyDelete
  23. Khushboo Sendre

    import java.util.Scanner;
    class Emp
    {
    int eid,esalary;
    String ename,job;

    void getdata()
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Entee emp name");
    ename = sc.next();
    System.out.println("Enter emp id");
    eid = sc.nextInt();
    System.out.println("Enter emp salary");
    esalary = sc.nextInt();
    System.out.println("Enter the job title");
    job = sc.next();
    }

    void display()
    {
    System.out.println("Welcome in our company");
    System.out.println("employee name=" +ename);
    System.out.println("salary=" +esalary);
    System.out.println("Id=" +eid);
    System.out.println("Job Title=" +job);
    }
    }

    class MEmployee
    {
    public static void main(String args[])
    {
    Emp e[] = new Emp[5];
    for(int i=0;i<5;i++)
    {
    System.out.println("Employee record" +i+ "number");
    e[i].getdata();
    }
    for(int i=1;i<5;i++)
    {
    e[i].display();
    }
    }
    }

    ReplyDelete
  24. import java.util.Scanner;
    class Emp
    {
    int eid,esalary;
    String ename,job;

    void getdata()
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Entee emp name");
    ename = sc.next();
    System.out.println("Enter emp id");
    eid = sc.nextInt();
    System.out.println("Enter emp salary");
    esalary = sc.nextInt();
    System.out.println("Enter the job title");
    job = sc.next();
    }

    void display()
    {
    System.out.println("Welcome in our company");
    System.out.println("employee name=" +ename);
    System.out.println("salary=" +esalary);
    System.out.println("Id=" +eid);
    System.out.println("Job Title=" +job);
    }
    }

    class MEmployee
    {
    public static void main(String args[])
    {
    Emp e[] = new Emp[5];
    for(int i=0;i<5;i++)
    {
    System.out.println("Employee record" +i+ "number");
    e[i].getdata();
    }
    for(int i=1;i<5;i++)
    {
    e[i].display();
    }
    }
    }

    ReplyDelete
  25. Khushboo Sendre

    import java.util.Scanner;
    class Marks
    {
    int mark[];
    float per = 0,total;
    String sub[];

    void enterSubjectMarks(String sub[],int mark[])
    {
    this.sub = sub;
    this.mark = mark;
    }

    void calculateMarks()
    {
    for(int i=0;i<mark.length;i++)
    {
    total = total+mark[i];
    }
    per = total/mark.length;
    System.out.println("Percentage=" +per);
    }
    }

    class MarkMain
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    String sub[] = {"Physics","Chemistry","Math","Hindi","English"};
    System.out.println("Enter number of students");
    Marks obj[] = new Marks[sc.nextInt()];
    float ag=0;
    for(int i=0;i<obj.length;i++)
    {
    obj[i] = new Marks();
    int marks[] = new int[5];

    System.out.println("Enter record for students" +(i+1));
    for(int j=0;j<5;j++)
    {
    System.out.println("Enter marks for " +sub[j]);
    marks[j] = sc.nextInt();
    }
    obj[i].enterSubjectMarks(sub,marks);
    obj[i].calculateMarks();
    ag+=obj[i].per;
    }
    System.out.println("Aggreagte percentage=" +ag/obj.length);
    }
    }

    ReplyDelete
  26. // MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX OBTAINED MARKS, Aggregate marks.
    import java .util.Scanner;
    class Student{
    private int max=0,i;
    float percent=0;
    private int a[]=new int[5];
    String sub[]= {"Maths","Physics","Chemistry","English","Hindi"};
    String maxSub=" ";
    private String name;
    void data(){
    System.out.print("Enter Student Name- ");
    Scanner scan=new Scanner(System.in);
    name=scan.nextLine();

    System.out.println("Enter marks- ");
    for(i=0;i<5;i++) {
    System.out.print(sub[i]+"- ");
    a[i]=scan.nextInt();
    if(a[i]>100) {
    a[i]=scan.nextInt();
    }
    if(a[i]>max) {
    max=a[i];
    maxSub=sub[i];
    }
    percent=percent+a[i];
    }
    }
    void display() {
    System.out.println("*************\nStudent name : "+name);
    for(i=0;i<5;i++) {
    System.out.println("\t"+sub[i]+": "+a[i]);
    }
    System.out.println("\tTotal: "+percent+"\tPercentage : "+(percent/5)+"\tMaximum mark: "+maxSub+"- "+max);

    }
    }
    public class Main {
    public static void main(String[] args) {
    int size,i;
    float aggr=0;
    System.out.print("Enter number of students-");
    Scanner sc=new Scanner(System.in);
    size=sc.nextInt();
    Student obj[]=new Student[size];
    for(i=0;i<obj.length;i++) {
    obj[i]=new Student();
    obj[i].data();
    aggr=aggr+(obj[i].percent);
    }
    System.out.println("\n");
    for(i=0;i<obj.length;i++) {
    obj[i].display();
    }
    System.out.print("Aggregate percentage is- "+((aggr/obj.length)/5));

    }

    }


    ReplyDelete
  27. //ATM Program with unlimited users, first admin add users with pin, amount and account than user module loaded ask pin three times and perform all operation.
    import java.util.Scanner;

    class Atm {

    private int pin;
    private String account_holder;
    private int ammount;
    private int account_no;
    private int count=1;
    Scanner sc = new Scanner(System.in);

    void accept(int x) {


    System.out.println("Enter Details of User "+x+" :");
    System.out.print("Enter Username: ");
    account_holder=sc.nextLine();
    System.out.print("Enter Account Number: ");
    account_no=sc.nextInt();
    System.out.print("Enter Ammount: ");
    ammount=sc.nextInt();
    System.out.print("Enter Pincode: ");
    pin=sc.nextInt();
    }

    int checkPin(int pincode) {
    if(pin==pincode) {
    operation();
    return 1;
    }
    else return 2;

    }

    void operation() {
    int choice=0;
    System.out.print("Choose any operation: \n1. Account Balance\n2. Cash Deposit\n3. Cash Withdrawal\n4.Reset Pincode");
    choice=sc.nextInt();
    if(choice==1)
    display();
    else if(choice==2) {
    System.out.print("Enter ammount to be deposited- ");
    choice=sc.nextInt();
    ammount=ammount+choice;
    display();
    System.out.println(choice+" cash deposited...");
    }
    else if(choice==3) {
    System.out.print("Enter ammount for withdrawal- ");
    choice=sc.nextInt();
    ammount=ammount-choice;
    display();
    System.out.println(choice+" cash withdrawn...");
    }
    else if(choice==4) {
    int newPin;
    System.out.print("Enter new pincode- ");
    newPin=sc.nextInt();
    System.out.print("Renter pincode- ");
    choice=sc.nextInt();
    if(newPin==choice) {
    pin=newPin;
    System.out.print("New pincode is updated ...");
    System.out.print("Do you want to perform any operation ? If yes enter 1 else enter 0 : ");
    choice=sc.nextInt();
    operation();
    }
    }
    else {
    System.out.println("Invalid operation!");
    operation();
    }

    }

    void display() {
    System.out.println("\n\n****************************************\nUser Information");
    System.out.println("Account holder- "+account_holder+"\nAccount number- "+account_no+"\nTotal ammount- "+ammount);
    }


    }


    class Question {

    public static void main(String args[]){

    int i,tempPin=0,flag=0;
    int pincode[]=new int[3];
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter number of users- ");
    Atm obj[]=new Atm[sc.nextInt()];

    for(i=0;i1)&&(pincode[i]==pincode[i-1])) {
    tempPin=pincode[i];
    }
    }
    for(i=0;i<obj.length;i++) {
    obj[i].checkPin(tempPin);
    if(flag==1)
    break;
    else {
    System.out.print("Invalid User!");
    break;
    }
    }



    }
    }

    ReplyDelete
  28. public class MatrixAdditionExample
    {
    public static void main(String args[])
    {
    int a[][]={{1,3,4},{2,4,3},{3,4,5}};
    int b[][]={{1,3,4},{2,4,3},{1,2,4}};


    int c[][]=new int[3][3];


    for(int i=0;i<3;i++)
    {
    for(int j=0;j<3;j++)
    {
    c[i][j]=a[i][j]+b[i][j];
    System.out.print(c[i][j]+" ");
    }
    System.out.println();
    }
    }}

    ReplyDelete
  29. //CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY.
    import java.util.Scanner;
    class Employee
    {
    int emid;
    String emname;
    String emjob;
    Float emsalary;
    void accept()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter employee id:");
    emid=sc.nextInt();
    System.out.println("Enter employee name:");
    emname=sc.next();
    System.out.println("Enter employee job :");
    emjob=sc.next();
    System.out.println("Enter employee salary: ");
    emsalary=sc.nextFloat();
    }
    void display()
    {
    System.out.println("Employee ID:"+emid);
    System.out.println("Employee Name:"+emname);
    System.out.println("Employee Job:"+emjob);
    System.out.println("Employee Salary:"+emsalary);
    }
    }
    class EmployeeMain
    {
    public static void main(String args[])
    {

    Scanner sc=new Scanner(System.in);
    System.out.print("Enter number of Employees=");
    int num=sc.nextInt();
    Employee obj[]=new Employee[num];
    for(int i=0;i<num;i++)
    {
    obj[i]=new Employee();
    obj[i].accept();
    }
    for(int i=0;i<num;i++)
    {
    obj[i].display();
    }
    }
    }

    ReplyDelete
  30. //Pushpendra Sisodiya

    import java.util.Scanner;
    class Employeee
    {
    int emp_id;
    String empname;
    String job;
    float salary;
    Scanner sc=new Scanner(System.in);
    void read()
    {

    System.out.println("enter emp_id");
    emp_id=sc.nextInt();
    System.out.println("enter empname");
    empname=sc.next();
    System.out.println("enter job");
    job=sc.next();
    System.out.println("enter salary");
    salary=sc.nextFloat();

    }
    void display()
    {
    System.out.println(emp_id +" " + empname +" "+ job+" " +salary);
    }


    }
    class EmployeeeMain
    {
    public static void main(String args[])
    {
    Employeee emp=new Employeee();
    System.out.println("enter no of employe");
    int num=emp.sc.nextInt();
    Employeee obj[]=new Employeee[num];
    for(int i=0;i<num;i++)
    {
    obj[i]=new Employeee();
    obj[i].read();
    }
    for(int i=0;i<num;i++)
    {
    obj[i].display();
    }
    }
    }

    ReplyDelete
  31. // Write a programe of access static data memeber into static member function in diffrent class

    // ADITYA BAGHEL

    class rank
    {
    static int x=10;
    static int y=20;
    static void show()
    {
    System.out.println("x="+x);
    }
    static void show1()
    {
    System.out.println("y="+y);
    }
    }
    class State
    {
    public static void main(String ar[])
    {
    rank.show();
    rank.show1();
    }
    }

    ReplyDelete
  32. // Write a programe of access static data memeber into static member function in Same class

    // ADITYA BAGHEL

    class State1
    {
    static int x=20;
    static int y=10;
    static public void main(String args[])
    {
    System.out.println("x="+x);
    System.out.println("y="+y);

    }
    }

    ReplyDelete
  33. // Write a programe of access static data memeber into non static member function in diffrent class

    // ADITYA BAGHEL

    class rank
    {
    static int x=10;
    static int y=20;
    void show()
    {
    System.out.println("x="+x);
    }
    void show1()
    {
    System.out.println("y="+y);
    }
    }
    class State
    {
    public static void main(String ar[])
    {
    rank r=new rank();
    r.show();
    r.show1();
    }
    }

    ReplyDelete
  34. // Write a programe of access static data memeber into non-static member function in Same class

    // ADITYA BAGHEL

    class State1
    {
    static int x=20;
    static int y=10;

    void show()
    {
    System.out.println("x="+x);
    System.out.println("y="+y);

    }
    static public void main(String args[])
    {

    State1 s=new State1();
    s.show();



    }

    }

    ReplyDelete
  35. // Write a programe of access dynamic data memeber into dynamic member function in diffrent class

    // ADITYA BAGHEL

    class rank
    {
    int x=10;
    int y=20;
    void show()
    {
    System.out.println("x="+x);
    }
    void show1()
    {
    System.out.println("y="+y);
    }
    }
    class State
    {
    public static void main(String ar[])
    {
    rank r=new rank();
    r.show();
    r.show1();
    }
    }

    ReplyDelete
  36. // Write a programe of access dynamic data memeber into dynamic member function in Same class

    // ADITYA BAGHEL

    class State1
    {
    int x=50;
    int y=60;

    void show()
    {
    System.out.println("x="+x);
    System.out.println("y="+y);
    System.out.println("sum="+(x+y));

    }
    static public void main(String args[])
    {

    State1 s=new State1();
    s.show();

    }
    }

    ReplyDelete
  37. // WAP to sort an without change in actual array using parametrized member function with return type.
    class Sort{
    int i,j,temp=0;
    int[] sortArray(int[] arr) {
    int[] b=new int[arr.length];
    for(i=0;i0) {
    for(j=0;j<i;j++) {
    if(b[i]<b[j]) {
    temp=b[j];
    b[j]=b[i];
    b[i]=temp;
    }
    }
    }
    }
    return b;

    }
    }
    class Main{
    public static void main(String[] args) {
    int a[]= {27,34,1,56,43,38,4};
    Sort obj=new Sort();
    int[] x=obj.sortArray(a);
    for(int i=0;i<x.length;i++) {
    System.out.print( x[i]+" ");
    }
    }
    }

    ReplyDelete
  38. // WAP to perform addition of matrix multiplication using param array with return type.

    class Array{
    int i,j,k,temp;
    int[][] arrayMulti(int[][] p,int[][] q) {
    int[][] r=new int[p.length][q.length];
    for(i=0;i<p.length;i++) {
    for(j=0;j<p.length;j++) {
    temp=0;
    for(k=0;k<p.length;k++) {
    temp=temp+(p[i][k]*q[k][j]);
    }
    r[i][j]=temp;
    }
    }
    return r;

    }
    }
    class Main{
    public static void main(String[] args) {
    int a[][]= {{2,2,2},{2,2,2},{3,3,3}};
    int b[][]= {{1,1,1},{1,1,1},{1,1,1}};
    Array obj=new Array();
    int c[][]=obj.arrayMulti(a,b);
    System.out.println("Actual Array- ");
    for(int i=0;i<a.length;i++) {
    for(int j=0;j<a.length;j++)
    System.out.print( c[i][j]+" ");
    System.out.println();
    }
    }
    }

    ReplyDelete
  39. // WAP to count total prime elements on the jagged array and show max prime elements using param array with return type
    class Array{
    int i,j,k,index=0,count=0;
    int[] arrayMulti(int[][] p) {
    int[] r=new int[10];
    for(i=0;i<p.length;i++) {
    for(j=0;j<p[i].length;j++) {
    count=0;
    for(k=1;k<=p[i][j];k++) {
    if(p[i][j]%k==0)
    count++;
    }if(count==2) {
    r[index]=p[i][j];
    index++;
    }
    }
    }
    return r;

    }
    }
    class Main{
    public static void main(String[] args) {
    int[][] arr=new int[3][];
    int max=0,i,j;
    arr[0]= new int[] {1,2,3,4};
    arr[1]= new int[] {5,7,9};
    arr[2]= new int[] {11,12,13,7,8};
    Array obj=new Array();
    int[] prime =obj.arrayMulti(arr);
    // Displaying Jagged Array
    for(i=0;i<arr.length;i++) {
    for(j=0;j<arr[i].length;j++) {
    System.out.print(arr[i][j]+" ");
    }System.out.println();
    }
    // Prime numbers present in Array
    System.out.println("Prime numbers present in jagged array are - ");
    for(i=0;i<prime.length;i++) {
    System.out.print(prime[i]+" ");
    if(max<prime[i]);
    max=prime[i];
    }
    // maximum prime number
    System.out.print("\nMaximum prime number - "+max);
    }
    }

    ReplyDelete
  40. Constructor example for batch 5 to 6

    class Add
    {
    int a,b,c;
    Add() // default
    {
    System.out.println("constructor");
    a=10;
    b=20;

    }
    Add(int a) // single param
    {
    System.out.println("param constructor");
    this.a=a;


    }
    Add(int a,int b) //double param
    {
    System.out.println("param constructor");
    this.a=a;
    this.b=b;

    }

    Add(Add o)
    {

    this.a=o.a;
    this.b = o.b;
    }
    void addition()
    {
    c=a+b;
    }

    void display()
    {
    System.out.println(c);
    }


    }

    class Addmain
    {
    public static void main(String args[])
    {
    Add obj = new Add(100,200);
    obj.addition();
    obj.display();
    Add obj1 = new Add(obj); //obj=obj1
    obj1.addition();
    obj1.display();
    }

    }

    ReplyDelete
  41. // Write a programe of find max and second max element from given String

    // ADITYA BAGHEL
    class Given
    {
    public static void main(String ar[])
    {
    String s="hello";
    int x=0,max=0,smax=0;
    for(int i=0;imax)
    {
    smax=max;
    max=x;
    }
    else if(x>smax)
    {
    smax=x;
    }
    }
    System.out.println((char)max);
    System.out.println((char)smax);
    }
    }

    ReplyDelete
  42. // Write a programe of Sorting of odd Number.

    // ADITYA BAGHEL

    class Sorted
    {
    public static void main(String ar[])
    {
    int temp=0;
    int array[]={12,21,34,56,67,89,3,88,7};
    for(int i=0;iarray[j]) && (array[i]%2!=0 && array[j]%2!=0))
    {
    temp=array[i];
    array[i]=array[j];
    array[j]=temp;
    }
    }
    }
    for(int i=0;i<array.length;i++)
    {
    System.out.print(array[i] + " ");
    }

    }
    }

    ReplyDelete
  43. Inheritance Example?

    class Circle
    {
    float r;
    float area;
    void accept(float r)
    {
    this.r=r;
    }
    void areaOfCircle()
    {
    area = 3.14F*r*r;
    }

    void display()
    {
    System.out.println(area);
    }
    }

    class Rectangle extends Circle
    {
    float b;
    void accept1(float b)
    {
    this.b=b;
    }
    void areaOfRectangle()
    {
    area = r*b;
    }

    }


    class Triangle extends Rectangle
    {

    void areaOfTriangle()
    {
    area = (r*b)/2;
    }

    }


    class Area
    {
    public static void main(String args[])
    {
    System.out.println("Area of Triangle");
    Triangle obj = new Triangle();
    obj.accept(100);
    obj.accept1(20);
    obj.areaOfTriangle();
    obj.display();
    System.out.println("Area of Circle");
    Circle obj1 = new Circle();
    obj1.accept(100);

    obj1.areaOfCircle();
    obj1.display();
    System.out.println("Area of Rectangle");
    Rectangle obj2 = new Rectangle();
    obj2.accept(100);
    obj2.accept1(10);
    obj2.areaOfRectangle();
    obj2.display();


    }

    }

    ReplyDelete
  44. // Class Addition, Subtraction, Multiplication, Division using possible Inheritance?
    class Add{
    protected int a,b;

    void Accept(int a,int b) {
    this.a=a;
    this.b=b;
    }
    int add() {
    return a+b;
    }
    }
    class Multi extends Add{
    int multi() {
    return a*b;
    }
    }
    class Sub extends Add{
    int sub() {
    return a-b;
    }
    }
    class Div extends Add{
    Div(int a,int b){
    this.a=a;
    this.b=b;
    }
    float div() {
    return a/b;
    }
    }
    class Main {
    public static void main(String[] args) {
    Add a=new Div(4,2);

    System.out.println("Addition: "+ a.add());
    Sub b=new Sub();
    b.Accept(4,2);
    System.out.println("Subtraction: "+ b.sub());
    Multi c=new Multi();
    c.Accept(4,2);
    System.out.println("Multiplication: "+ c.multi());
    Div d=new Div(4,2);

    System.out.println("division: "+ d.div());
    }
    }

    ReplyDelete
  45. // Addition, Subtraction, Multiplication, Division using possible Inheritance?
    class Addition
    {
    float a,b;
    float ans;
    void accept(float a,float b)
    {
    this.a=a;
    this.b=b;
    }
    void add()
    {
    ans=a+b;
    }
    void display()
    {
    System.out.println(ans);
    }
    }
    class Substraction extends Addition
    {
    void substraction()
    {
    ans=a-b;
    }
    }
    class Multiplication extends Addition
    {
    void multiplication()
    {
    ans=a*b;
    }
    }
    class Division extends Addition
    {
    void division()
    {
    ans=a/b;
    }
    }
    class Main_add_sub
    {
    public static void main(String ab[])
    {
    System.out.println("addition is");
    Addition obj=new Addition();
    obj.accept(20,10);
    obj.add();
    obj.display();
    System.out.println("substraction is");
    Substraction obj1=new Substraction();
    obj1.accept(40,24);
    obj1.substraction();
    obj1.display();
    System.out.println("Multiplication is");
    Multiplication obj2=new Multiplication();
    obj2.accept(23,4);
    obj2.multiplication();
    obj2.display();
    System.out.println("Division is");
    Division obj3=new Division();
    obj3.accept(20,5);
    obj3.division();
    obj3.display();
    }
    }

    ReplyDelete
  46. Example of User define function
    class Operation
    {
    int a,b,c;
    void addition() //default without return type
    {
    a=100;
    b=200;
    c=a+b;
    System.out.println(c);

    }

    int substraction() //default with return type
    {
    a=100;
    b=200;
    c=a+b;
    return c;

    }

    void multi(int a,int b) //parametrised without return type
    {

    c=a*b;
    System.out.println(c);

    }

    int division(int a,int b) //param with return type
    {

    c=a/b;
    return c;

    }



    public static void main(String args[])
    {

    Operation obj = new Operation();
    obj.addition();
    int r = obj.substraction();
    System.out.println(r);
    obj.multi(100,2);
    int d = obj.division(100,2);
    System.out.println(d);
    }


    }

    ReplyDelete
  47. import java.util.Scanner;
    class Circle
    {

    public void carea()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the radius");
    int r=sc.nextInt();
    float carea=(float)(3.14*r*r);
    System.out.println("carea="+carea);
    }


    }
    class Rectangle extends Circle
    {

    public void rarea()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the length");
    int length=sc.nextInt();
    System.out.println("Enter the breadth");
    int breadth=sc.nextInt();
    float rarea=length*breadth;
    System.out.println("rarea="+rarea);
    }


    }
    class Triangle extends Rectangle
    {

    public void tarea()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the base");
    int base=sc.nextInt();
    System.out.println("Enter the height");
    int height=sc.nextInt();
    float tarea=(base*height)/2;
    System.out.println("tarea="+tarea);
    }
    public static void main(String args[])
    {
    Triangle obj=new Triangle();
    obj.carea();
    obj.rarea();
    obj.tarea();

    }


    }

    ReplyDelete
  48. //Area of Triangle, Rectangle, Circle using possible Inheritance?
    class Rectangle
    {
    int l,b,r;
    Rectangle(int x,int y,int r1)
    {
    l=x;
    b=y;
    r=r1;
    }
    int getRectangle()
    {
    return l*b;
    }
    }
    class Triangle extends Rectangle
    {
    float a;
    Triangle(int v,int u,int r3)
    {
    super(u,v,r3);
    }
    float getTriangle()
    {
    a=(float)l/2*l*b;
    return (a);
    }
    }
    class Circle extends Triangle
    {
    float a;
    Circle(int u2,int u1,int r2)
    {
    super(u2,u1,r2);
    }
    float getCircle()
    {
    a=(float)3.14*(r*r);
    return (a);
    }
    }
    class Re
    {
    public static void main(String args[])
    {
    Circle m=new Circle(500,80,5);
    System.out.println("Area of Rectangle is : " +m.getRectangle());
    System.out.println("Area of Triangle is : "+m.getTriangle());
    System.out.println("Area of Triangle is : "+m.getCircle());
    }
    }

    ReplyDelete
  49. //Business class
    import java.util.Scanner;
    class EInfo
    {
    int eid;
    String ename;
    String job;
    int salary;
    public void accept()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the id");
    eid=sc.nextInt();
    System.out.println("enter the name");
    ename=sc.next();
    System.out.println("enter the job");
    job=sc.next();
    System.out.println("enter the salary");
    salary=sc.nextInt();

    }
    public void display()
    {
    System.out.println("The id of employee is " +eid);
    System.out.println("the name of employee is " +ename);
    System.out.println("the job of employee is " +job);
    System.out.println("the salary of employee is " +salary);


    }







    }
    //Executable class
    class EMain
    {
    public static void main(String args[])
    {
    EInfo obj1=new EInfo();
    obj1.accept();
    obj1.display();




    }





    }

    ReplyDelete
  50. //Class Addition, Subtraction, Multiplication, Division using possible Inheritance?
    class Addition
    {
    int a,b;
    float s;
    Addition(int x,int y)
    {
    a=x;
    b=y;
    }
    float getAdd()
    {
    s=a+b;
    return s;
    }
    }
    class Subtraction extends Addition
    {
    float s;
    Subtraction(int u,int v)
    {
    super(u,v);
    }
    float getSub()
    {
    s=a-b;
    return s;
    }
    }
    class Multiplication extends Subtraction
    {
    float s;
    Multiplication(int u1,int v1)
    {
    super(u1,v1);
    }
    float getMul()
    {
    s=a*b;
    return s;
    }
    }
    class Division extends Multiplication
    {
    float s;
    Division(int u2,int v2)
    {
    super(u2,v2);
    }
    float getDiv()
    {
    s=a*b;
    return s;
    }
    }
    class Main
    {
    public static void main(String[] args)
    {
    Division d = new Division(10,20);
    System.out.println("The Addition is :" +d.getAdd());
    System.out.println("The Substraction is :" +d.getSub());
    System.out.println("The Multiplication is :" +d.getMul());
    System.out.println("The Division is :" +d.getDiv());
    }
    }

    ReplyDelete
  51. class multiply
    {
    int res;
    int mul(int arr[])
    {
    res=1;
    for(int s:arr)
    {
    res=res*s;
    }
    return res;
    }
    }
    class MatrixMul
    {
    public static void main(String args[])
    {
    multiply obj = new multiply();
    int arr[]={3,2,7,5,9,1,4};
    int res = obj.mul(arr);
    System.out.println("ARRAY MULTIPLICATION IS:- "+res);
    }
    }

    ReplyDelete
  52. # Example of Data Abstraction

    class Bank
    {
    private int bal=500;
    private void credit(int amt )
    {
    bal+=amt;

    }
    private void debit(int amt )
    {
    bal-=amt;

    }

    private void checkBalance()
    {
    System.out.println("balance is "+bal);

    }

    public void login(int pin) //encapsulate the credit() and checkBalance()
    {
    if(pin == 1234)
    {
    credit(12000);
    checkBalance();
    }

    }

    }

    class Customer
    {
    public static void main(String args[])
    {
    Bank obj = new Bank();
    obj.login(1234);

    }


    }

    ReplyDelete
  53. #Function Overloading In Java:-

    class Ope
    {
    void addition(int x,int y)
    {
    System.out.println(x+y);
    }
    void addition(float x,int y)
    {
    System.out.println(x+y);
    }
    void addition(float x[],int y[])
    {
    System.out.println(x[0]+y[0]);
    }

    void addition(int x,float y)
    {
    System.out.println(x+y);
    }
    void addition(float x,float y)
    {
    System.out.println(x+y);
    }
    void addition(double x,float y)
    {
    System.out.println(x+y);
    }

    }

    class OpeMain
    {
    public static void main(String args[])
    {
    Ope obj = new Ope();
    float[] arr = {1,2};
    int [] arr1 = {2,3};
    obj.addition(arr,arr1);

    }

    }

    ReplyDelete
  54. class Sinterest
    {

    void interest(int p,int r,int t) //int
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,long r,long t) //long
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,float r,float t) //float
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,double r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,int r,long t) //int long
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,int r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,long r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,long r,int t) //long int
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,int r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,long r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,float r,double t) //float double
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,double r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,float r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,double r,float t) //double float
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,float r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,double r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,int r,float t) //int float
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,float r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,int r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,int r,double t) //int double
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,double r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,int r,int t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,long r,float t) //long float
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,float r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,long r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,long r,double t) //long double
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,double r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,long r,long t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,float r,int t) //float int
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,int r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,float r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,float r,long t) //float long
    {
    System.out.println((p*r*t)/100);
    }

    void interest(float p,long r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,float r,float t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,double r,int t) //double int
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,int r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(int p,double r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,double r,long t) //double long
    {
    System.out.println((p*r*t)/100);
    }

    void interest(double p,long r,double t)
    {
    System.out.println((p*r*t)/100);
    }

    void interest(long p,double r,double t)
    {
    System.out.println((p*r*t)/100);
    }
    }

    class Main
    {
    public static void main(String args[])
    {
    Sinterest obj = new Sinterest();
    obj.interest(20000,22.3f,3);
    }
    }


    ReplyDelete
  55. #inheritance Example:-
    class Admin
    {
    String name;
    void accept(String name)
    {
    this.name = name;
    }

    void display()
    {
    System.out.println("name is "+name);
    }

    }

    class Employee extends Admin
    {
    int id;
    int sal;
    void accept1(int id,int sal)
    {
    this.id=id;
    this.sal=sal;
    }
    void display1()
    {
    System.out.println("id is " + id + " Salary is " + sal);
    }

    }

    class OtherStaff extends Employee
    {


    int bonus;
    void accept2(int bonus)
    {
    this.bonus=bonus;

    }
    void display2()
    {
    System.out.println("bonus is " + bonus);
    }

    }
    class EmpMain
    {
    public static void main(String args[])
    {
    Admin obj = new Admin();
    obj.accept("Admin");
    obj.display();
    Employee obj1 = new Employee();
    obj1.accept("EMP");
    obj1.accept1(1002,15000);
    obj1.display();
    obj1.display1();
    OtherStaff obj2 = new OtherStaff();
    obj2.accept("EMP");
    obj2.accept1(1003,5000);
    obj2.accept2(500);
    obj2.display();
    obj2.display1();
    obj2.display2();

    }

    }

    ReplyDelete
  56. Name - Suresh Suryavanshi

    class Admin
    {
    String Empnm;
    void accept(String Empnm)
    {
    this.Empnm=Empnm;
    }
    void display()
    {
    System.out.println("Admin name is "+Empnm);
    }
    }
    class Employee extends Admin
    {
    int id;
    int sal;
    void accept1(int id, int sal)
    {
    this.id=id;
    this.sal=sal;
    }
    void display1()
    {
    System.out.println("Employee id "+id);
    System.out.println("salary is "+sal);
    }
    }
    class OtherStaff extends Employee
    {
    int bonus;
    void accept2(int bonus)
    {
    this.bonus=bonus;
    }
    void display2()
    {
    System.out.println("bonus "+bonus);
    }
    }
    class EmAdmain
    {
    public static void main(String[] args)
    {
    Admin a=new Admin();
    a.accept("Suresh Suryavanshi");
    a.display();
    Employee a1=new Employee();
    a1.accept1(110, 40000);
    a1.display1();
    OtherStaff a2=new OtherStaff();
    a2.accept2(4000);
    a2.display2();
    }
    }

    ReplyDelete
  57. class Addition
    {
    float a,b;
    float res;
    void accept(float a,float b)
    {
    this.a=a;
    this.b=b;
    }
    void add()
    {
    res=a+b;
    }
    void display()
    {
    System.out.println(res);
    }
    }

    class Substraction extends Addition
    {
    void substraction()
    {
    res=a-b;
    }
    }

    class Multiplication extends Addition
    {
    void multiplication()
    {
    res=a*b;
    }
    }

    class Division extends Addition
    {
    void division()
    {
    res=a/b;
    }
    }

    class MainInheri
    {
    public static void main(String ab[])
    {
    System.out.println("addition is");
    Addition obj=new Addition();
    obj.accept(33,10);
    obj.add();
    obj.display();


    System.out.println("substraction is");
    Substraction obj1=new Substraction();
    obj1.accept(10,44);
    obj1.substraction();
    obj1.display();

    System.out.println("Multiplication is");
    Multiplication obj2=new Multiplication();
    obj2.accept(21,42);
    obj2.multiplication();
    obj2.display();

    System.out.println("Division is");
    Division obj3=new Division();
    obj3.accept(200,5);
    obj3.division();
    obj3.display();
    }
    }

    ReplyDelete
  58. class AreaofTriangle
    {
    int b,h;
    float res;
    void accept(int b,int h)
    {
    this.b=b;
    this.h=h;
    }
    void area()
    {
    res=(b*h)/2;
    }
    void display()
    {
    System.out.println(res);
    }
    }

    class AreaofRectangle extends AreaofTriangle
    {
    int l,w;
    void accept1(int l,int w)
    {
    this.l=l;
    this.w=w;
    }
    void area1()
    {
    res=l*w;
    }
    }

    class AreaofCircle extends AreaofTriangle
    {
    int r;
    void accept2(int r)
    {
    this.r=r;
    }
    void area2()
    {
    res=3.14f*r*r;
    }
    }


    class AreaMain
    {
    public static void main(String ab[])
    {
    System.out.println("Area of Triangle = ");
    AreaofTriangle obj=new AreaofTriangle();
    obj.accept(33,10);
    obj.area();
    obj.display();


    System.out.println("Area of Rectangle = ");
    AreaofRectangle obj1=new AreaofRectangle();
    obj1.accept1(10,6);
    obj1.area1();
    obj1.display();

    System.out.println("Area of Circle = ");
    AreaofCircle obj2=new AreaofCircle();
    obj2.accept2(12);
    obj2.area2();
    obj2.display();

    }
    }

    ReplyDelete
  59. class AreaofTriangle
    {
    int b,h;
    float res;
    void accept(int b,int h)
    {
    this.b=b;
    this.h=h;
    }
    void area()
    {
    res=(b*h)/2;
    }
    void display()
    {
    System.out.println(res);
    }
    }

    class AreaofRectangle extends AreaofTriangle
    {
    int l,w;
    void accept1(int l,int w)
    {
    this.l=l;
    this.w=w;
    }
    void area1()
    {
    res=l*w;
    }
    }

    class AreaofCircle extends AreaofRectangle
    {
    int r;
    void accept2(int r)
    {
    this.r=r;
    }
    void area2()
    {
    res=3.14f*r*r;
    }
    }


    class AreaMain
    {
    public static void main(String ab[])
    {
    System.out.println("Area of Triangle = ");
    AreaofTriangle obj=new AreaofTriangle();
    obj.accept(33,10);
    obj.area();
    obj.display();


    System.out.println("Area of Rectangle = ");
    AreaofRectangle obj1=new AreaofRectangle();
    obj1.accept1(10,6);
    obj1.area1();
    obj1.display();

    System.out.println("Area of Circle = ");
    AreaofCircle obj2=new AreaofCircle();
    obj2.accept2(12);
    obj2.area2();
    obj2.display();

    }
    }

    ReplyDelete
  60. class Circle
    {
    int r;
    static final double PI = 3.141592653589793;
    void Accept(int r)
    {
    this.r=r;
    }
    void Display()
    {
    System.out.println(PI*r*r);
    }
    }
    class Rectangle
    {
    int b,h;
    void Accept1(int b,int h)
    {
    this.b=b;
    this.h=h;
    }
    void Display1()
    {
    System.out.println(b*h);
    }
    }
    class Triangle extends Rectangle
    {
    void Display2()
    {
    System.out.println(b*h/2);
    }
    }
    class AreaMain
    {
    public static void main(String args[])
    {
    Circle obj = new Circle();
    obj.Accept(14);
    obj.Display();
    Rectangle obj1 = new Rectangle();
    obj1.Accept1(8,9);
    obj1.Display1();
    Triangle obj2 = new Triangle();
    obj2.Accept1(7,10);
    obj2.Display2();
    }
    }

    ReplyDelete
  61. class Add
    {
    int a,b;
    void Accept(int a,int b)
    {
    this.a=a;
    this.b=b;
    }
    void Display()
    {
    System.out.println(a+b);
    }
    }
    class Sub extends Add
    {
    void Display1()
    {
    System.out.println(a-b);
    }
    }
    class Div extends Add
    {
    void Display2()
    {
    System.out.println(a/b);
    }
    }
    class Mul extends Add
    {
    void Display3()
    {
    System.out.println(a*b);
    }
    }
    class Oprations
    {
    public static void main(String args[])
    {
    Add obj = new Add();
    obj.Accept(10,45);
    obj.Display();
    Sub obj1 = new Sub();
    obj1.Accept(21,9);
    obj1.Display1();
    Div obj2 = new Div();
    obj2.Accept(80,10);
    obj2.Display2();
    Mul obj3 = new Mul();
    obj3.Accept(21,10);
    obj3.Display3();
    }
    }

    ReplyDelete
  62. package inheritance;

    class AreaofCircle
    {
    float a;
    float res;
    void accept(float a)
    {
    this.a=a;
    }
    void area()
    {
    res=3.14f*a*a;
    }
    void display()
    {
    System.out.println(res);
    }
    }


    class AreaofTriangle extends AreaofCircle
    {
    float b;
    void accept1(float b)
    {
    this.b=b;
    }
    void area1()
    {
    res=(a*b)/2;
    }

    }

    class AreaofRectangle extends AreaofTriangle
    {
    void area2()
    {
    res=a*b;
    }
    }



    class AreaMain
    {
    public static void main(String ab[])
    {
    System.out.println("Area of circle = ");
    AreaofCircle obj=new AreaofCircle();
    obj.accept(12);
    obj.area();
    obj.display();


    System.out.println("Area of triangle = ");
    AreaofTriangle obj1=new AreaofTriangle();
    obj1.accept(10);
    obj1.accept1(6);
    obj1.area1();
    obj1.display();

    System.out.println("Area of rectangle = ");
    AreaofRectangle obj2=new AreaofRectangle();
    obj2.accept(17);
    obj2.accept1(8);
    obj2.area2();
    obj2.display();

    }
    }

    ReplyDelete
  63. # interface example:-

    interface Device
    {

    void multimedia();
    void calling();
    void print();

    }

    interface Promotion
    {
    void salesPlan();
    void tvPromotion();
    void branding();

    }
    class MyDevice implements Device,Promotion
    {
    public void multimedia()
    {
    System.out.println("Multimedia");
    }
    public void calling()
    {
    System.out.println("Calling");

    }
    public void print()
    {
    System.out.println("Print");
    }

    public void salesPlan()
    {
    System.out.println("Print");
    }
    public void tvPromotion()
    {
    System.out.println("Promotio");

    }
    public void branding()

    {
    System.out.println("Branding");
    }

    }

    class Customer
    {
    public static void main(String args[])
    {
    Device obj = new MyDevice();
    obj.multimedia();
    Promotion obj1 = new MyDevice();

    obj1.branding();


    }
    }

    ReplyDelete
  64. Ankita Verma

    import java.util.Scanner;
    class Employee
    {
    int eid;
    String ename;
    String ejob;
    float esalary;
    Scanner sc=new Scanner(System.in);
    void accept(int eid,String ename,String ejob,float esalary)
    {
    this.eid=eid;
    this.ename=ename;
    this.ejob=ejob;
    this.esalary=esalary;
    }
    void display()
    {
    System.out.println(+eid);
    System.out.println(ename);
    System.out.println(ejob);
    System.out.println(+esalary);
    }
    }
    class EmployeeMain
    {
    public static void main (String[]args)
    {
    int num,id;
    String name,job;
    float salary;

    System.out.println("enter the number Employee");
    Scanner sc=new Scanner(System.in);
    num=sc.nextInt();
    Employee obj[]=new Employee[num];
    for(int i=0;i<num;i++)
    {
    System.out.println("enter the element for "+i+"index");
    obj[i]=new Employee();
    System.out.println("enter eid");
    id=sc.nextInt();
    System.out.println("enter ename");
    name=sc.next();
    System.out.println("enter ejob");
    job=sc.next();
    System.out.println("enter esalary");
    salary=sc.nextFloat();
    obj[i].accept(id,name,job,salary);
    }
    System.out.println("Employee infomation is");
    for(int i=0;i<=num;i++)
    {
    obj[i].display();
    }
    }
    }

    ReplyDelete
  65. Roshnee Rathode(batch 6 to 7)
    //Que.1- Area of Triangle,Rectangle,Circle using possible inheritance.(Multiple inheritance)
    import java.util.Scanner;
    class Triangle
    {
    int A,b,h;
    void show()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    b=sc.nextInt();
    h=sc.nextInt();
    A=(b*h)/2;
    }
    void display()
    {
    System.out.println("Area of Triangle="+A);
    }
    }

    class Rectangle extends Triangle
    {
    int A,l,w;
    void show1()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    l=sc.nextInt();
    w=sc.nextInt();
    A=l*w;
    }
    void display1()
    {
    System.out.println("Area of Rectangle="+A);
    }
    }

    class Circle extends Rectangle
    {
    int A,r;
    void show2()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    r=sc.nextInt();
    A=(22*r*r)/7;
    }
    void display2()
    {
    System.out.println("Area of Circle="+A);
    }
    }

    class Main
    {
    public static void main(String args[])
    {
    Rectangle obj=new Rectangle();
    obj.show();
    obj.display();
    obj.show1();
    obj.display1();
    Circle obj1=new Circle();
    obj1.show1();
    obj1.display1();
    obj1.show2();
    obj1.display2();
    }
    }

    ReplyDelete
  66. Roshnee Rathode(batch 6 to 7)
    //Que.1- Area of Triangle,Rectangle,Circle using possible inheritance.(Multilevel inheritance)
    import java.util.Scanner;
    class Triangle
    {
    int A,b,h;
    void show()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    b=sc.nextInt();
    h=sc.nextInt();
    A=(b*h)/2;
    }
    void display()
    {
    System.out.println("Area of Triangle="+A);
    }
    }

    class Rectangle extends Triangle
    {
    int A,l,w;
    void show1()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    l=sc.nextInt();
    w=sc.nextInt();
    A=l*w;
    }
    void display1()
    {
    System.out.println("Area of Rectangle="+A);
    }
    }

    class Circle extends Rectangle
    {
    int A,r;
    void show2()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    r=sc.nextInt();
    A=(22*r*r)/7;
    }
    void display2()
    {
    System.out.println("Area of Circle="+A);
    }
    }

    class Main
    {
    public static void main(String args[])
    {
    Rectangle obj=new Rectangle();
    obj.show();
    obj.display();
    obj.show1();
    obj.display1();
    Circle obj1=new Circle();
    obj1.show1();
    obj1.display1();
    obj1.show2();
    obj1.display2();
    }
    }

    ReplyDelete
  67. //Roshnee Rathode(batch 6 to 7)
    //Que.2- Class Addition,Subtraction,Multiplication,Division using possible inheritance.(Hierarchical inheritance)

    import java.util.Scanner;
    class Addition
    {
    int x,y,z;
    void set()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    x=sc.nextInt();
    y=sc.nextInt();
    z=x+y;
    }
    void display()
    {
    System.out.println("Addition the number="+z);
    }
    }

    class Subtraction extends Addition
    {
    int x,y,z;
    void set1()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    x=sc.nextInt();
    y=sc.nextInt();
    z=x-y;
    }
    void display1()
    {
    System.out.println("Subtraction the number="+z);
    }
    }

    class Multiplication extends Addition
    {
    int x,y,z;
    void set2()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    x=sc.nextInt();
    y=sc.nextInt();
    z=x*y;
    }
    void display2()
    {
    System.out.println("Multiplication the number="+z);
    }
    }

    class Division extends Addition
    {
    int x,y,z;
    void set3()
    {
    System.out.println("Enter any number");
    Scanner sc=new Scanner(System.in);
    x=sc.nextInt();
    y=sc.nextInt();
    z=x/y;
    }
    void display3()
    {
    System.out.println("Division the number="+z);
    }
    }

    class MainInherit
    {
    public static void main(String args[])
    {
    Subtraction obj=new Subtraction();
    obj.set();
    obj.display();
    obj.set1();
    obj.display1();
    Multiplication obj1=new Multiplication();
    obj1.set();
    obj1.display();
    obj1.set2();
    obj1.display2();
    Division obj2=new Division();
    obj2.set();
    obj2.display();
    obj2.set3();
    obj2.display3();
    }
    }

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post