Email Pattern check in Android

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by arifhasnat on 12/20/15.
*/
public class Utility {

private static Pattern pattern;
private static Matcher matcher;
//Email Pattern
private static final String EMAIL_PATTERN = “[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+”;

/**
* Validate Email with regular expression
*
* @param email
* @return true for Valid Email and false for Invalid Email
*/
public static boolean validate(String email) {
pattern = Pattern.compile(EMAIL_PATTERN);
matcher = pattern.matcher(email);
return matcher.matches();
}
}

Advertisements

Graphics Unit Interface(gui)-1 : JTabbedPane

graphics mode এ জাভা দিয়ে সহজে তৈরি করা যায় tabe ।tabe করার জন্য JTabbedPane use করা হয় । এটি swing এর একটি child class . javax.swing.JTabbbedPane.
প্রথমে TabeLayout নামে একটি class create করুন। কোড টুকু লিখুন ।


import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class TabeLayout extends JFrame{

public TabeLayout(){
super("Tabed introduction");
JTabbedPane tabbepane=new JTabbedPane();

JLabel label1=new JLabel("Label one");
JPanel panel1=new JPanel();

panel1.add(label1);
tabbepane.addTab("ONE ",null,panel1,"First panel");

JLabel label2=new JLabel("Label Two");

JPanel panel2=new JPanel();
panel2.setBackground(Color.orange);
panel2.add(label2);
tabbepane.addTab("Two",null, panel2, "Second panel");

JLabel label3=new JLabel();
JPanel panel3=new JPanel();
panel3.setLayout(new BorderLayout());
panel3.add(new JButton("top"),BorderLayout.NORTH);
panel3.add(new JButton("Footer"),BorderLayout.SOUTH);
panel3.add(new JButton("LEft"),BorderLayout.WEST);
panel3.add(new JButton("Right"),BorderLayout.EAST);

panel3.add(label3);
tabbepane.addTab("Three", null,panel3,"Third panel");

add(tabbepane);

}

}

এবার tabelayout_test নামে আরো একটি ক্লাস তৈরি করুন ।এটি মুলত main class . tabelayout class এখানে কল করা হয়েছে।

import javax.swing.JFrame;

public class tabelayout_test {

public static void main(String arg[]){

TabeLayout tl=new TabeLayout();
tl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tl.setSize(300, 250);
tl.setTitle(“I Love Allah. and (s) . “);
tl.setVisible(true)
;

}
}

Capture


কোড বিশ্লেষনঃ

প্রথমে package name গুলো import করে নিতে হবে ।
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class TabeLayout extends JFrame{

public TabeLayout(){
super(“Tabed introduction”);

এখানে tabbedPane create করা হয়েছে।
JTabbedPane tabbepane=new JTabbedPane();

label create করলাম

JLabel label1=new JLabel(“Label one”);

প্যানেল create করলাম

JPanel panel1=new JPanel();

label is added to panel.

panel1.add(label1);

panel is added to TabbedPane

tabbepane.addTab(“ONE “,null,panel1,”First panel”);

**********************************************************************
২য় tab এর কাজ শুরু
JLabel label2=new JLabel(“Label Two”);

JPanel panel2=new JPanel();

কালার add করেছি ।
panel2.setBackground(Color.orange);

panel2.add(label2);
tabbepane.addTab(“Two”,null, panel2, “Second panel”);
**********************************************************************
৩য় tab এর কাজ শুরু

JLabel label3=new JLabel();
JPanel panel3=new JPanel();
একটি বর্ডারলেয়াউট তৈরি করেছি।

panel3.setLayout(new BorderLayout());
চারটি লেয়াঊট করলাম।

panel3.add(new JButton(“top”),BorderLayout.NORTH);
panel3.add(new JButton(“Footer”),BorderLayout.SOUTH);
panel3.add(new JButton(“LEft”),BorderLayout.WEST);
panel3.add(new JButton(“Right”),BorderLayout.EAST);

label3 added to panel3

panel3.add(label3);

panel3 added to tabbedpane.

tabbepane.addTab(“Three”, null,panel3,”Third panel”);
অবশেষে tabbedpane কে আমরা JFrame add করলাম।

add(tabbepane);

}

}

এটি main class.

import javax.swing.JFrame;

public class tabelayout_test {

public static void main(String arg[]){

************calling TabeLayout class here*************

TabeLayout tl=new TabeLayout();
tl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tl.setSize(300, 250);
tl.setTitle(“I Love Allah. and (s) . “);
tl.setVisible(true)
;

}
}

Complex Numbers with input from keyboard

(Complex Numbers) Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form
realPart + imaginaryPart * i
where i is
Write a program to test your class. Use int type variables to represent the private data of the class. All values should taken input.
a) Add two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtract two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Print Complex numbers in the form (realPart, imageinaryPart).

