Tuesday 19 September 2023

JAVA PROGRAMMING - OOPS CHAPTER 1


Object-Oriented Programming Chapter 1:

Basics by Souradeep Roy Using IntelliJ IDEA Community version:-
___________________________________________________________________________________________


INTRODUCTION:
-------------
Java was developed by James Gosling, Patrick Naughton, Chris Warth, Ed Frank and Mike
Sheridan at Sun Microsystems in 1991. Initially, it was called 'Oak' but was renamed 'Java'
in 1995. Java was influenced by C++.

 Characteristics:

1) Platform independent (architecture neutral)
2) Object-oriented
3) Multi-threaded
4) Distributed
5) Dynamic

 Bytecode:
------------

Bytecode is a highly optimized set of instructions designed to be executed by the Java run-
time system called the Java Virtual Machine (JVM). JVM is an interpreter for bytecode.

The output of a Java compiler is not executable code, rather it is bytecode. This bytecode
can be run in a wide variety of environments by JVM that will differ from platform to
platform.


The main motive of Java is to implement the concept of OOPS and solve all the real world problems with the help of object creation......
So, lets see how to implement object creation

Question 1: Write a program in Java to demostrate object creation
------------------------------------------------------------------------------------------------------------------------

Code:
-----
class Techno
{
    public void hello()
    {
        System.out.println("hello welcome to the demostration of Object Creation");
    }
}

public class objcreation
{
    public static void main(String[] args)
 {
        Techno m1=new Techno();//always class name is used then object name and then new keyword
        m1.hello();//calling the method by using dot specifier and with the help of the object

    }
}

Output:
--------
class Techno
{
    public void hello()
    {
        System.out.println("hello welcome to the demostration of Object Creation");
    }
}
public class objcreation {

    public static void main(String[] args) {

        Techno m1=new Techno();//always class name is used then object name and then new keyword

        m1.hello();//calling the method by using dot specifier and with the help of the object

    }
}

Output:-
--------
"C:\Program Files\Java\jdk-20\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\lib\idea_rt.jar=55742:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\hp\IdeaProjects\justforfun\out\production\justforfun objcreation
hello welcome to the demostration of Object Creation

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
Question 2: //CREATING MORE THAN ONE OBJECTS

Code:
-----
class Techno
{
    public void hello()
    {
        System.out.println("hello welcome to the demostration of Object Creation");
    }
    public void add(int a,int b)
    {
        int c=a+b;
        System.out.println("Addition of 2 numbers\t"+c);
    }
}
public class objcreation {
    public static void main(String[] args)
{
        Techno m1=new Techno();//always class name is used then object name and then new keyword

        Techno m2=new Techno();//creating 2nd object using same class

        m1.hello();//calling the method by using dot specifier and with the help of the object

        m2.add(8,4); //passing two numbers as parameters to perform operation
    }
}


Output:-
--------
hello welcome to the demostration of Object Creation

Addition of 2 numbers    12

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
Question 3: //CLASS CONTAINING A METHOD


Code:
-----
import java.util.Scanner;
class Techno
{
    double w,h,d;

    public void result()
    {
        System.out.println("Volume is");

        System.out.println(w*h*d);
    }
}
public class objcreation
{
    public static void main(String[] args)
{
        Scanner input=new Scanner(System.in);

        Techno m1=new Techno();

        System.out.println("Enter the width , height , depth");

        m1.w= input.nextDouble();

        m1.h= input.nextDouble();

        m1.d= input.nextDouble();

        m1.result();

    }
}


Output:-
--------

Enter the width , height , depth

5
6
1
Volume is
30.0

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
Question 4://METHOD RETURNING A VALUE


Code:
-----
import java.util.Scanner;
class Techno
{
    double w,h,d;

    public double result()

    {
      return(w*h*d);
    }
}
public class objcreation {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

        Techno m1=new Techno();

        System.out.println("Enter the width , height , depth");

        m1.w= input.nextDouble();

        m1.h= input.nextDouble();

        m1.d= input.nextDouble();

        System.out.println("The volume is "+m1.result());

    }
}

Output:-
--------

Enter the width , height , depth

5
5
5
The volume is 125.0

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------

Question 5://PARAMETARIZED METHOD

Code:
-----
class Box
{
    double width,height,depth;
    double volume()
    {
        return (width * height * depth);
    }
    void getData(double w, double h, double d)
    {
        width = w; height = h; depth = d;
    }
}
public class Jop {
    public static void main(String[] args)
    {
        Box mybox1 = new Box();
        Box mybox2 = new Box();
        double vol;
        mybox1.getData(10,20,15);
        mybox2.getData(3,6,9);
        vol = mybox1.volume();
        System.out.println("Volume 1 is :" + vol);
        vol = mybox2.volume();
        System.out.println("Volume 2 is :" + vol);
    }
}

Output:-
--------
Volume 1 is :3000.0
Volume 2 is :162.0

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
Question 6://CONSTRUCTOR DEMO


Code:
-----
class Type
{

     Type() // Constructor Note: the constructor name and class name is always the same
     {
         System.out.println("This is simple constructor representing demo Constructor");
     }

    double w,h,d;

    Type(double w,double h,double d)//Parameterized Constructor
    {
        this.w =w;
        this.h = h;
        this.d = d;
    }

    double volume() //method
    {
        return (w * h * d);
    }
}

public class Jop {  //Main class

    public static void main(String[] args) //Main Function
    {
        Type m1=new Type(); // this syntax will automatically invoke the default constructor

        Type m2=new Type(10,10,10);//this syntax will automatically invoke the parameterized constructor

        double vol;

        vol=m2.volume();

        System.out.println("The volume is "+vol);
    }
}

Output:-
--------

This is simple constructor representing demo Constructor
The volume is 1000.0

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------

Question 7://OBJECTS MAY BE PASSED TO METHODS

Code:
-----
class Test {

    int a, b;

    Test(int i, int j) {

        a = i;
        b = j;

    }

    boolean equals(Test o)
    {
        if(o.a == a && o.b == b)
            return true;

        else
        {
            return false;
        }
    }
}

    public class Jop {
        public static void main(String[] args) {
            Test obj1 = new Test(100, 22);
            Test obj2 = new Test(100, 22);
            Test obj3 = new Test(15, 20);
            System.out.println("obj1 = = obj2 " + obj1.equals(obj2));
            System.out.println("obj1 == obj3 " + obj1.equals(obj3));
            System.out.println("obj2 == obj3 " + obj2.equals(obj3));

        }
    }

Output:-
--------
obj1 = = obj2 true
obj1 == obj3 false
obj2 == obj3 false

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
Question 8://STACK IMPLEMENTATION IN JAVA


