Showing posts with label java code. Show all posts
Showing posts with label java code. Show all posts

Sunday, 30 March 2014

JAVA PROGRAMS-Bank Transaction

Program Name:- Bank Transaction

import java.io.*;
class bankacc
{
int withdraw,deposite,amt;
int accbal;
static String accname;
static int accno;
public void withdraw()throws IOException
{
DataInputStream inp=new DataInputStream(System.in);
System.out.println("enter the amount for withdraw");
amt=Integer.parseInt(inp.readLine());
if(accbal<amt)
{
System.out.println("You can't withdraw amount");
}
else
{
accbal=accbal-amt;
}
}
public void deposite()throws IOException
{
DataInputStream inp=new DataInputStream(System.in);
System.out.println("enter the amount for deposite");
amt=Integer.parseInt(inp.readLine());
accbal=accbal+amt;
}
public void disp()
{
System.out.println("account name\t:"+accname);
System.out.println("\naccount number\t:"+accno);
System.out.println("\nbalance\t:"+accbal);
}
public static void main(String args[])throws IOException
{
DataInputStream inp=new DataInputStream(System.in);
bankacc bd=new bankacc();
System.out.println("enter the accno:");
accno=Integer.parseInt(inp.readLine());
System.out.println("enter the accname");
accname=inp.readLine();
int c=0,ch;
while(c==0)
{
System.out.println("1.deposite\n");
System.out.println("2.withdraw\n");
System.out.println("3.display");
System.out.println("\n 4.enter your choice\n");
ch=Integer.parseInt(inp.readLine());
if(ch==1)
bd.deposite();
else if(ch==2)
bd.withdraw();
else
bd.disp();
System.out.println("do you want continue enter the 0");
c=Integer.parseInt(inp.readLine());
}
}
}


OUTPUT;-


Compile:-

c:\javaprograms>javac banckacc.java


RUN:-


c:\javaprograms>java bankacc


Enter the account number:

1

Enter the account name:

Ajith

1.Deposit

2.Withdraw

3.Display

Enter your choice:

1

Enter the amount to deposite:

500

Do you want to continue:

0

1.Deposit

2.Withdraw

3.Display

Enter your choice:

3

Account Name:Ajith

Account Number:1

Balance:500

Do you want to continue:

0


1.Deposit

2.Withdraw

3.Display

Enter your choice:

2

Enter the amount of withdraw:

260

Do you want to continue:

0


1.Deposit

2.Withdraw

3.Display

Enter your choice:

3


Account Name:Ajith

Account number:1

Balance:240


Do you want to continue:

1

Java Programs - Alphabetical order of the given Name

 Alphabetical order of the given Name


Program Name:-    alpha.java


import java.io.*;
import java.lang.*;
class alpha
{
public static void main(String args[])throws IOException
 {
 String a[]=new String[10];
 String b;
 int n;
 DataInputStream in=new DataInputStream(System.in);
 System.out.print("\nEnter the Number of name  :");
 n=Integer.parseInt(in.readLine());
 for(int i=0;i<n;i++)
  {
  a[i]=in.readLine();
  }
  for(int i=0;i<n;i++)
  {
  for(int j=i+1;j<n;j++)
   {
    if(a[i].compareTo(a[j])<0)
    {
    b=a[i];
    a[i]=a[j];
    a[j]=b;
    }
   }
  }
 System.out.println("\n Alphabetical order of name is:");
 for(int i=0;i<n;i++)
 {
 System.out.println(a[i]);
 }
 }
}

JAVA PROGRAMS-Dispatch Program In Java

Dispatch Program In Java

Program Name:- dispatch.java

import java.io.*;
class a
{
void callme()
 {
 System.out.println("\nInside A's callme method");
 }
}
class b extends a
{
 void callme()
 {
 System.out.println("\nInside B's callme method");
 }
}
class c extends b
{
 void callme()
 {
 System.out.println("\nInside C's callme method");
 }
}
class dispatch
{
public static void main(String args[])
 {
 a obj=new a();
 b obj1=new b();
 c obj2=new c();
 a r;
 r=obj;
 obj.callme();
 r=obj1;
 obj1.callme();
 r=obj2;
 obj2.callme();
 }
}

JAVA PROGRAMS-Matrix Program in Java

Matrix Program in Java

  Program Name:- matrix.java 

import java.io.*;

class matrix

