Menu

Tuesday 30 May 2017

Hi this page is under construction for the next lecture in STP 113: Introduction to Digital Electronics for Science.....

Tuesday 9 May 2017


Analogue Signal:

Our world is analogue, most things we relate with has infinite values. Working with electronics with deal with both digital and analogue signals. An electronics system that deals with analogue signals are referred to as analogue system.

Come to think of it what is (are) signals?
Signals are time varying quantities. That is, there values changes as time changes.
An example of such in electronics is voltage (or Current), when we talk of signal just think voltage.
Signals are passed between devices in order to send and receive information, which might be video, audio, or some sort of encoded data.

While these signals may be limited to a range of maximum and minimum values, there are still an infinite number of possible values within that range. 

Example of analogue signal are Audio and Video signal.
Analogue devices










Digital Signals
Digital signals must have a finite set of possible values. The number of values in the set can be anywhere between two and a-very-large-number-that’s-not-infinity. Most commonly digital signals will be one of two values – like either 0V or 5V. Timing graphs of these signals look like square waves.

Digital device









Analogue and Digital Circuits

Analogue Electronics

Most of the fundamental electronic components – resistorscapacitors, inductors, diodes, transistors, and operational amplifiers – are all inherently analogue. Circuits built with a combination of solely these components are usually analogue.  Analogue circuits are much more difficult to design than those which accomplish the same task digitally.
Analogue Signal







Digital Electronics

Digital circuits operate using digital, discrete signals. These circuits are usually made of a combination of transistors and logic-gates and, at higher levels, microcontrollers or other computing chips. Most processors, whether they’re big beefy processors in your computer, or tiny little microcontrollers, operate in the digital realm.


Digital circuits usually use a binary scheme for digital signalling. These systems assign two different voltages as two different logic-level – a high voltage (usually 5V, 3.3V, or 1.8V) represents one value and a low voltage (usually 0V) represents the other.
Although digital circuits are generally easier to design, they do tend to be a bit more expensive than an equally tasked analog circuit.
Digital Signal







Digital information has certain properties that distinguish it from analogue communication methods. These include
·    Synchronisation – digital communication uses specific synchronisation sequences for determining synchronisation.
·  Language – digital communications requires a language which should be possessed by both sender and receiver and should specify meaning of symbol sequences.
·  Errors – disturbances in analogue communication causes errors in actual intended communication but disturbances in digital communication does not cause errors enabling error free communication. Errors should be able to substitute, insert or delete symbols to be expressed.
· Copying – analogue communication copies are quality wise not as good as their originals while due to error free digital communication, copies can be made indefinitely.
·  Granularity – for a continuously variable analogue value to be represented in digital form there occur quantization error which is difference in actual analogue value and digital representation and this property of digital communication is known as granularity.

Further reading:
1. Digital Electronics for Science 

Introduction to Electronic Logic for Science
1. Analogue Versus Digital Electronics
2. Number Systems
3. Binary Codes
4. Digital Arithmetic
5. Boolean Algebra
6. Logic gates.
7. Karnaugh Map Simplification Method




Collaborative Learning


Friday 16 September 2016

General Instrumentation Tutorials

1. What is measurement?  Why do we need instruments to measure? Enumerate    and define factors that will influence your choice of measuring instruments.
2. Briefly explain the importance of measurement in the following;
            i.    Scientific research
ii.   Industrial production
iii. Automatic control system


3. A beaker weighs 47.21g and a graduate cylinder is used to deliver 22.5ml water to the beaker at 270C. Afterwards, the mass of the beaker and water sample together have a mass of 70.15. What volume is the true volume of water delivered by the graduated cylinder? (Given that, the density of water at 270C is 0.99654g/ml), also determine the percentage error of the measurement by the measuring cylinder.
4. Complete the table below:
Quantity
Dimension
SI unit
Equivalent Unit
Speed or velocity
LT-1
ms-1
None
Frequency


Hertz
Acceleration



Force



Work or energy



Power