class Stack
{
    int stck[] = new int[15];
    int top;
    Stack() //constructor to initialize instance variables
    {
        top = -1;
    }
    void push(int item)//method
    {
        if(top == 14)
            System.out.println("Stack is full");
else
    stck[++top] = item;
    }
    int pop()//method
    {
        if(top<0)
        {
            System.out.println("Stack underflow");
            return 0;
        }
        else return stck[top--];
    }
    void display()
    {
        if(top == -1) // IF THE STACK IS EMPTY
System.out.println("Stack is Empty");
else
        {
            System.out.println("\nStack elements are:");
            for(int i = 0;i < top;i++)
                System.out.print(stck[i] + ",");

        }
    }
}
    public class Jop {
        public static void main(String[] args) {
            Stack myStack = new Stack();//new object creation
            int val;
            myStack.push(10); myStack.push(20); myStack.push(30);
            myStack.push(40);myStack.push(50); myStack.push(60);
            myStack.push(70);
            myStack.display();
            val = myStack.pop();
            System.out.print("\nPoped element is:" + val);
            val = myStack.pop();
            System.out.print("\nPoped element is:" + val);
            myStack.display(); System.out.println();

        }
    }

Output:-
--------

"C:\Program Files\Java\jdk-20\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\lib\idea_rt.jar=55351:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\hp\IdeaProjects\justforfun\out\production\justforfun Jop

Stack elements are:
10,20,30,40,50,60,
Poped element is:70
Poped element is:60
Stack elements are:
10,20,30,40,

Process finished with exit code 0
-----------------------------------------------------XXXXXXXX----------------------------------------------------------------
                    -------End of Chapter 1 Basics of OOPS-------

 

Saturday 8 July 2023

Java Chapter 6 Methods

METHODS IN JAVA 

[Edited and compiled by Souradeep Roy using IntelliJ IDEA (community version)
A method is nothing but a function only which is written inside a class.Since Java is an Object Oriented Programming Language,
we need to write the method inside some class in order to use it.
For instance, if you have written instructions to draw a circle in the method,
it will do that task. You can insert values or parameters into methods,
and they will only be executed when called.

Syntax:-

dataType name()
{
//method body
}

=============================================================================================================================

Now, We will quickly take a look at the examples provided below in order to create a better understanding and clarification

of the Methods in Java.


1.1                 WAP in Java to create a Method to print your name.
_____________________________________________________________________________________________________________________________

 
CODE:-
------
import java.util.Scanner;

public class Function
{
    public static void PrintName(String name)// User defined Function

    {

        Scanner input=new Scanner(System.in);

        System.out.println("Your name is "+name);

    }
 
    public static void main(String[] args)             

 {
        Scanner input=new Scanner(System.in);

        String nam;

        System.out.println("Enter your name ");

        nam= input.nextLine();

        PrintName(nam);//Function call

    }

    }

Output:-
--------
Enter your name

Souradeep

Your name is Souradeep

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------

1.2            Write a method in Java to perform a simple addition of 2 numbers
_____________________________________________________________________________________________________________________________

CODE:-
------
/*Function to accept and add 2 numbers */

import java.util.Scanner;


public class Function
{
   public static int sumcalc(int a,int b)
{                              //method definition
       int c;

       c=a+b;

       System.out.println(a+" + "+b+" = "+c);

       return  c;
    }

    public static void main(String[] args)
 {                                       //main function
       Scanner input=new Scanner(System.in);

       int x,y;

       System.out.println("Enter 2 numbers to perform addition ");

       x= input.nextInt();

       y= input.nextInt();

       sumcalc(x,y);//Method call
    }

    }


Output:-
--------
Enter 2 numbers to perform addition

4

5

4 + 5 = 9

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.3            Wap in Java to make a basic calculator using function
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function
{
   public static int calculation(int a,int b)
{
       int c,d,e,f;

       c=a+b;

       d=a-b;

       e=a*b;

       f=a/b;

       System.out.println(a+" + "+b+" = "+c);

       System.out.println(a+" - "+b+" = "+d);

       System.out.println(a+" * "+b+" = "+e);

       System.out.println(a+" / "+b+" = "+f);

       return 0;
    }

    public static void main(String[] args)
{
       Scanner input=new Scanner(System.in);

       int x,y;

       System.out.println("Enter 2 numbers to perform calculation ");

       x= input.nextInt();

       y= input.nextInt();

       calculation(x,y);//Method call

    }

    }


Output:-
--------
Enter 2 numbers to perform calculation
8
4
8 + 4 = 12
8 - 4 = 4
8 * 4 = 32
8 / 4 = 2

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.4    Write a method in Java to calculate the distance in Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter,       Inch, Feet and Gauge if it is entered as in Kilometer
_____________________________________________________________________________________________________________________________
    

CODE:-
------
import java.util.Scanner;
public class Function
{
public static int calculation(int km)
{
       double hm=0,dcm=0,m=0,dm=0,cm=0,mm=0,in=0,ft=0,g=0;

       hm=km*10;

       dcm=hm*10;

       m=dcm*10;

       dm=m*10;

       cm=dm*10;

       mm=cm*10;

       in=cm*2.54;

       ft=in/12;

       g=ft/3;

       System.out.println("Distance in Kilometer: "+km);

       System.out.println("Distance in Hectometer: "+hm);

       System.out.println("Distance in Decameter: "+dcm);

       System.out.println("Distance in Meter: "+m);

       System.out.println("Distance in Decimeter: "+dm);

       System.out.println("Distance in Centimeter: "+cm);

       System.out.println("Distance in Millimeter: "+mm);

       System.out.println("Distance in Inch: "+in);

       System.out.println("Distance in Feet: "+ft);

       System.out.println("Distance in Gauge: "+g);

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

       int x;

       System.out.println("Enter a number in Km to convert ");

       x=input.nextInt();

       calculation(x);
    }

    }

Output:-
--------
Enter a number in Km to convert
5

Distance in Kilometer: 5

Distance in Hectometer: 50.0

Distance in Decameter: 500.0

Distance in Meter: 5000.0

Distance in Decimeter: 50000.0

Distance in Centimeter: 500000.0

Distance in Millimeter: 5000000.0

Distance in Inch: 1270000.0

Distance in Feet: 105833.33333333333

Distance in Gauge: 35277.777777777774

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.5                Write a program to create a salary sheet using only method    
____________________________________________________________________________________________________________________________


CODE:-
------
import java.util.Scanner;

public class Function {

   public static int calculation(int basic){

       double da,ta,hra,it,pf,gp,np;

       da=basic*0.45;

       ta=basic*0.30;

       hra=basic*0.20;

       it=basic*0.04;

       pf=basic*0.08;

       gp=da+ta+hra+basic;

       np=gp-it-pf;

       System.out.println("Basic salary is: "+basic);

       System.out.println("D.A(Dearness_Allowance) is: "+da);

       System.out.println("T.A(Travel_Allowance) is: "+ta);

       System.out.println("H.R.A(House_Rent_Allowens) is: "+hra);

       System.out.println("I.T(Income_Tax) is: "+it);

       System.out.println("P.F(Provedent_Fund) is: "+pf);

       System.out.println("G.P(Gross_Pay) is: "+gp);

       System.out.println("N.P(Net_pay) is: "+np);

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int salary;

        System.out.println("Enter your basic salary ");

        salary= input.nextInt();

        calculation(salary);
    }

    }


Output:-
--------
Enter your basic salary

20000

Basic salary is: 20000

D.A(Dearness_Allowance) is: 9000.0

T.A(Travel_Allowance) is: 6000.0

H.R.A(House_Rent_Allowens) is: 4000.0

I.T(Income_Tax) is: 800.0

P.F(Provedent_Fund) is: 1600.0

G.P(Gross_Pay) is: 39000.0

N.P(Net_pay) is: 36600.0

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.6                Wap to create a method to swap 2 numbers
____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function
{
   public static int swap(int a,int b)
{
        a=a+b;

        b=a-b;

        a=a-b;

       System.out.println("After Swapping "+"a="+a+","+"b="+b);

       return 0;
    }

    public static void main(String[] args)
{
       Scanner input=new Scanner(System.in);

        int x,y;

        System.out.println("Enter 2 numbers to peform swap ");

        x=input.nextInt();

        y= input.nextInt();

        swap(x,y);
    }

    }



Output:-
--------
Enter 2 numbers

5

4

After Swapping a=4,b=5

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.7                    Write a method in JAVA to reverse a number
____________________________________________________________________________________________________________________________


CODE:-
------
import java.util.Scanner;

public class Function {

   public static int reverse (int n){

       int i,b=0;

       do {

           b=b*10+n%10;

           n/=10;
       }

       while(n!=0);

       System.out.println(" The output is ="+b);

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println("Enter a number ");

        x= input.nextInt();

        reverse(x);

    }

    }


Output:-
--------
Enter a number

123

The output is = 321

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.8                    Write Method in Java to check password        
____________________________________________________________________________________________________________________________


CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Password (int pass){

        if(pass==75959)
        {
            System.out.println("Entered password matched (Welcome user 587) ");
        }

        else
    {
            System.out.println("incorrect passcode access denied ");
        }

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println("Enter Your Password to Login  ");

        x= input.nextInt();

        Password(x);
    }

    }