solution:

import java.util.Scanner;
class part{
int real;
int complex;
int real1;
int complex1;
part(){
Scanner input =new Scanner(System.in);
System.out.println("Enter first real value: ");
real=input.nextInt();
System.out.println("Enter first imaginary value: ");
complex=input.nextInt();
System.out.println("Your first value is:"+"a="+"("+real+"x+i"+complex+"y"+")");

System.out.println("Enter your second real value :");

real1=input.nextInt();
System.out.println("Enter second real value: ");
complex1=input.nextInt();
System.out.println("Your second value is:"+"a="+"("+real1+"x+i"+complex1+"y"+")");

}
void add(){
System.out.println("Adding two values: ");
int real2=real+real1;
int complex2=complex+complex1;
System.out.println("After adding:"+real2+"x"+"+i"+complex2+"y");

}
void substruct(){
System.out.println("substracting two values : ");

int real3=real-real1;
int complex3=complex-complex1;
if(complex3>=0)
System.out.println("After substracting values: "+real3+"x"+"-"+complex3+"i");
else
System.out.println("After substracting values: "+real3+"x"+""+complex3+"i");

}

}
public class realcomplex {
public static void main(String arg[]){

part oikoi=new part();

oikoi.add();
oikoi.substruct();

}
}

Complex Numbers

(Complex Numbers) Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form
realPart + imaginaryPart * i
where i is
Write a program to test your class. Use floating-point variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods that perform the following operations:
a) Add two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtract two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Print Complex numbers in the form (realPart, imageinaryPart).

Solution

public class no13
{
private double real;
private double imaginary;

// Initialize both parts to 0
public no13()
{
this( 0.0, 0.0 );
} // end Complex no-argument constructor

public no13( double r, double i )
{
real = r;
imaginary = i;
} // end Complex two-argument constructor
// Add two Complex numbers
public no13 add( no13 right )
{
return new no13( real + right.real,
imaginary + right.imaginary );
} // end method add
// Subtract two Complex numbers
public no13 subtract( no13 right )
{
return new no13( real - right.real,
imaginary - right.imaginary );
} // end method subtract

// Return String representation of a Complex number
public String toString()
{
return String.format( "(%.1f, %.1f)", real, imaginary );
} // end method toComplexString;
} // end class Complex

class ComplexTest
{
public static void main( String args[] )
{
// initialize two numbers
no13 a = new no13( 9.5, 7.7 );
no13 b = new no13( 1.2, 3.1 );

System.out.printf( "a = %s\n", a.toString() );
System.out.printf( "b = %s\n", b.toString() );
System.out.printf( "a + b = %s\n", a.add( b ).toString() );
System.out.printf( "a - b = %s\n", a.subtract( b ).toString() );
} // end main
} // end class ComplexTest

solved by : arifur rahman

Printing the Decimal Equivalent of a Binary Number

(Printing the Decimal Equivalent of a Binary Number) Write a program that inputs an integer containing only 0s and 1s (i.e., a binary integer) and prints its decimal equivalent. [Hint: Use the remainder and division operators to pick off the binary number’s digits one at a time, from right to left. In the decimal number system, the rightmost digit has a positional value of 1 and the next digit to the left a positional value of 10, then 100, then 1000, and so on. The decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. In the binary number system, the rightmost digit has a positional value of 1, the next digit to the left a positional value of 2, then 4, then 8, and so on. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8, or 1 + 0 + 4 + 8 or, 13.]

Solution:

import java.util.Scanner;

public class binary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int bNumber,bNumberCopy,i=7,dNumber=0; int digit[] = new int[8];
//String strBinaryNumber = "11011001";

System.out.print("\nEnter binary number(max digits: 8) :");
bNumber = sc.nextInt();
if((Integer.toString(bNumber)).length() 0){
digit[i] = bNumberCopy % 10;
bNumberCopy /= 10;
i--;
}
for(int j=7;j>=0;j--){
dNumber += (Math.pow(2,(7-j))*digit[j]);
}
System.out.print("\nDecimal form of '" + bNumber + "' is :" + dNumber);
}else{
System.out.print("\nInvalid input,,,,program terminates.");
}
}
}