5. Explain with a block diagram the basic components of  electrical measuring system.
6. Describe forces/device required in the operation of an analogue indicating instrument.
7. With a suitable diagram, explain the principle of operation of an attraction and repulsion types of moving-iron instrument.
8. Describe how a moving-coil instrument can be improved to indicate the amplitude   of an alternating signal.
9. Define the following in terms of their operation/use;
    (i)  Ammeter   (ii)  Voltmeter   (iii) Shunt resistance  (iv)  Multiplier resistance                                
    (v)  Multirange meter.
10. Design a multirange ammeter by using direct method to measure within the following ranges. 10mA, 100mA, 1A and 10A. With a Permanent Magnet Moving Coil (PMMC) meter of internal resistance of 100W and full scale current of 1mA.
11. What do you understand by ‘Null method of measurement’. Describe with the   aid of an appropriate diagram, the following Null methods of measurement;
(a)  Wheatstone bridge   (b)  D.C potentiometer
12. A d.c potentiometer is balanced when the slider is at 380mm using a standard   cell of 1.242Volts. Determine the electromotive force (e.m.f) of a dry cell if balance is obtained with a length of 716mm.
13. In a Wheatstone bridge ABCD, a galvanometer is connected between A and C, and a battery between B and D, a resistor of unknown value is connected between A and B. When the bridge is balanced, the resistance between B and C is 470Ω, that between C and D is 18Ω and that between D and A is 300 Ω. Calculate the value of the unknown resistance.
14. The core of an analogue oscilloscope is a special type of vacuum tube known as a cathode ray tube. With a suitable diagram explain how a CRT functions. What goes on inside    the tube to produce waveform displays on the screen?
15. In general electronic use, when measuring AC voltage signals, what do the two axis (horizontal and Vertical) of the oscilloscope screen represents?
16. For the sinusoidal waveform shown figure 16, below, the volt/cm switch is on 50volt/div and time/cm switch is on 5ms/div. Determine;
(a).  The frequency    (b)  The peak-to-peak voltage    (c).  The  root mean square (r.m.s) voltage value of the signal. 
Figure 16
17. What do you understand by the phrase; “Temperature of a body”. Convert the following temperature in Celsius scale into Fahrenheit scale;  (i)  40.50C  (ii)  - 200C.
18. Describe briefly the principle of operation of the following temperature sensing instruments (thermometer), (i)  Liquid-in-glass thermometer  (ii)  Bimetallic strip thermometer  (iii)  Pressure thermometer.
19. In a certain thermocouple, 19.65mV of voltage is observed at its output when the reference junction T1 is maintained at 00C and T2 at 67.30C.
Using the same thermocouple, a potential difference output of 5.87mV was observed, when junction T1 was dipped in a melting ice and junction T2 was inserted in a solution of unknown temperature. Determine the temperature of the solution.
20.  Assume a newly produced mercury-in-glass thermometer, to calibrate the thermometer, measurement of increase in mercury thread length in the thermometer against temperature values was taken and tabulated as shown in table 17 bellow;
Table 17:
Change in temperature, Δθ(0C)
Change in Mercury length, ΔL(mm)
12.0
2.16
22.1
4.40
42.8
7.70
51.4
9.25
60.5
16.94
i.                    Plot the graph of the ΔL in the Y-axis against the ΔL against the Δθ0C on the x-axis, hence; determine the sensitivity of the thermometer with the graph.
ii.                  On another graph sheet, calibrate the thermometer using a suitable scale to measure temperature range 00C – 1000C.
21. (a)  Science/Technology depends on data and interrelation of different data types; measurement and quantification of various physical and chemical parameters “begat” data; measurement without proper measuring instruments results in a conjecture unusable for scientific and technological inference. Explain this statement with suitable illustrations.
22. Control system without measurement is “tantamount” to a car without the “steering”. Explain.
23. Explain with a block diagram the basic components of  electrical measuring system.
24. With a suitable diagram, explain the principle of operation of an atraction and repulsion types of moving-iron instrument.
25. Determine the shunt required to employ a moving-coil instrument of full scale deflection current of 1mA and internal resistance of 25Ω, as an ammeter to measure current range of 0-100mA.
26. Describe briefly the principle of operation of the following temperature sensing instruments (thermometer), (i)  Liquid-in-glass thermometer  (ii)  Bimetallic strip thermometer  (iii)  Pressure thermometer.
27. What is a Cathode Ray Oscilloscope? The core of an analogue oscilloscope is a special type of vacuum tube known as a cathode ray tube. With a suitable diagram explain how a CRT functions. What goes on inside the tube to produce waveform displays on the screen?
28. In general electronic use, when measuring AC voltage signals, what do the two axis (horizontal and Vertical) of the oscilloscope screen represents.
29.  A sinusoidal waveform of two voltage signals with the same frequency shown in figure 29, below, the volt/div switch is on 2.5V/div and time/div switch is on 5ms/div. Determine; determine the phase difference between the two signals in degrees. 
 Figure 29