Output:-
--------
Enter Your Password to Login  

75959

Entered password matched (Welcome user 587)

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.9            Write a Method to check voter ability if above 18 give a choice to cast their vote
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function {

   public static int vote (int age){

       Scanner input=new Scanner(System.in);

       int i;

        if(age>=18) {

            System.out.println("You are eligible to vote ");

            int number;

            System.out.println("\nPress 1 to vote TMC ");

            System.out.println("\n Press 2 to vote BJP ");

            System.out.println("\n Press 3 to vote All India Congress ");

            System.out.println("\n Press 4 to vote LEFT");

            System.out.println("\n Press 5 to vote others ");

            System.out.println("\n Enter Your Choice");

            number = input.nextInt();


            switch (number) {

                case 1:

                    System.out.println("Thanks May god bless you :)");

                    break;

                case 2:

                    System.out.println("We are grateful and honoured ;)");

                    break;

                case 3:
                    System.out.println("Faith is the Ultimatum thank You :( ");

                    break;
                case 4:

                    System.out.println("Have a good You may proceed futher ;(");

                    break;

                case 5:

                    System.out.println("Thank you Have a good day ");

                    break;

                default:

                    System.out.println("\n\nYou have entered an invalid option\nPlease try again");
            }
        }

        else {

            System.out.println("Sorry We found you are not eligible!:( ");
        }

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Welcome to Panchayat elections Enter Your Age to check voter abitlity and proceed further  ");

        x= input.nextInt();

        vote(x);
    }

    }


Output:-
--------
Welcome to Panchayat elections Enter Your Age to check voter abitlity and proceed further  

56

You are eligible to vote

Press 1 to vote TMC

 Press 2 to vote BJP

 Press 3 to vote All India Congress

 Press 4 to vote LEFT

 Press 5 to vote others

Enter Your Choice

1

Thanks May god bless you :)

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.10            Write a Method in Java to check whether a number is an Armstrong number or not     
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Armstrong (int number){

       int remainder,temp,sum=0;

       temp=number;

       do {
           remainder = temp%10;

           sum += remainder*remainder*remainder;

           temp = temp/10;
       }

       while(temp!=0);

       if ( number == sum )

           System.out.println("Entered Number is an Armstrong Number");

       else

           System.out.println("Entered Number is not an Armstrong Number");

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter a number to check whether the is a Armstrong number or not ");

        x= input.nextInt();

        Armstrong(x);
    }

    }

Output:-
--------
Enter a number to check whether the is a Armstrong number or not

153

Entered Number is an Armstrong Number

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.11                    Write a program to Print Star Pattern
_____________________________________________________________________________________________________________________________


CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Pattern(int number){

       int i,j;

       for(i=0;i<number;i++)

       {

           for(j=0;j<=i;j++)

           {

               System.out.printf("*");

           }

           System.out.println("");
       }

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the number of rows ");

        x= input.nextInt();

        Pattern(x);
    }

    }

Output:-
--------
Enter the number of rows
5

*
**
***
****
*****

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.12            Write a program to print all natural numbers within range
_____________________________________________________________________________________________________________________________
    
CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Natural(int number){

       int i,j;

       System.out.println("All natural numbers within range ");

      for(i=1;i<=number;i++)

      {

          System.out.println(""+i);

      }

       return 0;

    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the range ");

        x= input.nextInt();

        Natural(x);
    }

    }

Output:-
--------
Enter the range

10

All natural numbers within range
1
2
3
4
5
6
7
8
9
10

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.13            Write a Java program to find out value of a power number without using pow().
_____________________________________________________________________________________________________________________________

    
CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Power(int n,int p){

       int calc=1,i;

        for(i=1;i<=p;i++)
       {
           calc*=n;
       }

       System.out.println(n+" Raised to "+p+" = "+calc);

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x,y;

        System.out.println(" Enter the number ");

        x= input.nextInt();

        System.out.println("Enter the Power ");

        Power(x,y);
    }

    }


Output:-
--------

Enter the number
5
Enter the Power
2

5 Raised to 2 = 25

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.14            Write a method in Java to prove the execution and concept of array.    
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Array(int n){

       Scanner input = new Scanner(System.in);

       int i;

       int[] arr= new int[n];

       System.out.println("Enter the elements of  the array");

       for(i=0;i<n;i++)

       {

           arr[i]=input.nextInt();
       }

       System.out.println("Array elements are ");

       for(i=0;i<n;i++)

       {
           System.out.println(arr[i]);
       }

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the size of the array ");

        x= input.nextInt();

        Array(x);
    }

    }


