|
/*
*first.java
* Author Mahesh-cse-b520
*created on 23/12/2011
*To Print The Name of the String
*/
import java.lang.*;
class First
{
public static void main(String a[])
{
System.out.println("Mahesh");
}
}
/*
*Room area2.java
* Author Mahesh-cse-b520
*created on 23/12/2011
*To Calculate Area in which values are predefined
*/
import java.lang.*;
class Room
{
int length=0, breadth=0;
void getData(int a, int b)
{
length=a; breadth=b;
}
}
class RoomArea2
{
public static void main(String a[])
{
Room r=new Room();
r.getData(11,11);
int area;
area=r.length*r.breadth;
System.out.println("Area of Room is:"+area);
}
}
/*
*Room Area1.java
* Author Mahesh-cse-b520
*created on 23/12/2011
*To print the area in a user interactive manner
*/
import java.lang.*;
import java.io.*;
class RoomArea1
{
public static void main(String a[])
{
int length=0, breadth=0;
try{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("\n Enter Room Length:");
String str1=dis.readLine();
System.out.println("\n Enter Room Breadth:");
String str2=dis.readLine();
System.out.println("Length is:"+str1);
System.out.println("Breadth is :"+str2);
int area;
Integer objLength=Integer.valueOf(str1);//To convert String Object to Intiger Object
Integer objBreadth=Integer.valueOf(str2);
length=objLength.intValue();//To get an Integer Value
breadth=objBreadth.intValue();
area=length*breadth;
System.out.println("Area of room is:"+area);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
/*
*Room.java
* Author Mahesh-cse-b520
*created on 23/12/2011
*/
package praveen;
public class Room
{
public int length=0, breadth=0;
public void getData(int a, int b)
{
length=a; breadth=b;
}
}
// RoomArea.java
import java.lang.*;
import praveen.Room;
class RoomArea
{
public static void main(String a[])
{
Room r=new Room();
r.getData(3,30);
int area;
area=r.length*r.breadth;
System.out.println("Area of Room is:"+area);
}
}
/*
*StringOp.java
* Author Mahesh-cse-b520
*created on 23/12/2011
*To find given string palindrome or not
*/
import java.lang.*;
class StringOp
{
public static void main(String a[])
{
boolean flag=true;
String str="eye";
System.out.println();
int len= str.length();
for(int i=0;i<(len/2);i++)
{
if(str.charAt(i)==str.charAt((len-1)-i)) ;
else { flag=false; break;}
}
if(flag==true) System.out.println("Palindrome");
else System.out.println("Not Palindrome");
}
}
/*
*Basic.java
* Author Mahesh-cse-b520
*created on 30/12/2011
*Basic program in java
*/
import java.lang.*;
class Basic
{
public static void main(String args[])
{
System.out.println("Student");
}
}
/*
*Sum.java
* Author Mahesh-cse-b520
*created on 30/12/2011
*Sum of a and b
*/
import java.lang.*;
class Sum
{
public static void main(String args[])
{
int a,b,sum;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
sum=a+b;
System.out.println("Sum is:"+sum);
}
}
/*
*Sum1.java
* Author Mahesh-cse-b520
*created on 30/12/2011
*sum of N consecutive natural numbers
*/
import java.lang.*;
class Sum1
{
public static void main(String arg[])
{
int n=Integer.parseInt(arg[0]);
int sum=(n*(n+1))/2;
System.out.println("Sum of "+n+" natural numbers is:"+sum);
}
}
/*
*Sum2.java
* Author Mahesh-cse-b520
*created on 30/12/2011
*sum of b consecutive natural numbers after particular number a
*/
import java.lang.*;
class Sum2
{
public static void main(String arg[])
{
int a,b,sum=0;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
for(int i=a;i<a+b;i++)
{
sum=sum+i;
}
System.out.println("Sum of "+b+" consecutive natural numbers from "+a+":"+sum);
}
}
/*
*Sort.java
* Author Mahesh-cse-b520
*created on 30/12/2011
*Sorting of 5 numbers
*/
import java.lang.*;
class Sort
{
public static void main(String args[])
{
int arr[]=new int[5];
arr[0]=4;
arr[1]=3;
arr[2]=5;
arr[3]=1;
arr[4]=2;
for(int i=0;i<4;i++)
{
int small=i;
for(int j=i;j<5;j++)
{
if(arr[j]<arr[small])
small=j;
}
int temp=arr[i];
arr[i]=arr[small];
arr[small]=temp;
}
for(int i=0;i<5;i++)
System.out.println(arr[i]+"");
}
}
/*
*MagicSquare.java
* Author Mahesh-cse-b520
*created on 7/12/2011
*Print Magic Square of Order N
*/
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class MagicSquare
{
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
if (N % 2 == 0) throw new RuntimeException("N must be odd");
int[][] magic = new int[N][N];
int row = N-1;
int col = N/2;
magic[row][col] = 1;
for (int i = 2; i <= N*N; i++)
{
if (magic[(row + 1) % N][(col + 1) % N] == 0)
{
row = (row + 1) % N;
col = (col + 1) % N;
}
else {
row = (row - 1 + N) % N;
}
magic[row][col] = i;
}
for (int i = N-1; i>-1; i--) {
for (int j = 0; j < N; j++) {
if (magic[i][j] < 10) System.out.print(" ");
if (magic[i][j] < 100) System.out.print(" ");
System.out.print(magic[i][j] + " ");
}
System.out.println();
}
}
}
/*
*GCD.java
* Author Mahesh-cse-b520
*created on 06/01/2012
*GCD For Two Numbers
*/
import java.lang.*;
class GCD
{
public static void main(String args[])
{ int a,b,gcd;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
gcd=GCD1(a,b);
System.out.println("GCD is"+gcd );
}
public static int GCD1(int x,int y)
{
if(x>y&&y==0)
return x;
if(x<y&&x==0)
return y;
if(x>y)
return GCD1(y,x%y);
if(x<y)
return GCD1(x,y%x);
if(x==y)
return 0;
return 0;
}
}
/*
*LCM.java
* Author Mahesh-cse-b520
*created on 06/01/2012
*LCM Of two Numbers
*/
import java.lang.*;
class LCM
{
public static void main(String args[])
{ int a,b,gcd,lcm;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
gcd=GCD1(a,b);
lcm=(a*b)/gcd;
System.out.println("LCM is"+lcm );
}
public static int GCD1(int x,int y)
{
if(x>y&&y==0)
return x;
if(x<y&&x==0)
return y;
if(x>y)
return GCD1(y,x%y);
if(x<y)
return GCD1(x,y%x);
if(x==y)
return 0;
return 0;
} }
/* Program to create User defined Stack of type Integer.
*MyStack1.java
* Author Mahesh-cse-b520
*created on 06/01/2012
*/
import java.lang.*;
import java.io.*;
class MyException extends Exception
{
MyException(String str){ super(str); }
}
class MyStack1
{
int size;
int top;
int S[];
MyStack1(int n)
{
size=n;
top=-1;
S=new int[size];
}
void push(int ele)
{
try{
if(top==size-1){throw new MyException("Stack Overflow"); }
S[++top]=ele;
}
catch(Exception e){ System.out.println(e.getMessage()); }
}
int pop()
{
try{
if(top==-1){ throw new MyException("Stack UnderFlow"); }
}
catch(Exception e){ System.out.println(e.getMessage());return S[top]; }
return S[top--];
}
int peek()
{
try{
if(top==-1){ throw new MyException("Stack is Empty"); }
}
catch(Exception e){ System.out.println(e.getMessage());}
return S[top];
}
public static void main(String args[])
{
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter Size of the Stack");
String str=dis.readLine();
int val=Integer.parseInt(str);
MyStack1 st=new MyStack1(val);
int ch=0;
System.out.println("\n 1.for PUSH \n 2. for POP \n 3. for PEEK 4 . for EXIT\n Enter Your Choice:");
do
{
str=dis.readLine();
ch=Integer.parseInt(str);
try{
switch(ch)
{
case 1: System.out.print("\n Enter value to push into Stack:");
str=dis.readLine();
st.push(Integer.parseInt(str));
break;
case 2: System.out.println("\n Poped value is:"+st.pop()); break;
case 3:System.out.println("\n Top of the Stack is:"+st.peek()); break;
case 4:System.exit(1);
default:System.out.println("\n Enter Proper Choice"); ch=0;break;
}
}catch(Exception e)
{
System.out.println(e);
}
System.out.println("\n 1.for PUSH \n 2. for POP \n 3. for PEEK 4 . for EXIT\n Enter Your Choice:");
}while(ch<=4);
}catch(Exception e)
{
System.out.println(e);
}
}
}
/*
*Queue.java
*B.Naga Mahesh
*6,january,2012
*Program in java to perform Queue operations
*/
import java.lang.*;
import java.io.*;
class Queue
{
int size;
int front,rear;
int q[];
Queue(int n)
{
size=n;
front=0;
rear=0;
q=new int[size];
}
void insert(int ele)
{
try
{
if(rear==size-1)
{
throw new MyException("queue Overflow");
}
q[rear++]=ele;
}
catch(Exception e)
{
System.out.println(e.getMessage());
} }
int delt()
{
try
{
if(front==rear)
{
throw new MyException("queue UnderFlow");
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
return q[front];
}
return q[front++];
}
int peek()
{
try
{
if(front==rear)
{
throw new MyException("QUEUE is Empty");
} }
catch(Exception e)
{
System.out.println(e.getMessage());
}
return q[front];
}
public static void main(String args[])
{
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter Size of the queue");
String str=dis.readLine();
int val=Integer.parseInt(str);
Queue qe=new Queue(val);
int ch=0;
while(ch<=4)
{
System.out.println("\n 1.for INSERT\n 2. for DELETE \n 3. for peek \n 4. for EXIT\n Enter Your Choice:");
str=dis.readLine();
ch=Integer.parseInt(str);
try
{
switch(ch)
{
case 1: System.out.print("\n Enter value to push into QUEUE:");
str=dis.readLine();
qe.insert(Integer.parseInt(str));
break;
case 2: System.out.println("\n DELETED ELE value is:"+qe.delt());
break;
case 3:System.out.println("\n Top of the QUEUE is:"+qe.peek());
break;
case 4:System.exit(1);
default:System.out.println("\n Enter Proper Choice");
ch=0;
break;
} }
catch(Exception e)
{
System.out.println(e);
} } }
catch(Exception e)
{
System.out.println(e);
} } }
/* Program to create inbuilt Stack Class.
*inbuiltsta.java
* Author Mahesh-cse-b520
*created on 06/01/2012
*/
import java.io.*;
import java.util.*;
class inbuiltsta{
public static void main(String args[]){
int x=0,y=0;
char ch ='1';
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Please enter the size of the stack\n");
try{
x = Integer.parseInt(dis.readLine());
}catch(Exception e){x=0;}
System.out.println(x+"");
Stack a = new Stack();
while(ch!='4')
{ System.out.println("1. push\n2. pop\n 3.peek\n 4. exit");
try{
ch= (dis.readLine()).charAt(0);
}catch(Exception e){}
System.out.println(ch+"");
switch(ch){
case '1':
System.out.println("Please enter the integer");
try{
y = Integer.parseInt(dis.readLine());
}catch(Exception e){x=0;}
a.push(y+"");
break;
case '2':
System.out.println(a.pop());
break;
case '3':
System.out.println("top element is"+a.peek());
break;
default:
System.out.println("Please enter a valid input");
break;
}}}}
/*
*Pascal.java
* Author Mahesh-cse-b520
*created on 20/01/2012
*Program to print the pascal triangle for given number
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Pascal1 {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
int[][] pascal = new int[N+1][]; // initialize first row
pascal[0] = new int[3];
pascal[0][1] = 1; // fill in Pascal's triangle
for (int i = 1; i <= N; i++) {
pascal[i] = new int[i + 3];
for (int j = 1; j < pascal[i].length - 1; j++)
pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];
} // print results
for (int i = 0; i <= N; i++) {
for (int j = 1; j <= N - i; j++) {
System.out.print(" ");
}
for (int j = 1; j < pascal[i].length - 1; j++)
{ System.out.print(pascal[i][j] + " "); }
System.out.println(); }
} }
/*
*HS.java
* Author Mahesh-cse-b520
*created on 20/01/2012
*Program to Find Harmonic Series
*/
import java.lang.*;
import java.io.*;
class HS{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
double result = 0.0;
while(num > 0){
result = result + (double) 1 / num;
num--;
}
System.out.println("Output of Harmonic Series is "+result);
}
}
/*
*distance.java
* Author Mahesh-cse-b520
*created on 20/01/2012
*Program to Find Distance s=ut+1/2(at2)
*/
import java.util.*;
class distance
{
public static void main(String args[])
{
int ch=0;
float u,t,a,dist=0;
Scanner sc;
sc=new Scanner(System.in);
do
{
System.out.println("1.Enter t,a,u \n 2.Exit");
System.out.println("Enter ur choice:");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter time , initial speed & acceleration:");
t=sc.nextFloat();
u=sc.nextFloat();
a=sc.nextFloat();
dist=(u*t)+((a*t*t)/2);
System.out.println("The distance is:"+dist);
case 2:
break;
}
}while(ch!=2);
}
}
/*
*Celsius.java
* Author Mahesh-cse-b520
*created on 20/01/2012
*Program to Convert Farenheit to celsius
*/
import java.lang.*;
class Celsius
{
public static void main(String args[])
{
double c[]=new double[20];
double f[]=new double[20];
int n;
n=args.length;
for(int i=0;i<n;i++)
{
f[i]=Integer.parseInt(args[i]);
}
for(int i=0;i<n;i++)
{
c[i]=(f[i]-32)/1.8;
}
System.out.println(" farenheit-celsius");
for(int i=0;i<n;i++)
{
System.out.println(" "+f[i]+" "+c[i]);
} } }
/*
*Depreciation.java
* Author Mahesh-cse-b520
*created on 20/01/2012
*Program to Find Depreciation Value=(Purchase Value-Salvage Value)/Years of service
*/
import java.lang.*;
import java.io.*;
class Depreciation
{
public static void main(String args[])
{
int d=0,p=0,y=0,s=0;
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("\n enter the depriciation");
String str1=dis.readLine();
System.out.println("\n enter the purchase price");
String str2=dis.readLine();
System.out.println("\n enter the years of service");
String str3=dis.readLine();
Integer objd=Integer.valueOf(str1);
Integer objp=Integer.valueOf(str2);
Integer objy=Integer.valueOf(str3);
d=objd.intValue();
p=objp.intValue();
y=objy.intValue();
s=p-(d*y);;
System.out.println("salvage value is"+s);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
/*
*Mymath.java
* Author Mahesh-cse-b520
*created on 27/01/2012
*Program Math operations
*/
import java.lang.*;
class Mymath
{
public static void main(String args[])
{
System.out.println(Math.E);
System.out.println("Value of pi "+Math.PI);
System.out.println("absolute Value of -100 "+Math.abs(-100));
System.out.println("Value of acos "+Math.acos(-1));
System.out.println("Value of acos in degrees "+Math.toDegrees(Math.acos(-1)));
System.out.println("absolute Value of -1.23 "+Math.abs(-1.23));
System.out.println("Value of asin "+Math.asin(1));
System.out.println("Value of asin in degrees"+Math.toDegrees(Math.asin(1)));
System.out.println("Value of atan"+Math.atan(1));
System.out.println("Value of acos "+Math.toDegrees(Math.acos(-1)));
System.out.println("Value of asin "+Math.toDegrees(Math.asin(1)));
System.out.println("Value of atan "+Math.toDegrees(Math.atan(1)));
System.out.println("Value of atan2 "+Math.toDegrees(Math.atan2(1,0)));
System.out.println("Value of cbrt "+Math.cbrt(27));
System.out.println("Value of ceil "+Math.ceil(10.02));
System.out.println("Value of copySign "+Math.copySign(-10,15));
System.out.println("Value of cos "+Math.cos(0));
System.out.println("Value of cosh "+Math.cosh(1));
System.out.println("Value of exp "+Math.exp(2));
System.out.println("Value of expm1 "+Math.expm1(2));
System.out.println("Value of floor "+Math.floor(-10.03));
System.out.println("Value of getExponent "+Math.getExponent(103));
System.out.println("Value of hypot "+Math.hypot(1,1));
System.out.println("Value of IEEEremainder "+Math.IEEEremainder(2,9));
System.out.println("Value of log "+Math.log(2));
System.out.println("Value of log10 "+Math.log10(2));
System.out.println("Value of log1p "+Math.log1p(2));
System.out.println("Value of max "+Math.max(7,3));
System.out.println("Value of min "+Math.min(10,7));
System.out.println("Value of nextAfter "+Math.nextAfter(10,2));
System.out.println("Value of nextUp "+Math.nextUp(7));
System.out.println("Value of pow "+Math.pow(7,2));
System.out.println("Value of random "+Math.random());
System.out.println("Value of rint "+Math.rint(10.47));
System.out.println("Value of round "+Math.round(10.67));
System.out.println("Value of scalb "+Math.scalb(7,3));
System.out.println("Value of signum "+Math.signum(-7));
System.out.println("Value of sin "+Math.sin(90));
System.out.println("Value of sinh "+Math.sinh(1));
System.out.println("Value of sqrt "+Math.sqrt(9));
System.out.println("Value of tan "+Math.tan(0));
System.out.println("Value of tanh "+Math.tanh(1));
System.out.println("Value of acos "+Math.toRadians(Math.acos(1)));
System.out.println("Value of ulp "+Math.ulp(3));
}
}
/*
*Rectangle.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to find the area of a rectangle.
*/
import java.lang.*;
import java.io.*;
class Rectangle
{
int length,width; //Declaration of variables
void getdata(int x,int y) //Definition of method
{
length=x;
width=y;
}
int rectarea() //Definition of another method
{
int area=length*width;
return(area);
}
}
class rectarea //Class with main method
{
public static void main(String args[])
{
int area1,area2;
Rectangle rect1=new Rectangle(); //Creating objects
Rectangle rect2=new Rectangle();
rect1.length=15; //Accessing methods
rect1.width=10;
area1=rect1.length*rect1.width;
rect2.getdata(20,12); //Accessing methods
area2=rect2.rectarea();
System.out.println("Area="+area1);
System.out.println("Area="+area2);
}
}
/*
*Rectangle1.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to find the area of a rectangle.
*/
import java.lang.*;
import java.io.*;
class Rectangle1
{
int length,width;
Rectangle1(int x,int y) //Defining constructor
{ length=x;
width=y;
}
int rectarea()
{ return(length*width);
}
}
class rectanglearea
{
public static void main(String args[])
{ Rectangle1 rect1=new Rectangle1(15,10); //Calling constructor
int area1=rect1.rectarea();
System.out.println("Area="+area1);
}
}
/*
*perimeter.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to find the perimeter of a rectangle.
*/
import java.lang.*;
import java.io.*;
class perimeter
{
int length;
int breadth;
//default constructor
perimeter()
{
length=0;
breadth=0;
}
//parameterized constructor
perimeter(int x,int y)
{
length=x;
breadth=y;
}
void cal_perimeter()
{
int peri;
peri=2*(length+breadth);
System.out.println("\nThe perimeter of the rectangle is :"+peri);
}
}
class Ex_default_c
{
public static void main(String args[])
{
perimeter p1=new perimeter(); //calling default constructor
perimeter p2=new perimeter(5,10); //calling parametrised constructor
p1.cal_perimeter();
p2.cal_perimeter();
}
}
/*
*Mathoperation.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to calculate division and multiplication using mathoperation.
*/
import java.lang.*;
import java.io.*;
class Mathoperation
{
static float mul(float x,float y)
{ return x*y;
}
static float divide(float x,float y)
{ return x/y;
}
}
class MathApplication
{
public static void main(String args[])
{
float a=Mathoperation.mul(4,5);
float b=Mathoperation.divide(a,2);
System.out.println("b="+b);
}
}
/* *NestinTest.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to Implent nesting of methods.
*/
import java.lang.*;
import java.io.*;
class Nesting
{
int m,n;
Nesting(int x,int y)
{ m=x;
n=y;
}
int largest()
{ if(n>=m)
return n;
else
return m;
}
void display()
{ int large=largest();
System.out.println("Largest Value:"+large);
} }
class NestingTest
{
public static void main(String args[])
{ Nesting nest=new Nesting(50,40);
nest.display();
} }
/*
*InherTest.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to Implent Inheritance.
*/
import java.lang.*;
import java.io.*;
class Room
{
int length;
int breadth;
Room(int x,int y)
{
length=x;
breadth=y;
}
int area()
{
return(length*breadth);
}
}
class BedRoom extends Room //Inheriting Room
{
int height;
BedRoom(int x,int y,int z)
{
super(x,y); //pass values to superclass
height=z;
}
int volume()
{
return(length*breadth*height);
}
}
class InherTest
{
public static void main(String args[])
{
BedRoom room1=new BedRoom(14,12,10);
int area1=room1.area(); //superclass method
int volume1=room1.volume(); //baseclass method
System.out.println("Area1:"+area1);
System.out.println("Volume:"+volume1);
}
}
/*
*OverrideTest.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to Implent Overriding methods.
*/
import java.lang.*;
import java.io.*;
class Super
{
int x;
Super(int x)
{
this.x=x;
}
void display() //method define
{
System.out.println("Super x="+x);
}
}
class Sub extends Super
{
int y;
Sub(int x,int y)
{
super(x);
this.y=y;
}
void display() //method define again
{
System.out.println("Super x="+x);
System.out.println("Sub y="+y);
}
}
class OverrideTest
{ public static void main(String args[])
{
Sub s1=new Sub(100,200);
s1.display();
}
}
/*
*Exampleprg.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to Implent Method with varargs.
*/
import java.lang.*;
import java.io.*;
class Exampleprg
{
Exampleprg(String...person)
{
for(String name:person)
{
System.out.println("Hello "+name);
}
}
public static void main(String args[])
{
Exampleprg obj=new Exampleprg(" Mahesh"," Ravi"," prudhvi");
}
}
/*
*Dyn_dis.java
* Author Mahesh-cse-b520
*created on 03/02/2012
*Program to Implent Dynamic Method dispatch.
*/
import java.lang.*;
import java.io.*;
class Super1
{
public void method()
{ System.out.println("Method Super");
}
}
class Sub extends Super1
{
public void method()
{ System.out.println("Methoid Sub");
}
}
class Dyn_dis
{
public static void main(String args[])
{ Super1 A=new Sub();
A.method();
} }
//package student;
/*
*ClassInPackage.java
* Author Mahesh-cse-b520
*created on 04/02/2012
*Visibility of class in Package Student
*/
import java.lang.*;
public class ClassInPackage
{
public int a=88;
protected int b=99;
int c=30;
private int d=40;
}
/*
*SubClassInSamePackage.java
* Author Mahesh-cse-b520
*created on 04/02/2012
*Visibility of sub class in same package
*/
import java.lang.*;
class SubClassInSamePackage extends SameClass
{
public static void main(String args[])
{
SubClassInSamePackage ob=new SubClassInSamePackage();
System.out.println("Value of a is:"+ob.a);
System.out.println("Value of b is:"+ob.b);
System.out.println("Value of c is:"+ob.c);
//System.out.println("Value of d is:"+ob.d);
}
}
/*
*SubClassInOtherPackage.java
* Author Mahesh-cse-b520
*created on 04/02/2012
*Visibility of non sub class in same package
*/
import java.lang.*;
import student.ClassInPackage;
class NonSubClassInOtherPackage
{
public static void main(String args[])
{
ClassInPackage ob= new ClassInPackage();
System.out.println("Value of a is:"+ob.a);
//System.out.println("Value of bis:"+ob.b);
}
}
/*
*SameClass.java
* Author Mahesh-cse-b520
*created on 04/02/2012
*Visibility of same class
*/
import java.lang.*;
class SameClass
{
public int a=10;
protected int b=20;
int c=30;
private int d=40;
public static void main(String args[])
{
SameClass ob=new SameClass();
System.out.println("Value of a is:"+ob.a);
System.out.println("Value of b is:"+ob.b);
System.out.println("Value of c is:"+ob.c);
System.out.println("Value of d is:"+ob.d);
}
}
/*
*SubClassnOtherPackage.java
* Author Mahesh-cse-b520
*created on 04/02/2012
*Visibility of sub class in other Package
*/
import java.lang.*;
import student.ClassInPackage;
class SubClassInOtherPackage extends ClassInPackage
{
public static void main(String args[])
{
SubClassInOtherPackage ob= new SubClassInOtherPackage();
System.out.println("Value of a is:"+ob.a);
System.out.println("Value of b is:"+ob.b);
//System.out.println("Value of c is:"+ob.c);
}
}
/* Program to perform operations on String Objects */
/*
*Mystring1.java
* Author Mahesh-cse-b520
*created on 10/02/2012
*/
import java.lang.*;
class MyString1
{
public static void main(String args[])
{
String str1=new String(" Student ");
String str2=new String("Very Good");
String str3=new String("Student");
System.out.println(str1.length());
//System.out.println(str1.toLowerCase()+"\t\t"+str2.toUpperCase());
//System.out.println(str1.length()+"\t\t"+str2.length());
System.out.println((str1.trim()).length());
//System.out.println(str1.length()+"\t\t"+str2.length());
//System.out.println(str1.replace('e','B'));
//System.out.println(str1.equals(str3));
//System.out.println(str1.equalsIgnoreCase(str3));
//System.out.println(str1.compareTo(str3));
//System.out.println(str1.concat(str3));
//System.out.println(str1.charAt(2));
//System.out.println(str1.substring(1));
//int a=10, b=20;
//System.out.println(a+b);
//System.out.println(String.valueOf(a)+String.valueOf(b));
//System.out.println(str1.startsWith("Stu"));
String str4=new String(" All Students are Very Good");
System.out.println(str4.replaceAll(" "," fine "));
String s1[]=str4.split(" ");
for(String name:s1)
System.out.println(name);
}
}
/*
*Bank.java
* Author Mahesh-cse-b520
*created on 10/02/2012
* Program to implement bank operations
*/
import java.lang.*;
import java.io.*;
class BankWork
{
final int max_limit=20;
final int min_limit=1;
final double min_bal=500;
private String name[]=new String[20];
private int accNo[]=new int[20];
private String accType[]=new String[20];
private double balAmt[]=new double[20];
static int totRec=0;
BankWork() //constructor
{ for(int i=0;i<max_limit;i++)
{ name[i]="";
accNo[i]=0;
accType[i]="";
balAmt[i]=0.0;
}
}
public void newEntry() //TO ADD NEW RECORD
{ String str;
int acno;
double amt;
boolean permit;
permit=true;
if (totRec>max_limit)
{
System.out.println("\n\n\nSorry we cannot admit you in our bank...\n\n\n");
permit=false;
}
if(permit = true) //Allows to create new entry
{
totRec++; // Incrementing Total Record
System.out.println("\n\n\n=====RECORDING NEW ENTRY=====");
try{
accNo[totRec]=totRec; //Created AutoNumber to accNo so no invalid id occurs
System.out.println("Account Number : "+accNo[totRec]);
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Name : ");
System.out.flush();
name[totRec]=obj.readLine();
System.out.print("Enter Account Type : ");
System.out.flush();
accType[totRec]=obj.readLine();
do{
System.out.print("Enter Initial Amount to be deposited : ");
System.out.flush();
str=obj.readLine();
balAmt[totRec]=Double.parseDouble(str);
}while(balAmt[totRec]<min_bal); // Validation that minimun amount must be 500
System.out.println("\n\n\n");
}
catch(Exception e)
{}
}
}
//TO DISPLAY DETAILS OF RECORD
public void display()
{
String str;
int acno=0;
boolean valid=true;
System.out.println("\n\n=====DISPLAYING DETAILS OF CUSTOMER=====\n");
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account number : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println("\n\n\nInvalid Account Number \n\n");
valid=false;
}
if (valid==true)
{
System.out.println("\n\nAccount Number :"+accNo[acno]);
System.out.println("Name : "+name[acno]);
System.out.println("Account Type : "+accType[acno]);
System.out.println("Balance Amount : "+balAmt[acno]+"\n\n\n");
}
}
catch(Exception e)
{}
}
//TO DEPOSIT AN AMOUNT
public void deposit()
{
String str;
double amt;
int acno;
boolean valid=true;
System.out.println("\n\n\n=====DEPOSIT AMOUNT=====");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account No : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println("\n\n\nInvalid Account Number \n\n");
valid=false;
}
if (valid==true)
{
System.out.print("Enter Amount you want to Deposit : ");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
balAmt[acno]=balAmt[acno]+amt;
//Displaying Depsit Details
System.out.println("\nAfter Updation...");
System.out.println("Account Number : "+acno);
System.out.println("Balance Amount : "+balAmt[acno]+"\n\n\n");
}
}
catch(Exception e)
{}
}
//TO WITHDRAW BALANCE
public void withdraw()
{
String str;
double amt,checkamt;
int acno;
boolean valid=true;
System.out.println("\n\n\n=====WITHDRAW AMOUNT=====");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account No : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println("\n\n\nInvalid Account Number \n\n");
valid=false;
}
if (valid==true)
{
System.out.println("Balance is : "+balAmt[acno]);
System.out.print("Enter Amount you want to withdraw : ");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
checkamt=balAmt[acno]-amt;
if(checkamt >= min_bal)
{
balAmt[acno]=checkamt;
//Displaying Depsit Details
System.out.println("\nAfter Updation...");
System.out.println("Account Number : "+acno);
System.out.println("Balance Amount : "+balAmt[acno]+"\n\n\n");
}
else
{
System.out.println("\n\nAs per Bank Rule you should maintain minimum balance of Rs 500\n\n\n");
}
}
}
catch(Exception e)
{}
}
};
class Bank
{
public static void main(String args[])
{
String str;
int choice;
choice=0;
BankWork BW_obj = new BankWork();
do
{
System.out.println("Choose Your Choices ...");
System.out.println("1) New Record Entry ");
System.out.println("2) Display Record Details ");
System.out.println("3) Deposit...");
System.out.println("4) Withdraw...");
System.out.println("5) Exit");
System.out.print("Enter your choice : ");
System.out.flush();
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
str=obj.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1 : //New Record Entry
BW_obj.newEntry();
break;
case 2 : //Displaying Record Details
BW_obj.display();
break;
case 3 : //Deposit...
BW_obj.deposit();
break;
case 4 : //Withdraw...
BW_obj.withdraw();
break;
case 5 : System.out.println("\n \n.....THANKS FOR VISITING.....");
break;
default : System.out.println("\nInvalid Choice \n\n");
}
}
catch(Exception e)
{}
}while(choice!=5);
}
}
/*
*Bank.java
* Author Mahesh-cse-b520
*created on 10/02/2012
*Program to perform operations on Stringbuffer Objects
*/
import java.lang.*;
class MyStringBuffer1
{
public static void main(String args[])
{
StringBuffer str1=new StringBuffer(" Student ");
StringBuffer str2=new StringBuffer("Very Good");
StringBuffer str3=new StringBuffer("Student");
System.out.println(str1.append(true));
System.out.println(str1.append("i"));
System.out.println(str1.capacity());
System.out.println(str3.charAt(4));
System.out.println(str1.deleteCharAt(4));
System.out.println(str3.insert(4,false));
System.out.println(str1.replace(2,5,"stu"));
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
}
}
/*
*Bank.java
* Author Mahesh-cse-b520
*created on 10/02/2012
*demonstration of vectors
*/
import java.lang.*;
import java.util.*;
import java.io.*;
class MyVector
{
Vector v1;
Vector v2;
Vector v3;
MyVector()
{
//Constructors
v1=new Vector();
v2=new Vector(6);
v3=new Vector(4,3);
System.out.println("\n Initial Capacity of v1:"+v1.capacity()+
"\t Size:"+v1.size());
System.out.println("\n Initial Capacity of v2:"+v2.capacity()+
"\t Size:"+v2.size());
System.out.println("\n Initial Capacity of v3:"+v3.capacity()+
"\t Size:"+v3.size());
}
void myAdd()
{
//Add 11 objects to Vector1
v1.add("1"); v1.add("2");v1.add("3"); v1.add("4");
v1.add("5"); v1.add("6");v1.add("7"); v1.add("8");
v1.add("9");v1.add("10");v1.add("11");
//Add 7 objects to Vector2
v2.add("A"); v2.add("B");v2.add("C"); v2.add("D");
v2.add("E"); v2.add("F");v2.add("G");
//Add 5 Objects to Vector3
v3.add("1A"); v3.add("2B");v3.add("3C"); v3.add("4D");v3.add("5D");
}
void display1(Vector v)
{ Iterator it1=v.iterator();
System.out.println("\n \n Objects of Vector"+getClass());
while(it1.hasNext()){ System.out.print("\t"+it1.next());}
System.out.println("\n\n Present Capacity of v1:"+v.capacity()+
"\t Size:"+v.size());
}
void display()
{
Iterator it1=v1.iterator();
System.out.println("\n \n Objects of Vector1");
while(it1.hasNext()){ System.out.print("\t"+it1.next()); }
System.out.println("\n\n Present Capacity of v1:"+v1.capacity()+
"\t Size:"+v1.size());
/*
Iterator it2=v2.iterator();
System.out.println("\n \n Objects of Vector2");
while(it2.hasNext()){ System.out.print("\t"+it2.next()); }
System.out.println("\n \nPresent Capacity of v2:"+v2.capacity()+
"\t Size:"+v2.size());
Iterator it3=v3.iterator();
System.out.println("\n \n Objects of Vector3");
while(it3.hasNext()){ System.out.print("\t"+it3.next()); }
System.out.println("\n \nPresent Capacity of v3:"+v3.capacity()+
"\t Size:"+v3.size());*/
}
void elementOperations()
{
/*
display();
System.out.println("\n Fisrt Element of v1:"+v1.firstElement());
display();
System.out.println("\n Last Element of v1:"+v1.lastElement());
display();
System.out.println("\n Insert Element into v1 at pos 1");
v1.insertElementAt("99",1);
display();
System.out.println("\nRemove Element from v1 at pos1");
v1.removeElementAt(1);
*/
display();
System.out.println("\n Element at 10th Pos "+v1.get(10));
System.out.println("\n Element at 10th Pos "+v1.elementAt(10));
v1.setElementAt("CSE Student", 10);
System.out.println("\n Element at 10th Pos "+v1.elementAt(10));
System.out.println("\n Before Removing All Elements");
display();
//v1.removeAllElements();
Vector v4=(Vector)v1.clone();
v1.clear();
System.out.println("\n After Removing All Elements of v1");
display1(v1);
System.out.println("\n After Removing All Elements of v4");
display1(v4);
}
void fewMore()
{
/*System.out.println("\n Contains \"10\":"+v1.contains("10"));
Vector v5=new Vector();
v5.add("1");
v5.add("2");
v5.add("13");
display1(v1);
display1(v5);
System.out.println("\n Contains All:"+v1.containsAll(v5));*/
String str=v1.toString();
System.out.println("\n Output of toString function:"+v1.toString());
String x[]=new String[v1.size()];
v1.toArray(x);
System.out.println("Length is:"+x.length);
for(byte i=0;i<x.length;i++)
{ System.out.println(x[i]);
} }
public static void main(String args[])
{
MyVector ob=new MyVector();
ob.myAdd();
//ob.display();
//ob.elementOperations();
//ob.fewMore();
} }