{

public static void main(String args[])throws IOException

{

 DataInputStream in=new DataInputStream(System.in);

 int i,j,m,n,k;

 int a[][]=new int[10][10];

 int b[][]=new int[10][10];

 int c[][]=new int[10][10];

 int d[][]=new int[10][10];

 System.out.print("\n Enter the row and column\n\n");

 m=Integer.parseInt(in.readLine());

 n=Integer.parseInt(in.readLine());

 System.out.print("\n Enter the element of matrix A\n\n");

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 a[i][j]=Integer.parseInt(in.readLine());

 }

 }

 System.out.print("\n Enter the element of matrix B\n\n");

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 b[i][j]=Integer.parseInt(in.readLine());

 }

 }

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 for(k=0;k<m;k++)

 {

 c[i][j]=c[i][j]+a[i][k]*b[k][j];

 }

 }

 }

 System.out.print("\n A matrix\n");

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 System.out.print(a[i][j]+"\t");

 }

 System.out.println();

 }

 System.out.print("\n B matrix\n");

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 System.out.print(b[i][j]+"\t");

 }

 System.out.println();

 }

 System.out.print("\n Multipul matrix\n");

 for(i=0;i<m;i++)

 {

 for(j=0;j<n;j++)

 {

 System.out.print(c[i][j]+"\t");

 }

 System.out.println();

 }

 }

}


JAVA PROGRAMS-Method In Java Program

Method In Java Program

Program Name:- method.java


import java.io.*;

class circle

{

double radius;

final double pi=3.14;

circle(double r)

 {

 radius=r;

 }

double area()

 {

 return pi*radius*radius;

 }

double circum()

 {

 return 2*pi*radius;

 }

}

class cylinder extends circle

{

double hight;

cylinder(double r,double h)

 {

 super(r);

 hight=h;

 }

double area()

 {

 return circum()*hight;

 }

double volume()

 {

 return pi*radius*hight;

 }

}

class method

{

public static void main(String args[])

 {

 double area,area1,sectionarea,surfacearea,volume;

 circle cir=new circle(5.5);

 cylinder cy=new cylinder(3.2,12.5);

 area=cir.area();

 area1=cir.circum();

 System.out.println("\nArea of the circle of radius "+cir.radius+"\t:"+area);

 System.out.println("\nCircum ference of a circle\t:"+area1);

 System.out.println("\nCalculation for cylinder of radius "+cy.radius+" and height  "+cy.hight);

 surfacearea=cy.area();

 volume=cy.volume();

 System.out.println("\nSurface area\t"+surfacearea);

 System.out.println("\nVolume    \t"+volume);

 }

}

JAVA PROGRAMS-Student Details Program in Java

Student Details Program in Java

Program Name:- student1.java

import java.io.*;

class studentdetail

{

int sno;

String sname,major,yos;

 void getdata()throws IOException

 {

 DataInputStream in=new DataInputStream(System.in);

 System.out.print("\n Enter the student number\t:");

 sno=Integer.parseInt(in.readLine());

 System.out.print("\n Enter the student name\t:");

 sname=in.readLine();

 System.out.print("\n Enter the student Major\t:");

 major=in.readLine();

 System.out.print("\n Enter the year of student\t:");

 yos=in.readLine();

 }

}

class markdetails extends studentdetail

{

int m1,m2,m3,m4,tot;

String res;

void read()throws IOException

 {

 DataInputStream in=new DataInputStream(System.in);

 getdata();

 System.out.print("\n Enter the mark1\t:");

 m1=Integer.parseInt(in.readLine());

 System.out.print("\n Enter the mark2\t:");

 m2=Integer.parseInt(in.readLine());

 System.out.print("\n Enter the mark3\t:");

 m3=Integer.parseInt(in.readLine());

 System.out.print("\n Enter the mark4\t:");

 m4=Integer.parseInt(in.readLine());

 }

void total()

 {

 tot=m1+m2+m3+m4;

 }

 void result()

 {

 if((m1>=50)&&(m2>=50)&&(m3>=50)&&(m4>=50))

 res="Pass";

 else

 res="Fail";

 }

 void display()

 {

 System.out.println("\n\n \t Student details \n\n");

 System.out.println("\n Student number\t:"+sno);

 System.out.println("\n Student name\t:"+sname);

 System.out.println("\n Student major\t:"+major);

 System.out.println("\n Year of Study\t:"+yos);

 System.out.print("\n mark1: \t"+m1+"\n\n mark2: \t"+m2+"\n\n mark3: \t"+m3+"\n\n mark4: \t"+m4);

 System.out.print("\n\n Total: \t"+tot+"\n\n Result: "+res);

 }

}

class student1

{

public static void main(String[]args)throws IOException

{

markdetails in=new markdetails();

in.read();

in.total();

in.result();

in.display();

}

}

JAVA PROGRAMS-For,While,Do-While,Ternary Loops programs in Java