Output:-
--------
Enter the size of the array
5
Enter the elements of  the array
3
2
1
7
8
Array elements are
3
2
1
7
8

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.15                Write a method in JAVA to print array elements in reverse
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function {

   public static int ArrayReverse(int n){

       Scanner input = new Scanner(System.in);

       int i;

       int[] arr= new int[n];

       System.out.println("Enter the elements of  the array");

       for(i=0;i<n;i++)

       {

           arr[i]=input.nextInt();
       }

       System.out.println("Array elements in reverse are ");

       for(i=n-1;i>=0;i--)

       {
           System.out.println(arr[i]);
       }

       return 0;
    }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the size of the array ");

        x= input.nextInt();

        ArrayReverse(x);
    }

    }


Output:-
--------

Enter the size of the array
2
Enter the elements of  the array
6
3
Array elements in reverse are
3
6

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.16                Write a method in Java to find out the max and min element
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Array(int n){

       Scanner input = new Scanner(System.in);

       int i;

       int [] arr=new int[n];

       int min=Integer.MAX_VALUE;

       int max=Integer.MIN_VALUE;

       System.out.println("Enter the elements of the array ");

       for(i=0;i<n;i++)

       {

           arr[i]= input.nextInt();

       }

       for(i=0;i<n;i++)

       {

           if(arr[i]<min)

               min=arr[i];

           if(arr[i]>max)

               max=arr[i];
       }

       System.out.println("Max element is "+max);

       System.out.println("Min element is "+min);

       return 0;
   }



    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the size of the array ");

        x= input.nextInt();

        Array(x);
    }

    }


Output:-
--------
Enter the size of the array

5

Enter the elements of the array
2
3
4
5
6

Max element is 6

Min element is 2

Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.17            Write a program in Java to find out the frequency of an element using a method
_____________________________________________________________________________________________________________________________


CODE:-
------
import java.util.Scanner;

public class Function {

   public static int Arrayfrequent(int n){

       Scanner input = new Scanner(System.in);

       int [] num=new int[n];

       int i,count=0;

       System.out.printf("Enter 10 Elements of array");

       for(i=0;i<=n;i++)

       {
           System.out.printf("\n%d => ",i);

           num[i]=input.nextInt();
       }

       System.out.printf("Enter the Element to search ");

       n= input.nextInt();

       for(i=0;i<=n;i++)

       {
           if (num[i]==n)

               count++;

       }

       System.out.printf("\n The Number %d found %d time(s) in the Array",n,count);

       return 0;
   }

    public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

        int x;

        System.out.println(" Enter the size of the array ");

        x= input.nextInt();

        Arrayfrequent(x);
    }

    }

Output:-
--------
"C:\Program Files\Java\jdk-20\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\lib\idea_rt.jar=57308:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\hp\IdeaProjects\justforfun\out\production\justforfun Function
Enter the size of the array
5

Enter 10 Elements of array

0 => 2

1 => 2

2 => 3

3 => 4

4 => 5

5 => 6

Enter the Element to search
2

The Number 2 found 2 time(s) in the Array
Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------
1.18            Write a method to print the sum of 2 arrays(Matrix format)
_____________________________________________________________________________________________________________________________

CODE:-
------
import java.util.Scanner;
public class Function {
   public static int Arrayfrequent(int n){
       Scanner sc=new Scanner(System.in);

       int [] a=new int[n];

       int [] b=new int[n];

       int [] c=new int[n];

       int i;

       System.out.printf("\n 1st Array..............\n\n");

       for(i=0;i<n;i++)

       {
           System.out.printf("Enter the Element %d ",i);

           a[i]= sc.nextInt();

       }

       System.out.printf("\n 2nd Array..............\n\n");

       for(i=0;i<n;i++)

       {
           System.out.printf("Enter the Element %d ",i);

           b[i]= sc.nextInt();
       }

       System.out.printf("\n Result Array..............\n\n");

       for(i=0;i<n;i++)

       {

           c[i]=a[i]+b[i];

           System.out.printf(" %d + %d = %d\n",a[i],b[i],c[i]);

       }

       System.out.printf("Press Any Key to Exit");
       return 0;
   }
    public static void main(String[] args) {
       Scanner input=new Scanner(System.in);
        int x;
        System.out.print("Enter the  array size : ");
        x= input.nextInt();
        Arrayfrequent(x);
    }
    }


Output:-
--------
Enter the  array size : 5

 1st Array..............

Enter the Element 0 1
Enter the Element 1 2
Enter the Element 2 3
Enter the Element 3 4
Enter the Element 4 7

 2nd Array..............

Enter the Element 0 5
Enter the Element 1 6
Enter the Element 2 4
Enter the Element 3 1
Enter the Element 4 3

 Result Array..............

 1 + 5 = 6
 2 + 6 = 8
 3 + 4 = 7
 4 + 1 = 5
 7 + 3 = 10
Press Any Key to Exit
Process finished with exit code 0
-----------------------------------------------------------------------------------------------------------------------------

Good bye and happyCoding<____________________________________________________



Friday 7 July 2023

Spoken English Practice Level 4





Spoken English Level 4




A. COMPLEX EXPERIENCE SHARE:

[All about your feelings]

1. When you experienced a quarrel.

2. When you experienced a critical accident.

3. When you experienced a police case.

4. When you experienced a problem in bank.

5. When you experienced a problem in school / college.



B. JOB INTERVIEW QUESTIONS



1) HOW ARE YOU TODAY?

IT'S OK. I AM FINE BUT WITH A MIX STATE OF MY MIND, A LITTLE BIT OF NERVOUSNESS, A LITTLE BIT OF EXCITEMENT AND LOTS OF CURIOSITY.



2) HOW WAS YOUR JOURNEY?

I TOOK THE TRAIN FROM SUBHASGRAM. IT WAS LITTLE BIT OF CROWDY BUT I MANAGE IT.



3) WHAT IS YOUR GREATEST STRENGTH?

I CAN MANAGE THE GIVEN TASK AT MY LEVEL BEST WITH MY POSITIVE APPROACH. I CAN SOLVE THE PROBLEM AND LEAVE NO SPACE FOR ANY COMPLAIN.



4) WHAT IS YOUR GREATEST WEAKNESS?

ACTUALLY IT IS VERY DIFFICULT TO SAY. USUALLY I CAN'T SPEAK NO TO MY FRIENDS FOR THE HELP. I ALSO FORGET THE WHOLE WORLD AND PERSONAL PROBLEMS IN MY WORK TIME.



5) WHY SHOULD WE HIRE YOU?

ACTUALLY I NEED MONEY AND YOU NEED A HARD WORKING AND RESPONSIBLE PERSON. AND I THINK I CAN FULFIL YOUR REQUIREMENTS AND ADJUST TO YOUR NEEDS.