Friday 20 November 2015

Matrix Class Demo (Java Concept)

 */
package matrix;

/**
 *
 * Adeniran Adetunji
 */
public class Matrix {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
       
        MatrixMath calMatrix = new MatrixMath();
       
               
        double[][]matrix_A = calMatrix.createMatrix();
        double[][]matrix_B = calMatrix.createMatrix();
       
        calMatrix.enterMatrixElement(matrix_A);
        calMatrix.enterMatrixElement(matrix_B);
       
        double [][]matrix_C= calMatrix.addMatrix(matrix_A, matrix_B);
       
        calMatrix.displayMatrix(matrix_A);
        System.out.println(" ");
        calMatrix.displayMatrix(matrix_B);
        System.out.println(" ");
        calMatrix.displayMatrix(matrix_C);
       
}


Output
run:
Enter Number of row(s)2
Enter Number of column(s)2
Enter Number of row(s)2
Enter Number of column(s)2
Enter element in row: 1 column :1==>3
Enter element in row: 1 column :2==>14
Enter element in row: 2 column :1==>2
Enter element in row: 2 column :2==>3
Enter element in row: 1 column :1==>56
Enter element in row: 1 column :2==>2
Enter element in row: 2 column :1==>3
Enter element in row: 2 column :2==>45
3.0       14.0    
2.0       3.0      

56.0      2.0      
3.0       45.0    

59.0      16.0    
5.0       48.0    

BUILD SUCCESSFUL (total time: 30 seconds)

MatrixMaths Class (Java Concept)

package matrix;

/**
 *
 * Adeniran Adetunji
 */
public class MatrixMath extends MatrixC {
   
   
   double [][] addMatrix(double[][]augendMatrix, double[][]addendMatrix)
   {
       int x = augendMatrix.length;
       int y = augendMatrix[0].length;
       double [][]totalMatrix = new double[x][y];
     
     
       if((augendMatrix.length==addendMatrix.length)
               &&(augendMatrix[0].length==addendMatrix[0].length))
       {
           for(int i=0; i<augendMatrix.length; i++)
           {
               for (int k=0; k<augendMatrix[i].length; k++)
               {
                   totalMatrix[i][k]=getElement(augendMatrix, i, k )+
                              getElement(addendMatrix, i, k);
               }
           }
         
       }
       else
       {
           System.out.println("Matrix a not of the same dimension");
           System.out.println("Matrix Cannot be added");
       }
     
       return totalMatrix;
   }
   
}

Matrix Class (Java Concept)

package matrix;
import java.util.Scanner;

/**
    *
 * Adeniran Adetunji
 */
public class MatrixC {
   
    double [][]matrix;
   
    //Create Matrix of Row = x and Column=y
   
    MatrixC ()
    {
        matrix = new double[0][0];
    }
     double [][] createMatrix()
    {
        int x;
        int y;
        Scanner setMatrix = new Scanner (System.in);
        System.out.print("Enter Number of row(s)");
        x = setMatrix.nextInt();
        System.out.print("Enter Number of column(s)");
         y = setMatrix.nextInt();
        matrix = new double[x][y];
        initializeMatrix(matrix);
       
        return matrix;
       
      }
   
     double[][]createMatrix(double [][]matrix_1)
     {
         matrix = matrix_1;
         return matrix;
     }
   