For,While,Do-While,Ternary Loops programs in Java

Program Name:- simplepgm2

import java.io.*;

class simplepgm

{

void for_fun()

{

System.out.println("Enter the value ");

for(int i=1;i<=5;i++)

{

for(int j=1;j<=i;j++)

{

System.out.println(""+j);

}

System.out.println("\n");

}

}

void while_fun()

{

int a=0,b=1,c=1;

System.out.println("Fibonacci series");

System.out.println(a+"\n"+b+"\n");

while(c<=0)

{

int f=a+b;

System.out.println(f+"\n");

c+=1;

a=b;

b=f;

}

}

 void dowhile_fun()

 {

 int sum=0,i=1;

 do

{

sum=sum+i;

i+=1;

}

while(i<=10);

System.out.println("sum="+sum);

}

void ternary_fun()

{

int a=10,b=15,c=5;

int x=(a>b&&a>c)?a:(b>c)?b:c;

System.out.println(x+" is big");

}

}

class simplepgm2

{

public static void main(String arg[])throws IOException

{

char choice;

simplepgm obj=new simplepgm();

do

{

System.out.println("\n 1.For funtion");

System.out.println("\n 2.While funtion");

System.out.println("\n 3.do while funtion");

System.out.println("\n 4.Ternary funtion");

choice=(char)System.in.read();

}while(choice<'1'||choice>'8');

switch(choice)

{

case '1':

obj.for_fun();

break;

case '2':

obj.while_fun();

break;

case '3':

obj.dowhile_fun();

break;

case '4':

obj.ternary_fun();

break;

default:

System.out.println("not current choice");

}

}

}


JAVA PROGRAMS-Hierarchical Inheritance in Java

Hierarchical Inheritance in Java

Program Name:- hiear.java

import java.io.*;
class vehicle
{
String regno;
int model;
 vehicle(String r,int m)
 {
 regno=r;
 model=m;
 }
 void display2()
 {
 System.out.print("\nRegistration number\t:"+regno);
 System.out.print("\nModel\t\t\t:"+model);
 }
}
class roadvehicle extends vehicle
{
int noof;
 roadvehicle(String r,int m,int n)
 {
 super(r,m);
 noof=n;
 }
 void display()
 {
 System.out.print("\n\n\t Road Vehicle\n\n");
 super.display2();
 System.out.print("\nNumber of wheel\t:"+noof);
 }
}
class watervehicle extends vehicle
{
int nn;
 watervehicle(String s,int m,int n)
 {
 super(s,m);
 nn=n;
 }
 void display1()
 {
 System.out.print("\n\n\t Water Vehicle\n\n");
 super.display2();
 System.out.print("\nNumber of leaf\t:"+nn);
 }
}
public class hiear
{
 public static void main(String[]args)
 {
 roadvehicle r;
 watervehicle w;
 r=new roadvehicle("TN 58 s 5482",2011,2);
 w=new watervehicle("TN  57 A 5828",2011,10);
 r.display();
 w.display1();
 }
}

JAVA PROGRAMS-Multi Level Inheritance in Java

Multi Level Inheritance in Java

Program Name:- multi.java

import java.io.*;

class box1

{

int length,width,height;

box1()

 {

 length=0;

 width=0;

 height=0;

 }

box1(int l)

 {

 length=width=height=l;

 }

box1(int l,int w,int h)

 {

 length=l;

 width=w;

 height=h;

 }

int volume()

 {

 int v;

 v=length*width*height;

 return(v);

 }

}

class boxweight extends box1

{

double weight;

boxweight()

 {

 super();

 weight=0;

 }

boxweight(int l,double m)

 {

 super(l);

 weight=m;

 }

boxweight(int l,int w,int h,double m)

 {

 super(l,w,h);

 weight=m;

 }

}

class shipping extends boxweight

{

double cost;

shipping()

 {

 super();

 cost=0;

 }

shipping(int l,double m,double c)

 {

 super(l,m);

 cost=c;

 }

shipping(int l,int h,int w,double m,double c)

 {

 super(l,w,h,m);

 cost=c;

 }

}

class multi

{

public static void main(String args[])

{

shipping s1=new shipping(10,5,7,100.1,150.2);

shipping s2=new shipping(5,2,10,20.0,115.50);

double vol1,vol2;

vol1=s1.volume();

vol2=s2.volume();

System.out.println("\n\t Shipping list");

System.out.print("\n\n Volume weight cost");

System.out.print("\n"+vol1+" "+s1.weight+"rs\t"+s1.cost);

System.out.print("\n"+vol2+" "+s2.weight+"rs\t"+s2.cost);

 }

}