6) WHAT ARE YOUR SALARY EXPECTATIONS?

WELL, IT'S REALLY TOUGH QUESTION FOR ME. AS I AM A FRESHER AND HAVING NO SUCH TYPE OF ANY EXPERIENCE. SO I WANT TO GET A BETTER EXPERIENCE AND I THINK YOU ARE THE BEST PERSON TO JUSTIFY MY SALARY. I KNOW, THERE IS NO NEED TO TEACH A JUWELLER TO RECOGNISE A JUWELL.



7)WHY ARE YOU LEAVING YOUR PREVIOUS JOB?

WELL, ACTUALLY IN MY PREVIOUS JOB EVERYTHING WAS GOOD. THEY WERE PROVIDING ME A GOOD OPPORTUNITY AND HANDSOME SALARY ALSO BUT FROM THERE I CAN'T GET THE IMPROVEMENT OF MY KNOWLEDGE. AFTER READING YOUR COMPANY PROFILE I HOPE THAT I CAN IMPROVE MY PERFORMANCE AS WELL AS MY COMPANY'S ALSO. THAT'S WHY I AM LEAVING THE JOB.



8) HOW DO YOU HANDLE STRESS AND PRESSURE?

NORMALLY I TAKE A DEEP BREATH AND THEN TRY TO KEEP RELAX MY MIND. THEN I TRY TO BREAK THE PROBLEMS IN SMALL PIECES AND SOLVE ONE BY ONE, STEP BY STEP. THIS PHENOMENA HELPS ME IN SO MANY SITUATIONS. I THINK IT WORKS FINE FOR ME.



9) DISCUSS A DIFFICULT SITUATIONS AT YOUR WORK PLACE, YOU FACED:

ACTUALLY I AM A FRESHER. SO I DON'T HAVE ANY EXPERIENCE ABOUT THIS SITUATIONS.



10) DISCUSS A DIFFICULT SITUATIONS AT YOUR WORK PLACE, YOU FACED:

THEN I TRY TO BREAK THE PROBLEMS IN SMALL PIECES AND SOLVE ONE BY ONE, STEP BY STEP. THIS PHENOMENA HELPS ME IN SO MANY SITUATIONS. I THINK IT WORKS FINE FOR ME.



11) WHAT ARE THE GOALS FOR FUTURE?

WELL, I WANT TO BE A GOOD PROFESSIONAL THAT ANYBODY CAN TRUST ME. I WILL DO MY LEVEL BEST FOR THE GIVEN JOB.



12) WHY DO YOU WANT THIS JOB?

ACTUALLY AFTER READING YOUR COMPANY PROFILE I THINK IT WILL BE A BETTER OPPORTUNITY TO INCREASE MY PERFORMANCE FROM YOUR COMPANY. I NEED THIS JOB AND YOU NEED A HARD WORKING AND RESPONSIBLE PERSON TO DO SO. SO I AM HERE.



13) WHAT IS YOUR FAVOURITE PASS TIME?

WELL, I CAN SAY I AM A GOOD LISTENER OF MUSICS. I LIKE ALL TYPES OF MUSICS BUT SPECIALLY MODERN TYPES. SO WHENEVER I GET A SINGLE CHANCE, I NEVER MISS THAT.



14) WHAT IS YOUR FAVOURITE SUBJECT? WHY THIS YOUR FAVOURITE SUBJECT?

MY FAVOURITE SUBJECT IS BIOLOGY. ACTUALLY BIOLOGY DEPICTS THE STORY OF LIFE. HOW IT BEGAN AND HOW IT IS NOW AND HOW IT WILL BE IN FUTURE? ALL THE ANSWERS ARE THERE AND STILL SOME MYSTERIES ARE THERE AND THESE MYSTERIES ARE ALWAYS TAKE MY ATTENTION. I WANT TO EXPLORE THESE. THAT'S WHY I LIKE IT VERY MUCH.



15) WHO IS YOUR FAVOURITE PERSON IN YOUR FAMILY AND WHY?

I THINK MY FAVOURITE PERSON IS MY FATHER BECAUSE I CAN LEARN LOTS OF THINGS FROM HIM AS HE IS A HARD WORKER. THAT'S WHY HE IS MY INSPIRATION.



C. LISTEN AND TELL STORIES

1. HORROR STORIES

2. LOVE STORIES

3. SUSPENSE STORIES

4. ACTION STORIES

5. SATIRE STORIES



C. MAKING A PHONE CALL

1. Make a phone call to get information for admission procedure.

2. Make a phone call to get information for VISA / PASSPORT.

3. Make a phone call to get information for buying a colorful fish.



D. MAKING PLANS

1. Make a plan for Tour.

2. Make a plan for Birth Day Party.

3. Make a plan for Opening Ceremony.

4. Make a plan for Marriage Ceremony.

5. Make a plan for Durga Puja Holiday.



E. TALKING ABOUT AN ACCIDENT

1. Talking about a Railway Accident.

2. Talking about a Road Accident.

3. Talking about an Air Accident.

4. Talking about a Ship Accident.

5. Talking about a Level Crossing Accident.



F. TALKING ABOUT FAMOUS PEOPLE

1. Talking about Mr Sourav Ganguly.

2. Talking about Miss Jhulan Goswami.

3. Talking about Mrs Meri Kom.

4. Talking about Mr APJ Abul Kalam.

5. Talking about Mr. Ram Nath Kobind.



G. TALKING ABOUT HOLIDAYS

1. Holidays on Mountain Range.

2. Holidays on River side.

3. Holidays on Sea side.

4. Holidays on Desert side.

5. Holidays on an Island.



H. TALKING ABOUT TALENT AND ABILITIES

1. Talking about dance and dancers in India.

2. Talking about Art and Drawings in India.

3. Talking about Singers in India.

4. Talking about Sculpture Art in India.

5. Talking about Pottery Art in India.



J. WORD PRACTICE

Spoken English Practice Level 3





Spoken English Level 3


A. ASKING AND ANSWERING COMPLEX QUESTIONS

1. CONVERSATION WITH TICKET BOOKING CLERK.

2. CONVERSATION WITH FLOWER SELLER.

3. CONVERSATION WITH CARPENTER.

4. CONVERSATION WITH GARMENT SELLER.

5. CONVERSATION WITH MILKMAN OR MILKMAID.

6. CONVERSATION WITH MAID SERVENT OR SERVENT.

7. CONVERSATION WITH TICKET BOOKING CLERK in a bus.

8. CONVERSATION WITH YOUR NEIGHBOUR.

9. CONVERSATION WITH UNKNOWN PERSON.

10. CONVERSATION WITH UNKNOWN PERSON OVER THE MOBILE PHONE .



B. COMPLEX SIMPLE STORY TELLING

Badsahi Angti

Chander Pahar