     double[][] createColumnVector()
     {
        final int x= 1;
        int y;
      Scanner columnNo = new Scanner (System.in);
      System.out.print("Enter Number of Column(s): ");
      y = columnNo.nextInt();
     
      matrix=new double [x][y];
      initializeMatrix(matrix);
     
      return matrix;
     }
   
     double[][]createColumnVector(double[]cMatrix)
     {
       
         int y = cMatrix.length;
       
         matrix = new double [y][1];
       
         for (int i=0; i<matrix.length; i++)
         {
             for (int k=0; k<matrix[i].length; k++)
             {
                 matrix[i][k]=cMatrix[i];
               
             }
         }
       
         return matrix;
     }
   
     double [][] createRowVector()
     {
         final int y= 1;
        int x;
      Scanner columnNo = new Scanner (System.in);
      System.out.print("Enter Number of Row(s): ");
      x = columnNo.nextInt();
     
      matrix=new double [x][y];
      initializeMatrix(matrix);
     
      return matrix;
     }
   
     double [][]createRowVector(double[]rMatrix)
     {
        int y = rMatrix.length;
       
         matrix = new double [1][y];
       
         for (int i=0; i<matrix.length; i++)
         {
             for (int k=0; k<matrix[i].length; k++)
             {
                 matrix[i][k]=rMatrix[k];
               
             }
         }
       
         return matrix;
     }
   
     void initializeMatrix(double [][]matrix)
    {
        for (int i=0; i<matrix.length; i++)
        {
            for(int k=0; k<matrix[i].length; k++)
            {
                matrix[i][k]=0.0;
            }
        }
    }
     void displayMatrix(double[][]matrix1)
     {
         for(int i=0; i<matrix1.length; i++)
         {
             for(int k=0; k<matrix1[i].length; k++)
             {
                 System.out.printf("%-10.1f", matrix1[i][k]);
             }
             System.out.println("");
         }
       
     }
   
   
    //Initialize matrix of row i and column K with each element initialy equal to zero
   
   
    void enterMatrixElement(double[][]matrix)
    {
        for(int i=0; i<matrix.length; i++)
        {
            for(int k = 0; k<matrix[i].length; k++)
            {
                Scanner input_matrix_element = new Scanner (System.in);
                System.out.print("Enter element in "+ "row:"+" "+ (i+1)+" "+ "column :"+(k+1));
                System.out.print("==>");
                matrix[i][k]= input_matrix_element.nextInt();
            }
        }
    }
   
    boolean equalMatrix(double [][]matrix_1, double[][]matrix_2)
    {
       boolean test = false;
       
        if((matrix_1.length==matrix_2.length)
               &&(matrix_1[0].length==matrix_2[0].length))
        {
            for (int i = 0; i<matrix_1.length; i++)
            {
                for (int k = 0; k<matrix_1[i].length; i++)
                {
                    if(matrix_1[i][k]==matrix_2[i][k])
                    {
                        test = true;
                    }
                }
            }
        }
        else          
        {
            test =  false;
        }
        return test;
    }
   
   
    void clearMatrix (double[][]matrix)
    {
        initializeMatrix(matrix);
    }
   
    double [][] cloneMatrix(double[][]matrix)
    {
       return matrix;
    }
   
    double getElement(double[][]matrix, int x, int y)
    {
       double element = matrix[x][y];
     
       return element;
    }
   
    void  setElement( double[][]matrix, int x, int y, double z)
    {
       matrix[x][y]=z;
    }
   
    double [][]getColumn(double[][]matrix, int col_index)
    {
        int num = matrix.length;
       
        double [][] matrixR = new double[num][1];
       
        for (int i=0; i<matrix.length; i++)
        {
            matrixR[i][0]= matrix[i][col_index];
        }
       
        return matrixR;
    }
   
    boolean IsVector (double[][]matrix_c)
    {
        boolean result = false;
       
        if((matrix_c.length==1)||(matrix_c[0].length==1))
        {
            result = true;
        }
       
        return result;
       
    }
   
