Tuesday, September 15, 2009

Program to check two object of the same pojo same class having same valur or not

//This is Pojo class with two property name and email
class PojoBean {
private String name;
private String email;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}


}
// main class to test pojo object
class PojoMain
{
public static void main(String[] args)
{
//create first instance of the Pojo Class and set property values.
PojoBean pBeanOne = new PojoBean();
pBeanOne.setName("Pushpa");
pBeanOne.setEmail("ashish@gmail.com");


//create second instance of the Pojo Class and set property values.
PojoBean pBeanTwo = new PojoBean();
pBeanTwo.setName("ashish");
pBeanTwo.setEmail("ashish@gmail.com");

//code to check two object is having same data or not.
if(pBeanOne.getName().equals(pBeanTwo.getName())){
System.out.println("Two object is having same Name");
}
// second property email
if(pBeanOne.getEmail().equals(pBeanTwo.getEmail())){
System.out.println("Two object is having same email");
}



}
}

Read data from console and print in one file.

//Read data from console and print in one file.
import java.io.*;
class ReadDataFromConsole
{
public static void main(String[] args)
{
try{
String fileStr = ""; // declare a string variable
for(int i = 0; i'<'args.length; i++){ // for loop start with argument size

fileStr = fileStr + " " + args[i];
}


//create an instance of the random acces file "rfile'.
RandomAccessFile rfile = new RandomAccessFile("C:/Temp/text.txt","rw");
// write object into the file.
rfile.writeBytes(fileStr);


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

}
}
}

Tuesday, August 18, 2009

Fibonacci Series

class FibonacciNumbers
{
public static void main(String[] args)
{
System.out.println("Hello World!");
if(ContainNumber.onlyNumbers(args[0])){
int number = Integer.parseInt(args[0]);
int num1;
int num2= 0;
int num3 = 1;
while(number>0){
System.out.println(" F Series : " + num2);
num1 = num2;
num2= num3;
num3 = num1+num2;
number--;
}

}


}
}

//Program to Find Factorial of given number

class FindFactorial
{
public static void main(String[] args)
{

if(ContainNumber.onlyNumbers(args[0])){
int number = Integer.parseInt(args[0]);
int result = 1;
while(number>0){
result = result*number;
number--;
}
System.out.println("Factorial of given number : " + result);

}
else{
System.out.println("Enter number is not positive integer");
}
}
}

Friday, August 14, 2009

programe Compare Two No

import java.io.*;

class CompareTwoNo{
public static void main(String[] args) {
try{
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);

if(num1'/<'/num2){
System.out.println("Number " + num1 +" <" + " Number " +num2);
}
else
{
System.out.println("Number " + num1 +" >" + " Number " +num2);
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
}

Monday, May 4, 2009

Draw Triangle


Problem Statement:
Draw a triangle for a given size, using given character and pointing toward given direction.

Language:
Java

Platform:
Command Prompt

Command:
[Program] -size [Size] -char [Char] -direction [Direction]

Expected Input:
[Size]: Any positive integer. Error should be printed if non-positive integer or string is given.
[Char]: Any single char. Error should be printed if more then one char is given.
[Direction]: R/L/U/D for Right / Left / Up / Down. Error should be printed if any other input is given.
Note: The order of parameters may change.
Hint: First make programme with fix order of parameter to get a working code. Then attempt to process the command line input for parameter reordering. This approach is known as modular approach for programming.

Expected Output:
Print the triangle of given size in given direction using given character. See example for better understanding.

Example:
Interface:
$ java DrawTriangle -size 5 -char A -direction R
Output:
A
AA
AAA
AAAA
AAAAA
AAAA
AAA
AA
A

Saturday, May 2, 2009

Make Table


Problem Statement:
Write a program to generate a table of given number from command prompt.

Language:
Java

Platform:
Command Prompt

Command:
[Program] [Input Number]

Expected Input:
[Input Number]: Any Integer (positive or negative)

Expected Output:
Table of given integer from 1 to 10.

Example:
Interface:
C:\Program> java table 5
Output:
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50