Chhinnomostar Abhishaap

Gangtok e Gondogol

Professor-Shonkur-Ekshringa-Abhijaan



C. SEMI SIMPLE EXPERIENCE SHARE

1. READING A NOVEL/STORY BOOK.

2. LISTENING OF AN AUDIO STORY.

3. WATCHING IPL MATCH.

4. WATCHING NEWS CHANNEL.

5. HAVING YOUR FIRST SMART PHONE.



D. WORD PRACTICE

1) Word by Word Picture Dictionary



E. INVITING

1. Invite for marriage ceremony.

2. Invite for picnic party.

3. Invite for Bijay Utsav.

4. Invite for Holi Utsav.

5. Invite for Durga Puja.



F. ACCEPTING AND REFUSING AN EVENT

1. Why you have accepted the seminar event?

2. Why you have rejected the seminar event?

3. Why you have accepted the musical event?

4. Why you have rejected the road show event?

5. Why you have accepted the road play event?



G. MAKING A SUGGESTION

1. HOW TO MANAGE A DISASTER?

2. HOW TO MANAGE AN EXAMINATION STRESS?

3. HOW TO MANAGE PROPOSAL OF LOVE?

4. HOW TO MANAGE BREAKUP PROBLEMS?

5. HOW TO MANAGE MENTAL STRESS?





H. OFFERING HELP

1. OFFERING HELP FOR EXAMINATION.

2. OFFERING HELP FOR CHOOSING A DRESS.

3. OFFERING HELP FOR DECORATING HOUSE.

4. OFFERING HELP FOR ARRANGING SOME FOOD FOR THE DAY

5. OFFERING HELP FOR BUYING AND DECORATING AQUARIUM.



I. ORDERING FOODS

1. HOW TO ORDER FROM ZOMATO?

2. HOW TO ORDER FROM LOCAL RESTAURANT?

3. HOW TO ORDER FOOD INSIDE A RESTAURANT?

4. HOW TO ORDER FOOD IN PICNIC PARTY?

5. HOW TO ORDER FOOD FOR BIRTHDAY CEREMONY?



J. READING AND ANSWERING FROM A MAGAZINE

1) How It Works - Book of 101 Amazing Facts You Need To Know 2014.pdf

2) How It Works Book of Space Vol 1 5th RE - 2015 UK.pdf

3) How It Works Magazine Issue 40, 2012.pdf

Spoken English Practice Level 2




Spoken English Level 2


A. Asking and answering simple questions


1. HOW TO BUY A MOVIE TICKET?

2. HOW TO BUY A CAR?

3. HOW TO PLAY FOOTBALL?

4. HOW TO WRAP PRESENTATION?

5. HOW TO LOOSE WEIGHT FAST?

6. HOW TO CURL YOUR HAIR?

7. HOW TO CONNECT WITH WIFI?

8. HOW TO USE CALCULATOR?

9. HOW TO DOWNLOAD A PICTURE FROM INTERNET?

10. HOW TO DOWNLOAD A MOVIE FROM YOUTUBE?



B. Giving Advice

1. NEVER TELL A LIE.

2. NEVER BE LATE.

3. NEVER FIGHT WITH FRIENDS.

4. NEVER TAKE LOAN.

5. NEVER TELL ROUGH LANGUAGE.

6. NEVER BREAK ANY RELATION.

7. NEVER TRUST A GREEDY MIND.

8. NEVER CROSS YOUR LIMIT.

9. NEVER FORGET YOUR FRIENDS.

10. NEVER GIVE UP.



C. Giving Reason


1. WHY ARE YOU LATE?

2. WHY ARE YOU SO SILLY?

3. WHY ARE YOU THINKING SO MUCH?

4. WHY ARE YOU LEARNING?

5. WHY ARE YOU BEHAVING LIKE THAT?

6. WHY ARE YOU WALKING HERE?

7. WHY ARE YOU SLEEPING NOW?

8. WHY ARE YOU READING STORY BOOKS?

9. WHY ARE YOU BUYING THIS MOBILE PHONE?

10. WHY ARE YOU WATCHING THIS MOVIE?



D. SEMI SIMPLE STORY TELLING

1) Aadh-Khawa-Mora

2) Aranyak--By-Harinarayan-Chattapdhyay

3) Bhoot-Niye-Khela

4) Bhusindir-Mathey-By-Rajsekhar-Basu

5) Chiler-Chhader-Ghor

6) Hawakol-By-Syed-Mustafa-Siraj

7) Makorsar-Ras_-_Byomkesh-Adventure

8) Poro-Mandirer-Atonka-By-Hemandra-Kumar-Ray

9) Raater-Traine-Eka-And-Jonmodiner-Upohar

10) Telephone-By-Hemandra-Kumar-Ray



E. SIMPLE EXPERIENCE SHARE

AT LEAST 10 SENTENCES

1) 1ST DAY IN EXAMINATION

2) FIRST TIME IN A CLASS

3) FIRST TIME IN SEALDAH / HOWRAH

4) FIRST TIME IN ZOO.

5) FIRST TIME IN SOCIAL MEDIA.





F. TALKING ABOUT CURRENT ACTIVITY

AT LEAST 10 SENTENCES

1) IN STUDY.

2) FOR YOUR FAMILY.

3) FOR YOUR FRIEND.

4) FOR YOUR SOCIETY.

5) FOR YOUR COUNTRY.



G. TALKING ABOUT PAST EVENTS

10 SENTENCES

1) LAST BOOK YOU READ.

2) LAST RESTAURANT YOU VISITED.

3) LAST CINEMA HALL YOU VISITED.

4) LAST SCHOOL YOU ATTENDED.

5) LAST JOURNEY YOU TRAVELED.



H. TALKING ABOUT PRICE AND QUANTITY

( 5 SENTENCES )

1) VEGETABLES

2) CLOTHS

3) BOOKS

4) ELECTRONICS

5) FISH AND MEATS.



I. TALKING ABOUT WEATHER. ( 5 SENTENCES )

1) RAINY DAY OR NIGHT.

2) CLOUDY DAY OR NIGHT.

3) SUNNY DAY OR CLEAR MOON LIT NIGHT.

4) WINDY DAY OR NIGHT.

5) DEWY DAY OR NIGHT.



Sunday 2 July 2023

Python Programming Chapter 1 - Basic Questions

 

 

PYTHON PROGRAMS

 

1.1.  Write a program to show a message only.

 

print("Technologica \nComputer \nEducation \nSociety");

 

Output:

 

Technologica

Computer

Education

Society

 

 

1.2 Write a program to addition of two numbers

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

c=a+b;

print("Addition : ",c);

 

Output:

 

Enter the 1st number :  20

Enter the 2ndnumber :  30

 

Addition : 50

 

1.3 Write a program to calculation of two numbers

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

Add=a+b;

Sub=a-b;