    boolean checkVectorEqualLength(double [][]matrix_A, double[][] matrix_B)
    {
   
        boolean result = false;
       
            if((matrix_A.length==matrix_B.length)&&(matrix_A[0].length==matrix_B[0].length))
            {
                result=true;
            }
            else if ((matrix_A.length==matrix_B[0].length)&&(matrix_A[0].length==matrix_B.length))
            {
                result = true;
            }
            else
            {
                result=false;
            }
         
         
       
        return result;
    }
   
    boolean equalDimension(double[][]matrix_A, double[][]matrix_B)
    {
        boolean check = false;
        if((matrix_A.length==matrix_B.length)&&(matrix_A[0].length==matrix_B[0].length))
        {
            check = true;
        }
       
        return check;
    }
   
    double dotProduct(double[][]matrix_A, double[][]matrix_B)
    {
        boolean check;
        boolean check2;
        double result=0;
       
        check = (IsVector(matrix_A)&&IsVector(matrix_B));
       check2 = ((check)&&(checkVectorEqualLength(matrix_A, matrix_B)));
        if(check2)
        {
             if((matrix_A.length==matrix_B.length)&&(matrix_A[0].length==matrix_B[0].length))
             {
                 for(int i=0; i<matrix_A.length; i++)
                 {
                     for(int k=0; k<matrix_A[i].length; k++)
                     {
                         result= result+(matrix_A[i][k]*matrix_B[i][k]);
                     }
                 }
             }
             if((matrix_A.length==matrix_B[0].length)&&(matrix_A[0].length==matrix_B.length))
             {
                 if(matrix_A.length==1)
                 {
                     for (int i=0; i<matrix_A.length; i++)
                     {
                         for (int k=0; k<matrix_B.length; k++)
                         {
                             result = result+(matrix_A[i][k]*matrix_B[k][i]);
                         }
                     }
                 }
                 if(matrix_B.length==1)
                     for(int i=0; i<matrix_B.length; i++)
                     {
                         for(int k=0; k<matrix_A.length; k++)
                         {
                             result = result+(matrix_B[i][k]*matrix_A[k][i]);
                         }
                     }
             }
               
        }
        else
        {
            System.out.println("Matrices are not compartible for dot product");
           
         
        }
       
        return result;
    }
   
   
    double [][] addMatrix (double[][] matrix_A, double [][]matrix_B)
    {
        double [][]result;
       
        result = new double[matrix_A.length][matrix_A[0].length];
        initializeMatrix(result);
           
        if(equalDimension(matrix_A, matrix_B))
        {
            result = new double[matrix_A.length][matrix_A[0].length];
            initializeMatrix(result);
            for(int i =0; i<matrix_A.length; i++)
            {
                for(int k=0; k<matrix_A[i].length; k++)
                {
                    result[i][k]=matrix_A[i][k]+matrix_B[i][k];
                }
               
            }
        }
        else
        {
            System.out.println("The matrices do not have the same dimesion");
        }
       
        return result;
       
    }
   

 
}

Wednesday 14 October 2015

Java Concept (Matrix Operation using java array 1)

package matrix;
import java.util.Scanner;

/**
    *
 * @author Adeniran Adetunji
 */
public class MatrixC {
 
    double [][]matrix;
 
    //Create Matrix of Row = x and Column=y
     double [][] createMatrix()
    {
        int x=0;
        int y=0;
        Scanner setMatrix = new Scanner (System.in);
        System.out.print("Enter Number of row(s)");
        x = setMatrix.nextInt();
        System.out.print("Enter Number of column(s)");
         y = setMatrix.nextInt();
        matrix = new double[x][y];
        initializeMatrix(matrix);
     
        return matrix;
     
      }
 
//create Column vector i.e matrix of 1 row
     double[][] createColumnVector()
     {
        final int x= 1;
        int y;
      Scanner columnNo = new Scanner (System.in);
      System.out.print("Enter Number of Column(s): ");
      y = columnNo.nextInt();
   
      matrix=new double [x][y];
      initializeMatrix(matrix);
   
      return matrix;
     }
   
//create Row vector i.e. matrix of 1 column
     double [][] createRowVector()
     {
         final int y= 1;
        int x;
      Scanner columnNo = new Scanner (System.in);
      System.out.print("Enter Number of Row(s): ");
      x = columnNo.nextInt();
   
      matrix=new double [x][y];
      initializeMatrix(matrix);
   
      return matrix;
     }
   
