Saturday, June 9, 2018

Percentage Maths magic


Percentage tricks

Percentages can be done mentally both accurately and rapidly using this cool math trick.
You can solve percentage problems mentally.Become a genius !

You have to learn below tables in order to master percentage and it problems.


Percentage Basics
(1/2) 50% (1/20) 5%
(1/3) 33(1/3)% (1/25) 4%
(1/4) 25% (1/50) 2%
(1/5) 20% (3/8) 37(1/2)%
(1/6) 16(2/3)% (5/8) 62(1/2)%
(1/7) 14(2/7)% (4/7) 57(1/7)%
(1/8) 12(1/2)% (5/7) 71(3/7)%
(1/9) 11(1/9)% 1 100%
(1/10) 10%
(1/11) 9(1/11)%
(1/12) 8(1/3)%
(1/13) 7(9/13)%
(1/14) 7(1/7)%
(1/15) 6(2/3)%
(1/16) 6(1/4)%

Question 1: Convert percentage into fraction
i) 157(1/7)%

Solution:
157(1∕7)
=100%+57(1/7)%
=1+4/7
=11/7 Ans

Question 2: If 44(4/9) % of a number is added to itself then result becomes 650.Find the original number.
Solution:
44(4/9)%
=4*11(4/9) %
=4*(1/9)
=4/9 %

In percentage,denominator always denotes original number and numerator is result %.

so as per question 4+9=13
13 units =650
1 units=50
so original number is =9*40=450 ans.

Question 3: In an election,10 % of the voters did not cast their votes,11(1/9)% of the votes out of voting done were considered invalid.The winner got 75% of the valid votes and won by 2000 votes.Find out the total number of voters in the voting list.

[ Try to solve this within 30 seconds ]

Solution:

Let total number of voter be 100

100
| -10 ( 10% voter did not cast)
90
| -10 [119(1/9)% =1/9 and 1+9=10 ]
80

    80
  /      \
75% 25%

Difference of 75% and 25% is 50%.

50% of 80=2000 (given)
40 ---->2000
1------> 50

Then 100 ---> 50 * 100=5000 Answer


Friday, June 8, 2018

AngularJS application with Oracle database Tutorial


AngularJS application with Oracle database Tutorial

I am going to show you how to connect angularJS with Oracle database sing java-servlet and read data in JSON format.


CREATE TABLE employee
( empno number(10) NOT NULL,
  ename varchar2(50) NOT NULL,
  job varchar2(50)
);

Java model class (Employee.java)
package com.devyan;

public class Employee {
       int empno;
       String ename;
       String job;
      
    public Employee(int empno, String ename, String job) {
        this.empno = empno;
        this.ename = ename;
        this.job = job;
    }
       public int getEmpno() {
             return empno;
       }
       public void setEmpno(int empno) {
             this.empno = empno;
       }
       public String getEname() {
             return ename;
       }
       public void setEname(String ename) {
             this.ename = ename;
       }
       public String getJob() {
             return job;
       }
       public void setJob(String job) {
             this.job = job;
       }     

}


Database Connection Class ( Mydatabase.java)
package com.devyan;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Mydatabase {
 static Connection con;
 
  public static Connection getCon(){
   
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","SYSTEM","oracle");
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
    return con;
  }
 
}

AngularJsServlet.java

It will used database connectivity with Oracle and convert data in JSON format


package com.devyan;

import java.io.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
import javax.servlet.http.*;
import org.json.JSONArray;

import com.google.gson.Gson;

public class AngularJsServlet extends HttpServlet {
       public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
             response.setContentType("application/json");
             try {
                    /* TODO output your page here. You may use following sample code. */
                    // Mydb db = new Mydb();
                    PrintWriter out = response.getWriter();
                    Connection con = Mydatabase.getCon();
                    ArrayList<Employee> al = new ArrayList<Employee>();

                    try {
                           Statement stmt = con.createStatement();
                           ResultSet rs = stmt.executeQuery("select * from HIBERNATE.Employee");

                           while (rs.next()) {
                                 Employee userobj = new Employee(rs.getInt("empno"), rs.getString("ename"), rs.getString("job"));
                                 al.add(userobj);
                           }
                           JSONArray arrayObj = new JSONArray(al);
                           String json = new Gson().toJson(arrayObj);
                           response.getWriter().write(json);
                    } catch (SQLException ex) {
                           System.out.println();
                           Logger.getLogger(AngularJsServlet.class.getName()).log(Level.SEVERE, null, ex);
                    }

             } catch (Exception e) {
                    e.printStackTrace();
             }

       }
}


Angular JS application (index.html)
    <html>
        <head>
            <title>TODO supply a title</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <style>
                    table, th , td  {
                      border: 1px solid grey;
                      border-collapse: collapse;
                      padding: 5px;}
                    table tr:nth-child(odd) {
                                   background-color: #f1f1f1;
                           }
                                 table tr:nth-child(even) {
                                   background-color: #ffffff;
                                 }
                    </style>
        </head>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
      <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope, $http) {
      // email = $scope.email;
      // psw = $scope.psw;
      $http({
        method: "GET",
        url: "http://localhost:8085/AngularJSDemo/devil"
       
      }).then(function mySuccess(response) {
          // a string, or an object, carrying the response from the server.
          $scope.myRes = response.data.myArrayList;
          console.log('Successful' +response);
          $scope.statuscode = response.status;
        }, function myError(response) {
          $scope.myRes = response.myArrayList;
          console.log('Failure' +response);
      });
    });
    </script>
    </head>
    <body>
    <div ng-app="myApp">
            <div ng-controller="myCtrl">
        
              <!-- {{statuscode}}-->
                <div ng-repeat="x in myRes">
                <!--    <h3>{{x.map.empno + " : " +x.map.ename+ " : "+x.map.job}}</h3>-->
                 
                  
                </div>
                <h3>AngularJS application with Oracle database</h3>
                <table>
                <tr><td>Employee No</td><td>Employee Name</td><td>Job</td></tr>
                                 <tr ng-repeat="x in myRes">
                                       
                                     <td>{{ x.map.empno }}</td>
                                     <td>{{ x.map.ename | uppercase }}</td>
                                     <td>{{ x.map.job }}</td>
                                 </tr>
                           </table>
                
              </div>
    </div>
    </body>
    </html>

Hibernate Tutorial