Mult=a*b;

Div=a/b;

print("Addition : ",Add);

print("Subtraction : ",Sub);

print("Multiplication : ",Mult);

print("Division : ",Div);

Output:

 

Enter the 1st number: 20

Enter the 2nd  number: 5

 

Addition: 25

Subtraction: 15

Multiplication: 100

Division: 4

 

 

1.4 Write a program to add three numbers.

 

x=int(input("Enter 1st number : "));

y=int(input("Enter 2nd number : "));

z=int(input("Enter 3rd number : "));

c=x+y+z;

print("Addition : ",c);

 

Output:

 

Enter the 1st Number=           10

Enter the 2nd Number=          20

Enter the 3rd Number=          30

 

Addition = 60

           

 

1.5 Write a program to calculate the area and circumference of a circle.

 

radius=int(input("Enter Radius (cm) : "));

Area=(22/7)*radius*radius;

Circumference=2*(22/7)*radius;

print("Area of Circle(sqcm) = ",Area);

print("Circumference of Circle(cm) = ",Circumference);

 

Output:

 

Enter Radius (cm) : 20

Area of Circle(sqcm) =  1257.14285714

Circumference of Circle(cm) =  125.714285714

1.6 Write a program to calculate the area and perimeter of a rectangle.

 

length=int(input("Enter Length(cm) : "));

width=int(input("Enter Width(cm) : "));

Area=length*width;

Perimeter=2*(length+width);

print("Area of Rectangle(sqcm) = ",Area);

print("Perimeter of Rectangle(cm)= ",Perimeter);

 

Output:

 

Enter Length(cm) : 20

Enter Width(cm) : 10

Area of Rectangle(sqcm) =  200

Perimeter of Rectangle(cm)=  60

 

1.7 Write a program to calculate the distance covered by a wheel in Kilometer if the radius in centimeter is given through the keyboard.

 

radius=int(input("Enter Radius (cm) : "));

rotation=int(input("Enter Rotation : "));

circumference=2*(22/7)*radius;

distance=(circumference*rotation)/100000;

print("Circumference of Circle(cm) = ",circumference);

print("Distance Covered(km) = ",distance);

 

Output:

 

Enter Radius (cm) : 20

Enter Rotation : 1000

Circumference of Circle(cm) =  125.714285714

Distance Covered(km) =  1.25714285714

1.8 Write a program to calculate total cost for coloring a room if height, width, length and color rate is given through the keyboard.

 

length=int(input("Enter Length(feet) : "));

width=int(input("Enter Width(feet) : "));

height=int(input("Enter Height(feet) : "));

rs=int(input("Enter the Rate for the Coloring as Per Square feet Rs. : "))

TotalArea=(2*(length*height))+(2*(width*height))+(length*width);

TotalCost=TotalArea*rs;

print("Total Area (sqft)= ",TotalArea);

print("Total Cost(Rs.)= ",TotalCost);

 

Output:

 

Enter Length(feet) : 16

Enter Width(feet) : 12

Enter Height(feet) : 20

Enter the Rate for the Coloring as Per Square feet Rs. : 20

Total Area (sqft)=  1312

Total Cost(Rs.)=  26240

1.9 Write a program to calculate the distance in Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Inch, Feet and Gauge if it is entered as in Kilometer.

 

km=int(input("Enter the distance in Kilometer (KM) : "))

hm=km*10;

dcm=hm*10;

m=dcm*10;

dm=m*10;

cm=dm*10;

mm=cm*10;

inch=cm/2.54;

ft=inch/12;

g=ft/3;

print(" Distance in Kilometer = ",km);

print(" Distance in Hectometer  = ",hm);

print(" Distance in Decameter = ",dcm);

print(" Distance in Meter = ",m);

print(" Distance in Decimeter = ",dm);

print(" Distance in Centimeter = ",cm);

print(" Distance in Millimeter = ",mm);

print(" Distance in inch = ",inch);

print(" Distance in Feet = ",ft);

print(" Distance in Gouge = ",g);

 

Output:

Enter the distance in Kilometer (KM) : 10

 Distance in Kilometer =  10

 Distance in Hectometer  =  100

 Distance in Decameter =  1000

 Distance in Meter =  10000

 Distance in Decimeter =  100000

 Distance in Centimeter =  1000000

 Distance in Millimeter =  10000000

 Distance in inch =  393700.787402

 Distance in Feet =  32808.3989501

 Distance in Gouge =  10936.1329834

 

1.10 Write a program to calculate the retail price for a product if the name and rate and quantity are given through the keyboard.

 

pn=input(" Enter The Product Name : ")

r=int(input(" Enter The Rate Rs. : "))

qty=int(input(" Enter the Quantity (pcs) : "))

t= r*qty;

cc=t*.1;

vat=t*.05;

p=t*.35;

rp=t+cc+vat+p;

print("\n Retail Price (Rs.)= ",rp);

 

Output:

 

Enter The Product Name : lux

 Enter The Rate Rs. : 10

 Enter the Quantity (pcs) : 20

 

 Retail Price (Rs.)=  300.0

1.11 Write a program to calculate estimated population on a certain period.

 

p=int(input(" Enter The Current Population Of The Area : "))

r=float(input(" Enter The Current Population Of The Rate : "))

t=int(input(" Enter The Current Population Of The Time : "))

a=1+r/100;

b=pow(a,t);

ci= p*b;

print("The Estimated Population= ",ci);

 

 

 

 

Output:

 

Enter The Current Population Of The Area : 1000

 Enter The Current Population Of The Rate : 1.2

 Enter The Current Population Of The Time : 3

The Estimated Population=  1036.433728

1.12 Write a program to calculate the discount on a product.

 

pn=input(" Enter The Product Name : ")

p=float(input(" Enter the Price in Rs. : "))

dis=float(input(" Enter the Discount Percentage(%) : "))

rp=p-(p*dis/100);

print("The Current Price In Rs. = ",rp);

 

 

Output:

 

Enter The Product Name : lux

 Enter the Price in Rs. : 1000

 Enter the Discount Percentage(%) : 10

The Current Price In Rs. =  900.0

1.13 Write a program to calculate the simple interest and final amount  if principal, interest rate and time in years are given through the keyboard.

 

p=float(input("Enter the Principal Amount Rs. : "))

r=float(input("Enter the Rate(%) : "))

t=float(input("Enter The Time In Years : "))

si=p*r*t/100;

amt=si+p;

print("The Simple Interest = Rs.",si);

print("The Final Amount = Rs.",amt);

 

 

Output:

 

Enter the Principal Amount Rs. : 1000

Enter the Rate(%) : 10

Enter The Time In Years : 5

The Simple Interest = Rs. 500.0

The Final Amount = Rs. 1500.0

1.14 Write a program to calculate the simple interest and final amount with installment facilities  if principal, interest rate and time in years are given through the keyboard.

 