     void displayMatrix(double[][]matrix1)
     {
         for(int i=0; i<matrix1.length; i++)
         {
             for(int k=0; k<matrix1[i].length; k++)
             {
                 System.out.printf("%-10.1f", matrix1[i][k]);
             }
             System.out.println("");
         }
       
     }
   
   
    //Initialize matrix of row i and column K with each element initialy equal to zero

    void initializeMatrix(double [][]matrix)
    {
        for (int i=0; i<matrix.length; i++)
        {
            for(int k=0; k<matrix[i].length; k++)
            {
                matrix[i][k]=0.0;
            }
        }
    }
 
//Update matrix or enter matrix elements

    void enterMatrixElement(double[][]matrix)
    {
        for(int i=0; i<matrix.length; i++)
        {
            for(int k = 0; k<matrix[i].length; k++)
            {
                Scanner input_matrix_element = new Scanner (System.in);
                System.out.print("Enter element in "+ "row:"+" "+ (i+1)+" "+ "column :"+(k+1));
                System.out.print("==>");
                matrix[i][k]= input_matrix_element.nextInt();
            }
        }
    }

=======================================================================
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package matrix;

/**
 *
 * @author DELL
 */
public class Matrix {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        MatrixC myMatrix = new MatrixC();

        System.out.println("Creating and Intializing Matrix");
        System.out.println("================================");
       double[][] matrixA = myMatrix.createMatrix();
       
       System.out.println("Entering elements in matrix indexes");
       System.out.println("===================================");
        myMatrix.enterMatrixElement(matrixA);
      
       System.out.println("Displaying Matrix Elements");
       System.out.println("==========================");
      
        myMatrix.displayMatrix(matrixA);
       
        System.out.println("Creating and initializing Column Vector");
        System.out.println("=======================================");
                           
       double[][]matrixB=myMatrix.createColumnVector();
       
       System.out.println("Entering elements in the Column Vector");
       System.out.println("======================================");
                           
       myMatrix.enterMatrixElement(matrixB);
       
       System.out.println("Displaying the elements in the column vector");
       System.out.println("============================================");
        myMatrix.displayMatrix(matrixB);
         
        
       System.out.println("Creating and Initializing row vector");
       System.out.println("======================================");
       double[][]matrixC =myMatrix.createRowVector();
        
        System.out.println("");
        
       System.out.println("Entering elements in the row Vector");
       System.out.println("===================================");
        myMatrix.enterMatrixElement(matrixC);
        
         System.out.println("Displaying elements of the Column Vector");
         System.out.println("=========================================");
        myMatrix.displayMatrix(matrixC);
        
        
    }
        
        
        
    }

OUTUPUT
run:

Creating and Initializing Matrix
================================
Enter Number of row(s)3
Enter Number of column(s)4

Entering elements in matrix indexes
===================================
Enter element in row: 1 column :1==>3
Enter element in row: 1 column :2==>12
Enter element in row: 1 column :3==>4
Enter element in row: 1 column :4==>12
Enter element in row: 2 column :1==>4
Enter element in row: 2 column :2==>5
Enter element in row: 2 column :3==>12
Enter element in row: 2 column :4==>2
Enter element in row: 3 column :1==>3
Enter element in row: 3 column :2==>4
Enter element in row: 3 column :3==>2
Enter element in row: 3 column :4==>2
Displaying Matrix Elements
==========================
3.0       12.0      4.0       12.0      
4.0       5.0       12.0      2.0       
3.0       4.0       2.0       2.0       

Creating and initializing Column Vector
=======================================
Enter Number of Column(s): 3
Entering elements in the Column Vector
======================================
Enter element in row: 1 column :1==>3
Enter element in row: 1 column :2==>3
Enter element in row: 1 column :3==>3

Displaying the elements in the column vector
============================================
3.0       3.0       3.0       

Creating and Initializing row vector
======================================
Enter Number of Row(s): 3

Entering elements in the row Vector
===================================
Enter element in row: 1 column :1==>33
Enter element in row: 2 column :1==>3
Enter element in row: 3 column :1==>33

