Errors
. ..Error Makes Experience.. .
Sunday, 30 March 2014
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-Interface Demo program in java
Interface Demo program in java
Program Name:- inter1
import java.io.*;
interface demo
{
final double pi=3.14;
abstract double area(int r);
}
interface demo1
{
abstract double circum(int r);
}
class cir implements demo,demo1
{
public double area(int r)
{
return pi*r*r;
}
public double circum(int a)
{
return 2*pi*a*a;
}
}
class inter1
{
public static void main(String arg[])
{
cir c=new cir();
System.out.print("\nCircle\t:"+c.area(5));
System.out.print("\nCircum\t:"+c.circum(5));
}
}
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-Stack Program In Java
Stack Program In Java
Program Name:- stackdemo.java
import java.io.*;
class stack
{
int s[]=new int[100];
int top;
void stack()
{
top=0;
System.out.println("\n The stack is empty");
}
public void push()throws IOException
{
DataInputStream inp=new DataInputStream(System.in);
int x;
if(top==100)
{
System.out.println("The Stack is full");
}
else
{
System.out.print("\n Enter the value :");
x=Integer.parseInt(inp.readLine());
s[top]=x;
top++;
System.out.println("\n The value is pushed");
}
}
public void pop()throws IOException
{
DataInputStream inp=new DataInputStream(System.in);
int y;
if(top==0)
{
System.out.println("\n The stack is empty");
}
else
{
top--;
y=s[top];
s[top]='\0';
System.out.println("\n The value is poped");
}
}
void display()
{
int i;
if(top==0)
{
System.out.println("\nThe stack is empty");
}
else
{
System.out.println("\nValues are top-->");
}
for(i=top-1;i>=0;i--)
System.out.println(s[i]);
}
}
public class stackdemo
{
public static void main(String args[])throws IOException
{
stack in=new stack();
int item=0;
int opt=1;
String s=new String();
while(opt<4)
{
System.out.println("\n\n\t\t Main menu\n\n1.push\n\n2.Pop\n\n3.Display\n\n4.Exit\n\nSelection the option");
DataInputStream din=new DataInputStream(System.in);
s=din.readLine();
opt=Integer.parseInt(s);
switch(opt)
{
case 1:
System.out.println("\nEnter the elementis add");
in.push();
break;
case 2:
System.out.println("\nEnter the delete item");
in.pop();
break;
case 3:
System.out.println("\nThe stack element is:");
in.display();
break;
default:
opt=4;
}
}
}
}
JAVA PROGRAMS-Java Program using Super key
Java Program using Super key
Program Name:- superkey.java
class rectangle
{
int length,breadth;
rectangle(int l,int m)
{
length=l;
breadth=m;
}
int area()
{
int a;
a=length*breadth;
return(a);
}
}
class box extends rectangle
{
int height;
box(int l,int b,int h)
{
super(l,b);
height=h;
}
int volume()
{
int v;
v=length*breadth*height;
return(v);
}
}
class superkey
{
public static void main(String args[])
{
box in=new box(10,10,10);
int a,v;
a=in.area();
v=in.volume();
System.out.print("\nArea\t:"+a);
System.out.print(" \nVolume\t:"+v);
}
}
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();
}
}
Subscribe to:
Comments (Atom)