p=float(input("Enter the Principal Amount Rs. : "))

r=float(input("Enter the Rate(%) : "))

t=float(input("Enter The Time In Years : "))

si=p*r*t/100;

amt=si+p;

y=amt/t;

m=y/12;

d=y/365.25;

print("The Simple Interest = Rs.",si);

print("The Final Amount = Rs.",amt);

print("The Yearly Installment = Rs.",y);

print("The Monthly Installment = Rs.",m);

print("The Daily Installment = Rs.",d);

 

Output:

 

Enter the Principal Amount Rs. : 1000

Enter the Rate(%) : 10

Enter The Time In Years : 5

The Simple Interest = Rs. 500.0

The Final Amount = Rs. 1500.0

The Yearly Installment = Rs. 300.0

The Monthly Installment = Rs. 25.0

The Daily Installment = Rs. 0.82135523614

1.15 Write a program if input is 1 then output is 0 if input is 0 output is 1

                       

a=int(input("Enter The No : "))

b=1-a;

print("Result = ",b);

 

Output:

 

Enter The No : 1

Result =  0

1.16 Write a program to create a salary sheet

basic=int(input("Enter the basic salary: Rs."))

da=basic*0.45;

ta=basic*0.30;

hra=basic*0.20;

it=basic*0.04;

pf=basic*0.08;

gp=basic+da+ta+hra;

np=gp-it-pf;

 

print("Basic salary is: Rs.",basic);

print("D.A. is: Rs.",da);

print("T.A. is: Rs.",ta);

print("H.R..A. is: Rs.",hra);

print("I.T. is: Rs.",it);

print("P.F. is: Rs.",pf);

print("G.P. is: Rs.",gp);

print("N.P. is: Rs.",np);

 

Output

 

Enter the basic salary: Rs.1000

Basic salary is: Rs. 1000

D.A. is: Rs. 450.0

T.A. is: Rs. 300.0

H.R..A. is: Rs. 200.0

I.T. is: Rs. 40.0

P.F. is: Rs. 80.0

G.P. is: Rs. 1950.0

N.P. is: Rs. 1830.0

 

1.17 Write a program to convert Celsius to Fahrenheit

 

c=float(input("Enter The Celsius : "))

f=((9*c)/5)+32;

print("Fahrenheit : ",f);

Output:

 

Enter The Celsius : -40

Fahrenheit :  -40.0

1.18 Write a program to convert Fahrenheit to Celsius

f=float(input("Enter The Fahrenheit  : "))

c=((f-32)*5)/9;

print("Celsius: ",c);

 

Output

 

Enter The Fahrenheit  : -40

Celsius:  -40.0

1.19 Write a C program for swapping of two numbers.

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

c=a;

a=b;

b=c;

print("Value of a = ",a);

print("Value of b = ",b);

 

Output

 

Enter 1st number : 10

Enter 2nd number : 20

print("After Swap = ",a);

print("After Swap = ",b);

 

1.20 Write a C program for swapping of two numbers without using a third variable.  

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

a=a+b;

b=a-b;

a=a-b;

print("After Swap = ",a);

print("After Swap = ",b);

 

Output

 

Enter 1st number : 10

Enter 2nd number : 20

print("After Swap = ",a);

print("After Swap = ",b);

 

1.21  If a five digit number is input through the keyboard, write a program to reverse the number.

 

a=int(input("Enter The Five Digit Number : "));

b=0

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

print("The Reverse of the Number = ",b);

 

Output

 

Enter The Five Digit Number : 12345

The Reverse of the Number =  54321

1.22  If a four digit number is input through the keyboard, write a program to the sum of the first and last digit of this number.

 

a=int(input("Enter The Five Digit Number : "));

b=a%10;

a=int(a/10);

m=b;

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

n=b;

x=n+m;

print("The Sum Of The First And Last Digit = ",x);

 

 

Output

 

Enter The Five Digit Number : 12345

The Sum Of The First And Last Digit =  6

 

1.23  In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

 

totpop=80000;

totmen=(52.0/100.0)*totpop;

totlit=(48.0/100.0)*totpop;

litmen=(35.0/100.0)*totpop;

ilitmen=totmen-litmen;

totlitwomen=totlit-litmen;

totwomen=totpop-totmen;

ilitwomen=totwomen-totlitwomen;

print("Total number of men in the town is : ",totmen);

print("Total number of literate in the town is : ",totlit);

print("Total number of literate men in the town is : ",totmen);

print("Total number of women id : ",totwomen);

print("Total number of illiterate men is : ",ilitmen);

print("Total number of illiterate women is : ",ilitwomen);      

Output

 

Total number of men in the town is :  41600.0

Total number of literate in the town is :  38400.0

Total number of literate men in the town is :  41600.0

Total number of women id :  38400.0

Total number of illiterate men is :  13600.0

Total number of illiterate women is :  28000.0

1.24  A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

amount=int(input("Enter The Amount To Be Withdrawn Rs."))

nohun=amount/100;

nofifty=amount/50;

noten=amount/10;

print("Number Of Hundred Notes Required =  ",nohun);

print("Number Of Fifty Notes Required =  ",nofifty);

print("Number Of Ten Notes Required = ",noten);

 

Output

 

Enter The Amount To Be Withdrawn Rs.500

Number Of Hundred Notes Required =   5.0

Number Of Fifty Notes Required =   10.0

Number Of Ten Notes Required =  50.0

1.25  If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

 

sp=float(input("Enter The Total Selling Price Rs."))

profit=float(input("Enter The Total Selling Profit Rs."))

cp=sp-profit;

cp=cp/15;

print("Cost Price Per Item Is Rs. =  ",cp);

Output

 

Enter The Total Selling Price Rs.500

Enter The Total Selling Profit Rs.200

Cost Price Per Item Is Rs. =   20.0

1.26 if a five –digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if that number is input is 12391 the output should be displayed as 23402.

 

num=int(input("Enter A 5 Digit Number (Less Than 32767) : "));

newnum=0;

a=int(num/10000+1);

n=int(num%10000);

newnum=int(newnum+a*10000);

 

a=int(n/1000+1);

n=int(n%1000);

newnum=int(newnum+a*1000);

 

a=int(n/100+1);

n=int(n%100);

newnum=int(newnum+a*100);

 

a=int(n/10+1);

n=int(n%10);

newnum=int(newnum+a*10);

 

a=int(n+1);

newnum=int(newnum+a);

 

print("The New Numbers Are : = ",newnum);

 

 Output

 

Enter A 5 Digit Number (Less Than 32767) : 12391

The New Numbers Are : =  23502

 

 

JAVA PROGRAMMING - OOPS CHAPTER 1

Object-Oriented Programming Chapter 1: Basics by Souradeep Roy Using IntelliJ IDEA Community version:- _____________________________________...