Displaying elements of the Column Vector
=========================================
33.0      
3.0       
33.0      
BUILD SUCCESSFUL (total time: 41 seconds)

Sunday 4 October 2015

Java Concept (Queue Data structure)

package queuedatastructure;

/**
 *
 * @author Adeniran Adetunji
 */
public class ArrayStaticQueue {
    //Declaring the instance variables of a queue. Initalizing head and tail to zero
    int headRef=0;
    int tailRef=0;
    char [] arrayQueue;
     
    //Method to create queue array
   void initializeQueue(int Size)
    {
     
       arrayQueue = new char[Size];
     
       for( int i=0; i<arrayQueue.length; i++)
       {
           arrayQueue[i] = '\u0000';
       }
    }
 
   //This method checks if queue is empty
  boolean isEmpty()
  {
      boolean test= true;
      for (int i=0; i<arrayQueue.length; i++)
      {
          if(arrayQueue[i]!='\u0000')
           
              test=false;
      }
   
      return test;
  }

  //This method test if queue is full
  boolean isFull()
  {
      boolean test = true;
   
      for (int i=0; i<arrayQueue.length; i++)
      {
          if(arrayQueue[i]=='\u0000')
           
              test = false;
      }
   
      return test;
  }

  //This method adds item to queue
 void addItem( char c)
 {
     // The test determines if the queue is full
     boolean test=isFull();
     // If the queue is full
     if(test)
     {
     //The system should print QUEUE IS FULL
         System.out.println("Queue is Full");
     }
     else
     {
        arrayQueue[tailRef]=c;
     }
   
     setTail();
 }
   
//This method set new tail location after adding item to queue
  void setTail()
  {
//Test if queue is full
 boolean  test=isFull();
     //if is full
     if(test)
     {
         //Then tail index becomes -1
         tailRef=-1;
     }
     //If queue is not full
     else
     {
         //Get the current tail index in nTail variable
     int nTail = tailRef;
   
     //Check for free space to the right-side of the tail
         for(int i=tailRef; tailRef<arrayQueue.length; i++)
         {
             //if found...
             if(arrayQueue[i]=='\u0000')
             {
                 //set new tail at the index of the free space
                 tailRef=i;
                 //break out of the loop
                 break;
             }
         }
         //Test if tailRef is not updated by the loop above
         //If test is true: that is loop is not updated
      if (nTail==tailRef)
      {
          //start searching for the free space from the begining of the
          //queue i.e. from index 0
          for (int k=0; k<arrayQueue.length; k++)
          {
             //Get first free space
             if(arrayQueue[k]=='\u0000')
             {
                 //Update tailRef at the index of the first free space gotten
                 tailRef=k;
                 //break out of the loop
                 break;
             }
          }
      }
     }
  }
  //This method removes item from queue
 void removeItem()
 {
     boolean test = isEmpty();
   
     if(test)
     {
         System.out.print("Queue is empty");
     }
     else
     {
       
         arrayQueue[headRef]='\u0000';
       
         if(tailRef==-1)
         {
             tailRef=headRef;
         }
       
     }
   
     setHead();  
 }

 //This method set new head location after removing item from queue
 void setHead()
 {
    boolean test = isEmpty();
         if(test)
         {
           
         headRef=0;
       
         }
         else
         {
             if(headRef+1<arrayQueue.length)
             {
               
              headRef=headRef+1;
             }
             else
             {
                 for(int i=0; i<arrayQueue.length; i++)
                 {
                     if(arrayQueue[i]!='\u0000')
                       
                         headRef=i;
                     break;
                 }
             }
         }
 }
   
 }

....Class Instance...
package queuedatastructure;

/**
 *
 * @author Adeniran Adetunji
 */
public class QueueDataStructure {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     
        ArrayStaticQueue myQueue = new ArrayStaticQueue();
     
        myQueue.initializeQueue(5); //Initializes queue that can hold five characters
     
 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }    

/*2*/    boolean check = myQueue.isEmpty();

            System.out.println(check);

/*3*/ System.out.println("Head =" + myQueue.headRef);
         System.out.println("Tail =" + myQueue.tailRef);

/*4*/  myQueue.addItem('A');
/*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*2*/ check = myQueue.isEmpty();

       System.out.println(check);
     
 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);
  /*5*/ myQueue.addItem('B');
       myQueue.addItem('C');
       myQueue.addItem('D');
       myQueue.addItem('E');

 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*2*/ check = myQueue.isEmpty();
     
       System.out.println(check);
     
 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);

              check=myQueue.isFull();
 /*6*/     System.out.println(check);

 /*7*/   myQueue.addItem('F');
/*8*/  myQueue.removeItem();
 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);
     
/*9*/  myQueue.removeItem();
 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);

 /*10*/ myQueue.removeItem();
 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);

 /*11*/ myQueue.addItem('F');
 /*12*/ myQueue.removeItem();
 /*1.*/ for (int i = 0; i<myQueue.arrayQueue.length; i++)
       {
           System.out.println(myQueue.arrayQueue[i]);
       }  

 /*3*/ System.out.println("Head =" + myQueue.headRef);
       System.out.println("Tail =" + myQueue.tailRef);



     
     
}
}


Output
run:
1.





2. true      
3. Head =0
   Tail =0

4.A




1. false
2. Head =0
3. Tail =1
//After adding item at /*5*/
1.A
   B
   C
   D
   E
2.false
3.Head =0
4.Tail =-1
6.True
7.Queue is Full
//After /*8*/
1.
   B
   C
   D
   E
3.Head =1
4.Tail =0
//After  /*9*/

C
D
E
Head =2
Tail =0
//After /*10*/
1.


   D
   E
3.Head =3
4.Tail =0
//After  /*11*/ & /*12*/
F


E
Head =4
Tail =1
BUILD SUCCESSFUL (total time: 9 seconds)


















Friday 25 September 2015

Java concept (Stack Implementation)

Using Stack To reverse Input String


/*
 * To change this license header, choose License Headers in Project  *Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package stackimplementation;

import java.util.Scanner;

/*
  @author Adeniran Adetunji
 */

/* 
This program uses stack implementation to reverse a string e.g. Input "CAT" will output "TAC"
*/

public class StackImplementation {
   
/* Declare class variables Top: which keeps track the top of the stack, Size: the size of the stack that is predetermined, stack implementationwithan array "myStack".
*/

    int size;
    char [] myStack;
    int top;
    
    //set stack size to accomodate the string input
    
    void setSize(String n) 
   {
             
       int stackSize = n.length();
       
       size = stackSize;
       myStack = new char [size];
       top = myStack.length;
    }
    
    //push string character-by-character into stack
    void push(String myWord) 
   {
       
       if (top<=0)
       {
           System.out.println("Stack is full");
       }
       else
       {
       for (int i = 0; i<myWord.length(); i++)
       {
           
             myStack[top-1]=myWord.charAt(i);
           
           top--; //update top
       }
       
   }
   }
    
    //POP string in Last-in-first-out order from stack
     String pop()
    {
      String outString="";
      
      if (top==myStack.length)
      {
      System.out.println("Stack is Empty, Enter String to reverse");
      }
       for (int i= 0; i<myStack.length; i++) 
       {
           outString = outString+myStack[i];
           
           top++;
       }
      
     
      return outString;
    }
    

     //reverse string using push and pop methods
     String reverse(String n)
     {
         setSize(n);
         push(n);
         n = pop();
         
         return n;
         
     }
   
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
       String str;  //Declaratio of string to be reversed
       
       Scanner read = new Scanner(System.in);  
       
       System.out.println("Enter String Input: ");
       str = read.nextLine();  //read string from keyboard input
       
       //Declare a new stackImplementaton object
      StackImplementation reverseString = new StackImplementation();
       
       //reverse string input using stackImplementation
       str = reverseString.reverse(str);
       
       //Prints input string in reverse order   
       System.out.println(str);
          
   }
        
    }


OUTPUT:

run:

Enter String Input: 

Tunji

ijnuT

BUILD SUCCESSFUL (total time: 3 seconds)


    
Please comment or suggest better implementation: Tunji4physics2@gmail.com