0% found this document useful (0 votes)
157 views

greatest No. From Three Numbers 2

The document contains code for several Java programs that demonstrate different programming concepts like: 1) Finding the greatest of three numbers 2) Printing prime numbers up to a given number 3) Using methods to print student information 4) Overloading methods to calculate area of different shapes 5) Calculating simple interest 6) Counting characters in a string 7) Sorting an array of numbers in ascending order 8) Demonstrating the Vector class

Uploaded by

Govind Hambarde
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

greatest No. From Three Numbers 2

The document contains code for several Java programs that demonstrate different programming concepts like: 1) Finding the greatest of three numbers 2) Printing prime numbers up to a given number 3) Using methods to print student information 4) Overloading methods to calculate area of different shapes 5) Calculating simple interest 6) Counting characters in a string 7) Sorting an array of numbers in ascending order 8) Demonstrating the Vector class

Uploaded by

Govind Hambarde
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 72

//Greatest No.

from three numbers 2


import java.io.*;
import java.lang.*;
class higher
{
int a=7 ,b=10, c=4;
void display()
{
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
if(a>b && a>c)
{
System.out.println("a is greater than b & c = "+a);
}
else if(b>a && b>c)
{
System.out.println("b is greater than a & c = "+b);
}
else
{
System.out.println("c is greater than a & b = "+c);
} } }
class higherdemo
{
public static void main(String a[])
{
higher h=new higher();
h.display();
}
}
Output :
b is greater than a & c = 10
// Prime No’s upto the given N No. 2.1
import java.io.*;
import java.lang.*;
class prime
{
void display()
{
int n=5,i;
System.out.print(“Prime No’s upto N are :”);
for(i=1;i<=n;i++)
{
int flag=1,j=2;
while(j<i)
{
if(i%j==0)
{
flag=0;
break;
}
j++;
}
if(flag==1)
System.out.println(i);
}
} }
class primedemo
{
public static void main(String s[])
{
prime p=new prime();
p.display();
}
}
Output :
Prime No’s upto N are :
1,3,5
//Print Student info using appropriate methods.
import java.io.*;
import java.lang.*;
class student
{
int rollno;
String name;
int sub1,sub2;
void getdata()
{
rollno=22;
name="Ajay";
sub1=98;
sub2=99;
}
void putdata()
{
System.out.println("Student Name = "+name);
System.out.println("Student Roll No = "+rollno);
System.out.println("Sub1 Mark = "+sub1);
System.out.println("Sub2 Mark = "+sub2);
System.out.println("Total Marks = "+(sub1+sub2));
}
}
class studentdemo
{
public static void main(String a[])
{
student s=new student();
s.getdata();
s.putdata();
}
}
Output :
Student Name = Ajay
Student Roll No = 22
Sub1 Mark = 98
Sub2 Mark = 99
Total Marks = 197
// Experiment No. 4.1
import java.io.*;
class Area
{
static void area(int l,int b)
{
int a=l*b;
System.out.println("Area of rectangle="+a);
}
static void area(int s)
{
int a=s*s;
System.out.println("Area of squre="+a);
}
}
class abc
{
public static void main(String a[])
{
Area a1=new Area();
a1.area(5,6);
a1.area(5);
}
}

Output :

C:\Program Files\Java\jdk1.6.0_06\bin>javac abc.java

C:\Program Files\Java\jdk1.6.0_06\bin>java abc

Area of rectangle= 30
Area of squre= 25
//Experiment No. 4.2
import java.io.*;
import java.lang.*;
class fraction
{
float num,deno;
fraction()
{
num=1.0f;
deno=2.0f;
}
fraction(float x)
{
num=x;
deno=20.0f;
}
fraction(float y,float z)
{
num=y;
deno=z;
}
void show()
{
System.out.println("Numerator="+num);
System.out.println("Denomenator="+deno);
}
}
class fraction1
{
public static void main(String ags[])
{
fraction ob1=new fraction();
fraction ob2=new fraction(20.0f);
fraction ob3=new fraction(100.0f,200.0f);
System.out.print("First Object Constructor ");
ob1.show();
System.out.print("Second Object Constructor ");
ob2.show();
System.out.print("Third Object Constructor ");
ob3.show();
}
}

Output :

C:\Program Files\Java\jdk1.6.0_06\bin>javac fraction1.java

C:\Program Files\Java\jdk1.6.0_06\bin>java fraction1

First Object Constructor


Numerator=1.0
Denomenator=2.0
Second Object Constructor
Numerator=20.0
Denomenator=20.0
Third Object Constructor
Numerator=100.0
Denomenator=200.0
//Experiment No. 5.1
import java.io.*;
import java.lang.*;
class inter
{
public static void main(String ags[])
{
String a,b,c;
int p,n,r,sol;
DataInputStream I=new DataInputStream(System.in) ;
try
{
System.out.println("Enter the amount=");
a=I.readLine();
p=Integer.parseInt(a);
System.out.println("Enter tthe Rate of Interest=");
b=I.readLine();
r=Integer.parseInt(b);
System.out.println("Enter the year of interest=");
c=I.readLine();
n=Integer.parseInt(c);
sol=p*n*r/100;
System.out.println("Simple Interest="+sol);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output :

C:\Program Files\Java\jdk1.6.0_06\bin>javac inter.java


Note: inter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:\Program Files\Java\jdk1.6.0_06\bin>java inter


Enter the amount=
5000
Enter tthe Rate of Interest=
20
Enter the year of interest=
5
Simple Interest=5000
//Experiment No. 5.2
import java.io.*;
import java.lang.*;
class digit
{
public static void main(String ags[])
{
String name;
int len,vowel=0,tab=0,space=0,digit=0;
char ch;
BufferedReader I=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.print("Enter the string=");
name=I.readLine();
len=name.length();
for(int i=0;i<len;i++)
{
ch=name.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
vowel++;
}
if(ch=='\t')
{
tab++;
}
if(ch==' ')
{
space++;
}
if(ch>='0'&&ch<='9')
{
digit++;
}
}
System.out.println("Length of string="+len);
System.out.println("No of vowel="+vowel);
System.out.println("No of tabs="+tab);
System.out.println("No of spaces="+space);
System.out.println("No of digits="+digit);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output :

C:\Program Files\Java\jdk1.6.0_06\bin>javac digit.java

C:\Program Files\Java\jdk1.6.0_06\bin>java digit


Enter the string=gramin polytechnic Vishnupuri Nanded 431606
Length of string=44
No of vowel=11
No of tabs=2
No of spaces=3
No of digits=6
//Experiment No. 6.1

import java.io.*;

import java.lang.*;

import java.util.Scanner;

class occurence

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

String str;

String ch;

int len;

int count=0;

Scanner s=new Scanner(System.in);

System.out.print("Enter the String : ");

str=s.next();

System.out.print("Enter charater to count Occurences : ");

ch=s.next();

len=str.length();

for(int i=0;i<len;i++)

if(str.charAt(i)==ch.charAt(0))

count++;
}

System.out.println("No of Occurences = "+count);

Output :

Enter the String : infrastructure

Enter charater to count Occurences : u

No of Occurences = 2
//Experiment No. 6.2

import java.io.*;

import java.lang.*;

class password

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

String str;

String t=new String("gramin");

String app=new String("Welcome To Java!!!");

int a=0,b=0,i;

char ch;

DataInputStream ob=new DataInputStream(System.in);

try

System.out.println("Enter any password=");

str=ob.readLine();

int q=str.length();

if(str.equals(t))

System.out.println("Good");

else

System.out.println("Incorrect password");

str=str.concat(app);
System.out.println("String modified="+str);

System.out.println("Length="+q);

for(i=q-1;i>=0;i--)

ch=str.charAt(i);

System.out.print(ch);

str=str.replace('!','*');

System.out.println("String ="+str);

catch(Exception e){}

} }

Output :

Enter any password=

gramin

Good

String modified=graminWelcome To Java!!!

Length=6

nimargString =graminWelcome To Java***


//Experiment No. 7

import java.io.*;

import java.lang.*;

import java.util.Scanner;

class input

public static void main(String s[])

int i=0;

float avg;

float cal=0.0f;

float arr[]=new float[7];

Scanner a=new Scanner(System.in);

System.out.println("Enter the Value for apple sales for each day of week :");

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

arr[i]=a.nextFloat();

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

cal=arr[i]+cal;

avg=cal/7.00f;

System.out.println("Average Sale Of Week = "+avg);

}
Output:

Enter the Value for apple sales for each day of week :

10.00

10.00

10.00

10.00

10.00

10.00

10.00

Average Sale Of Week = 10.0


//Experiment No. 7.1

import java.io.*;
import java.lang.*;
import java.util.Scanner;
class input
{
float price;
int code;
input(float p,int c)
{
price=p;
code=c;
}
public void display()
{
System.out.println("\t"+price+"\t\t"+code);
}
}
class item
{
public static void main(String r[])
{
int c;
float p;
float total=0.0f;
Scanner a=new Scanner(System.in);
input ob[]=new input[5];
for(int i=0;i<5;i++)
{
System.out.print("Enter the Price & code of item :");
p=a.nextFloat();
c=a.nextInt();
ob[i]=new input(p,c);
}
System.out.println("\tPrice \t\tCode ");
for(int i=0;i<5;i++)
ob[i].display();
for(int i=0;i<5;i++)
total=ob[i].price+total;
System.out.println("Total Price Of Items="+total);
}
}
Output :
Enter the Price & code of item :125.66 800
Enter the Price & code of item :255.12 900
Enter the Price & code of item :143.24 400
Enter the Price & code of item :255.32 600
Enter the Price & code of item :180.23 555
Price Code
125.66 800
255.12 900
143.24 400
255.32 600
180.23 555
Total Price Of Items=959.57
//Experiment No. 7.3
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class ascending
{
public static void main(String s[])
{
int i,j,temp;
int arr[]=new int[10];
Scanner ob=new Scanner(System.in);
System.out.print("Enter any 10 elements :");
for(i=0;i<10;i++)
arr[i]=ob.nextInt();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
System.out.println("Elements in ascending Order :");
for(j=0;j<10;j++)
System.out.print(“\t”+arr[j]);
}
}

Output :
Enter any 10 elements :85 45 65 63 52 12 11 1 25 51
Elements in ascending Order :
1 11 12 25 45 51 52 63 65 85
//Experiment No. 8
import java.util.*;
class vectordemo1
{
public static void main(String arg[])
{
int i=0;

Vector v=new Vector();


v.addElement(new Integer(5));
v.addElement(new Integer(55));
v.addElement(new Integer(10));
v.addElement(new Integer(9));
v.addElement(new Integer(7));
v.addElement(new Float(5));
v.addElement(new Float(5));
v.addElement(new Float(5));
v.addElement(new Character('a'));
v.addElement(new Character('s'));
v.addElement("gramin");
v.addElement("Poly");
for(i=0;i<v.size();i++)
{
System.out.print("\t"+v.elementAt(i));
}
v.addElement("Avinash");
v.removeElementAt(2);
System.out.println("\n\nFirst Element : "+v.firstElement());
System.out.println("Last Element : "+v.lastElement());
System.out.println("\nList of Element : ");
for(i=0;i<v.size();i++)
{
System.out.print("\t"+v.elementAt(i));
}
}}

Output:
5 55 10 9 7 5.0 5.0 5.0 a
s gramin Poly

First Element : 5
Last Element : Avinash

List of Element :
5 55 9 7 5.0 5.0 5.0 a s
gramin Poly Avinash
//Experiment No. 8.1
import java.util.*;
class vectordemo
{
public static void main(String arg[])
{
int i=0;
Vector v=new Vector();
int length=arg.length;
for(i=0;i<length;i++)
{
v.addElement(arg[i]);
}
for(i=0;i<length;i++)
{
System.out.println(v.elementAt(i));
}}}
Output :
C:\Program Files\Java\jdk1.6.0_06\bin>java vectordemo Gramin
polytechnic vishnup
uri Nanded
Gramin
polytechnic
vishnupuri
Nanded
//Experiment No. 9
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class person
{
String name;
int age;
Scanner s=new Scanner(System.in);
void getdata()
{
System.out.print("Enter the name of person :");
name=s.next();
System.out.print("Enter the age of person :");
age=s.nextInt();
}
void putdata()
{
System.out.println("Name Of Person : "+name);
System.out.println("Age Of Person : "+age);
}
}
class employee extends person
{
float salary;
String designation;
Scanner s=new Scanner(System.in);
void get()
{ super.getdata();
System.out.print("Enter the designation of employee :");
designation=s.next();
System.out.print("Enter the salary of employee :");
salary=s.nextFloat();
}
void put()
{
super.putdata();
System.out.println("Designation Of Employee : "+designation);
System.out.println("Salary Of Employee : "+salary);
} }
class inheritance
{
public static void main(String p[])
{
employee e=new employee();
e.get();
e.put();
} }
Output:
Enter the name of person :Anuragh
Enter the age of person :23
Enter the designation of employee :General_Manager
Enter the salary of employee :87000
Name Of Person : Anuragh
Age Of Person : 23
Designation Of Employee : General_Manager
Salary Of Employee : 87000.0
//Experiment No. 9.1
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class Account
{
long acc_no;
String cust_name;
Scanner s=new Scanner(System.in);
void getinfo()
{
System.out.print("Enter the Name Of Customer :");
cust_name=s.next();
System.out.print("Enter the Account No Of Customer :");
acc_no=s.nextLong();
}
void putinfo()
{
System.out.println("Name Of Customer :"+cust_name);
System.out.println("Account No Of Customer :"+acc_no);
}
}
class Saving_Acc extends Account
{
float mini_bal;
float saving_bal;
Scanner s=new Scanner(System.in);
void getbal()
{
super.getinfo();
System.out.print("Enter Minimum Balance :");
mini_bal=s.nextFloat();
System.out.print("Enter Saving Balance :");
saving_bal=s.nextFloat();
}
void putbal()
{
super.putinfo();
System.out.println("Minimum Balance :"+mini_bal);
System.out.println("Saving Balance :"+saving_bal);
}
}
class Acc_details extends Saving_Acc
{
float deposit;
float withdrawals;
Scanner s=new Scanner(System.in);
void getdetails()
{
super.getbal();
System.out.print("Enter Deposit Balance :");
deposit=s.nextFloat();
System.out.print("Enter Withdrawal Amount :");
withdrawals=s.nextFloat();
}
void putdetails()
{
super.putbal();
System.out.println("Deposit Balance :"+deposit);
System.out.println("Withdrawal Amount :"+withdrawals);
}
}
class bank
{
public static void main(String p[])
{
Acc_details a=new Acc_details();
a.getdetails();
System.out.println("*********** Customer Details ***********");
a.putdetails();
}
}
Output :
Enter the Name Of Customer :Vishwanath
Enter the Account No Of Customer :30672086457
Enter Minimum Balance :50000
Enter Saving Balance :100000
Enter Deposit Balance :10000
Enter Withdrawal Amount :5000
*********** Customer Details ***********
Name Of Customer :Vishwanath
Account No Of Customer :30672086457
Minimum Balance :50000.0
Saving Balance :100000.0
Deposit Balance :10000.0
Withdrawal Amount :5000.0
//Experiment No. 10.1
import java.io.*;
import java.lang.*;
import java.util.Scanner;
interface Exam
{
public void percent_cal();
}
class Student
{
int roll_no;
float mark1,mark2;
Scanner s=new Scanner(System.in);
void getdata()
{
System.out.println("Enter Student Roll No :");
roll_no=s.nextInt();
System.out.println("Enter Student Marks m1,m2 : ");
mark1=s.nextFloat();
mark2=s.nextFloat();
}
}
class Result extends Student implements Exam
{
float percentage;
public void percent_cal()
{
getdata();
percentage=(mark1+mark2)/2;
}
void display()
{
System.out.println("Student Roll No = "+roll_no);
System.out.println("Percentage ="+percentage);
}
}
class interfacedemo
{
public static void main(String ss[])
{
Result r=new Result();
r.percent_cal();
r.display();
} }
Output :
Enter Student Roll No :85
Enter Student Marks m1,m2 : 98 89
Student Roll No = 85
Percentage =93.5
//Experiment No. 10.2
import java.io.*;
import java.lang.*;
import java.util.Scanner;
interface Casette
{
void accept_title();
}
interface CD
{
void accept();
}
class Media implements Casette,CD
{
Scanner s=new Scanner(System.in);
String cdtitle;
float cdprize;
String producer;
public void accept_title()
{
System.out.print("Enter the Title of CD :");
cdtitle=s.next();
}
public void accept()
{
System.out.print("Enter the Prize of CD :");
cdprize=s.nextFloat();
}
void get()
{
accept_title();
accept();
System.out.print("Enter the Name of Producer :");
producer=s.next();
}
void put()
{
System.out.println("Title of CD :"+cdtitle);
System.out.println("Prize Of CD :"+cdprize);
System.out.println("Producer Of CD :"+producer);
}
}
class cdshop
{
public static void main(String args[])
{
Media m=new Media();
m.get();
m.put();
}
}

Output :
Enter the Title of CD :Encarta
Enter the Prize of CD :800
Enter the Name of Producer :Tata

Title of CD :Encarta
Prize Of CD :800.0
Producer Of CD :Tata
//Experiment No. 11.1
import java.io.*;
import java.lang.*;
class Shape
{
float dim1=100.00f;
float dim2=200.00f;
void disp()
{
System.out.println("Dim1 = "+dim1);
System.out.println("Dim2 = "+dim2);
}
void area()
{
System.out.println("*************** Area ***************");
}
}
class Rectangle extends Shape
{
float a;
void getd()
{
super.disp();
}
void area()
{
super.area();
a=dim1*dim2;
System.out.println("Area of Rectangle = "+a);
}
}
class Triangle extends Shape
{
float b;
void getd()
{
super.disp();
}
void area()
{
super.area();
b=(dim1*dim2)/2;
System.out.println("Area of Triangle = "+b);
}
}
class overridedemo
{
public static void main(String s[])
{
Rectangle r=new Rectangle();
r.getd();
r.area();
Triangle t=new Triangle();
t.getd();
t.area();
} }

Output :
Dim1 = 100.0
Dim2 = 200.0
*************** Area ***************
Area of Rectangle = 20000.0
Dim1 = 100.0
Dim2 = 200.0
*************** Area ***************
Area of Triangle = 10000.0
//Experiment No. 11.2
import java.io.*;
import java.lang.*;
class Server
{
String serv_name="Gramin";
int serv_port=511;
void show()
{
System.out.println("Server Name = "+serv_name);
System.out.println("Server Port No. = "+serv_port);
}
}
class Client extends Server
{
String client_name="Student";
int client_port=452;
void show()
{
super.show();
System.out.println("Client Name = "+client_name);
System.out.println("Client Port No. = "+client_port);
}
}
class overridedemo1
{
public static void main(String s[])
{
Client c=new Client();
c.show();
}
}
Output :

Server Name = Gramin


Server Port No. = 511
Client Name = Student
Client Port No. = 452
//Experiment No. 12.1
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class MyException extends Exception
{
MyException(String msg)
{
super(msg);
}
}
class ExceptonTest
{
public static void main(String s[])
{
Scanner ss=new Scanner(System.in);
String a;
try
{
System.out.println("Enter your password");
a=ss.next();
String b="gramin";
if(a.equals(b))
{
throw new MyException("Congratulations !");
}
else
{
throw new MyException("Authontication Failure");
} }
catch(MyException e)
{ System.out.println(e); }
} }
Output :

Enter your password


polytechnic
MyException: Authontication Failure
//Experiment No. 12.2
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class MyException extends Exception
{
MyException(String msg)
{
super(msg);
}
}
class even
{
public static void main(String s[])
{
Scanner ss=new Scanner(System.in);
int a;
try
{
System.out.println("Enter No");
a=ss.nextInt();
if(a%2==0)
{
throw new MyException("Even No");
}
else
{
throw new MyException("Odd No");
}
}
catch(MyException e)
{System.out.println(e); }
} }
Output :

Enter No
27
MyException: Odd No
//Experiment No. 12.3
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class MyException extends Exception
{
MyException(String msg)
{
super(msg);
}
}
class charater
{
public static void main(String s[])
{
Scanner ss=new Scanner(System.in);
String a;
try
{
System.out.println("Enter your String ");
a=ss.next();
//char b='a';
int l=a.length();
for(int i=0;i<=l;i++)
{
if(a.charAt(i)=='a')
{
throw new MyException("String Contains charater 'a'");
}
else
{
throw new MyException("String doesn't contain charater 'a'");
}
}
}
catch(MyException e)
{System.out.println(e); }
}
}

Output :

Enter your String


akash
MyException: String Contains charater 'a'
//Experiment No. 13.1

import java.io.*;
import java.lang.*;
class prime extends Thread
{
public void run()
{
try
{
int i;
for(i=1;i<=10;i++)
{
if(i==2||i==3)
{
System.out.println("Prime No. ="+i);
}
else if(!((i%2==0)||(i%3==0)))
{
System.out.println("Prime No. ="+i);
Thread.sleep(500);
}
}
}
catch(Exception e)
{}
}
}
class nonprime extends Thread
{
public void run()
{
try
{
int i;
for(i=1;i<=10;i++)
{
if((i%2==0)||(i%3==0))
{
System.out.println("Non Prime No. ="+i);
Thread.sleep(500);
} } }
catch(Exception e)
{} } }
class threaddemo
{
public static void main(String s[])
{
new prime().start();
new nonprime().start();
}
}

Output :
Prime No. =1
Non Prime No. =2
Non Prime No. =3
Prime No. =2
Prime No. =3
Prime No. =5
Prime No. =7
Non Prime No. =4
Non Prime No. =6
Non Prime No. =8
Non Prime No. =9
Non Prime No. =10
//Experiment No. 13.2
import java.io.*;
import java.lang.*;
class ShareData
{
int count;
synchronized void getdata()
{
count=10;
}
synchronized void putdata()
{
System.out.println("Count ="+count);
}
}
class Synk1 extends Thread
{
ShareData a;
Thread t;
Synk1(ShareData p)
{
a=p;
t=new Thread(this);
t.start();
}
public void run()
{
a.getdata();
a.putdata();
}
}
class Synk2 extends Thread
{
ShareData b;
Thread t1;
Synk2(ShareData q)
{
b=q;
t1=new Thread(this);
t1.start();
}
public void run()
{
b.getdata();
b.putdata();
}
}
class Syncronization
{
public static void main(String s[])
{
ShareData sd=new ShareData();
Synk1 s1=new Synk1(sd);
Synk2 s2=new Synk2(sd);
}
}

Output :

Count =10
Count =10
//Experiment No. 13.3
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class Book
{
int count;
String book_name;
int book_id;
synchronized void issue(String s,int x,int y)
{
count=x;
System.out.println("Before Issuing Book Quantity is :"+count);
book_name=s;
book_id=y;
count--;
System.out.println("Book Name :"+book_name);
System.out.println("Book ID :"+book_id);
System.out.println("Now, No. Of Copies of Book :"+count);
}
}
class thread1 extends Thread
{
Book a;
Thread t;
int r,s;
String str1;
thread1(Book p,String e,int k, int l)
{
r=k;
s=l;
str1=e;
a=p;
t=new Thread(this);
t.start();
}
public void run()
{
a.issue(str1,r,s);
}
}
class thread2 extends Thread
{
Book a;
Thread t;
int r,s;
String str1;
thread2(Book p,String e,int k, int l)
{
r=k;
s=l;
str1=e;
a=p;
t=new Thread(this);
t.start();
}
public void run()
{ a.issue(str1,r,s); }
}
class SyncroDemo
{ public static void main(String s[])
{ Book bk=new Book();
thread1 t=new thread1(bk,"Networking",20,55);
thread2 t1=new thread2(bk,"Java",42,44);
}
}
Output :

Before Issuing Book Quantity is :20


Book Name :Networking
Book ID :55
Now, No. Of Copies of Book :19
Before Issuing Book Quantity is :42
Book Name :Java
Book ID :44
Now, No. Of Copies of Book :41
//Experiment No. 14.1
//User Defined Package
package box;
public class definition
{
public void disp(float a)
{
System.out.println(“Volume = ”(a*a*a));
}
}

//Implementation Of Program By using User Defined Package


import box.definition;
import java.util.Scanner;
class volume
{
public static void main(String s[])
{
definition d=new definition();
float value;
Scanner ss=new Scanner(System.in);
System.out.print("Enter the value to calculate volume of box :");
value=ss.nextFloat();
d.disp(value);
}
}

Output :
Enter the value to calculate volume of box :10 20
Volume = 1000.0
//EXPERIMENT NO:15

import java.io.*;
import java.lang.*;
import java.util.*;
class police
{
DataInputStream I=new DataInputStream(System.in);
String name,s;
int id;
double c,d,sal;
void getdata()
{ try
{
System.out.println("Enter the name and id policeman:");
name=I.readLine();
s=I.readLine();
id=Integer.parseInt(s);
}
catch(Exception e) {}
}
double calcy(double x,double y)
{
c=x;
d=y;
sal=c+d;
return sal;
}
void show()
{ try
{
System.out.println();
System.out.println("***********policeman data**************");
System.out.println("Name:"+name);
System.out.println("ID:"+id);
System.out.println("Salary:"+calcy(12.34,2345.67));
}
catch(Exception e){}
}
}

class criminal extends police


{
DataInputStream i=new DataInputStream(System.in);
String name1,s1;
int id1;
double c1,d1;
void getdata1()
{
super.getdata();
try
{
System.out.println("Enter the name and id of criminals:");
name1=i.readLine();
s1=i.readLine();
id1=Integer.parseInt(s1);
}
catch(Exception e)
{}
}
void show1()
{
super.show();
try
{
System.out.println();
System.out.println("***********CRIMINALS
DATA**************");
System.out.println("Name:"+name1);
System.out.println("ID:"+id1);
}
catch(Exception e){}
}
}
class policestation extends criminal
{
DataInputStream I=new DataInputStream(System.in);
String name,place,s;
int tot_police;
void get3()
{
super.getdata1();
System.out.println("ENTER POLICE STATION NAME,PLACE AND
TOTAL POLICES: ");
try
{name=I.readLine();
place=I.readLine();
s=I.readLine();
tot_police=Integer.parseInt(s);
}
catch(Exception e ){}
}
void put3()
{
super.show1();
try
{
System.out.println("NAME OF POLICE STATION:"+name);
System.out.println("PLACE:"+place);
System.out.println("TOTAL NUMBER OF POLICE :"+tot_police);
}
catch(Exception e){}
}
}
class Expt15
{
public static void main(String args[])
{
policestation ob=new policestation();
ob.get3();
ob.put3();
}
}

OUTPUT
Enter the name and id policeman:
ARYA
786
Enter the name and id of criminals:
ALI_MOHOMMAD
9283
ENTER POLICE STATION NAME,PLACE AND TOTAL POLICES:
SHIVAJI_NAGAR_POLICE_STATION
NANDED
800

***********policeman data**************
Name:ARYA
ID:786
Salary:2358.01

***********CRIMINALS DATA**************
Name:ALI_MOHOMMAD
ID:9283
NAME OF POLICE STATION:SHIVAJI_NAGAR_POLICE_STATION
PLACE:NANDED
TOTAL NUMBER OF POLICE :800
//Experiment No:16
import java.io.*;
import java.lang.*;
class company
{
DataInputStream I=new DataInputStream(System.in);
String name,owner,i;
Double income;
void getdata()
{
try
{
System.out.println("Enter the name of company,owner and annual
income:");
name=I.readLine();
owner=I.readLine();
i=I.readLine();
income=Double.parseDouble(i);
}
catch(Exception e)
{}
}
void show()
{
try
{
System.out.println("Company:"+name);
System.out.println("owner:"+owner);
System.out.println("Income:"+income);
}
catch(Exception e){}
}
}
class emp extends company
{
DataInputStream i=new DataInputStream(System.in);
String name1,a,b;
int id;
double sal;
void getdata()
{
try
{
System.out.println("Enter the name ,id and salary of employee:");
name1=i.readLine();
a=i.readLine();
b=i.readLine();
id=Integer.parseInt(a);
sal=Double.parseDouble(b);
}
catch(Exception e){}
}
void show()
{
try
{
System.out.println("Name:"+name1);
System.out.println("ID:"+id);
System.out.println("Salary:"+sal);
}
catch(Exception e){}
}
}
class exp16
{
public static void main(String args[])
{
company ob1=new company();
company ref; //Super class reference
emp ob2=new emp();
ref=ob1;
ref.getdata();

ref=ob2;
ref.getdata();

ref=ob1;
ref.show();

ref=ob2;
ref.show();

}
}

Output:
Enter the name of company,owner and annual income:
Microsoft Corporation
Bill Gets
25000000
Enter the name ,id and salary of employee:
Amol Eklare
309
700000
Company:Microsoft Corporation
owner:Bill Gets
Income:2.5E7
Name:Amol Eklare
ID:309
Salary:700000.0
//Experiment no:17
import java.io.*;
import java.lang.*;
interface performance
{
final String perfm="BEST";
}
interface sports extends performance
{
final String branch="Computer Engineering";
final int spm=95;
void getdata();
void putdata();
}
class student implements sports
{
int m1,m2;
String s1,s2,name;
DataInputStream I=new DataInputStream(System.in);
public void getdata()
{
try
{
System.out.println("ENTER THE NAME , MARKS1 AND
MARKS2: ");
name=I.readLine();
s1=I.readLine();
m1=Integer.parseInt(s1);
s2=I.readLine();
m2=Integer.parseInt(s2);
}
catch(Exception e)
{}
}
public void putdata()
{
try
{
System.out.println("NAME : "+name);
System.out.println("BRANCH : "+branch);
System.out.println("MARKS1 : "+m1);
System.out.println("MARKS2 : "+m2);
System.out.println("PERFORMANCE : "+perfm);
}
catch(Exception e){}
}
}

class exp17
{
public static void main(String args[])
{
student ob=new student();
ob.getdata();
ob.putdata();

}
}
Output:
ENTER THE NAME , MARKS1 AND MARKS2:
PRITHVIRAJ CHAVAN
100
100
NAME : PRITHVIRAJ CHAVAN
BRANCH : Computer Engineering
MARKS1 : 100
MARKS2 : 100
PERFORMANCE : BEST
*/
//Experiment No:18

//package p1
//class student
package p1;
import java.io.*;
import java.lang.*;

class teacher
{
DataInputStream I11=new DataInputStream(System.in);
private int id;
public String name1,c1,c2;
protected double age;
void getdata11()
{
try
{
System.out.println("ENTER THE TEACHER'S DATA.");
System.out.println("ENTER THE ID , NAME AND AGE:");
c1=I11.readLine();
id=Integer.parseInt(c1);
name1=I11.readLine();
c2=I11.readLine();
age=Double.parseDouble(c2);
}
catch(Exception e){}
}
void putdata11()
{
try
{
System.out.println("THE TEACHER'S DATA.");
System.out.println("NAME: "+name1);
System.out.println("ID: "+id);
System.out.println("AGE: "+age);
}
catch(Exception e){}
}
}
public class student extends teacher
{
DataInputStream I1=new DataInputStream(System.in);
private int rollno;
public String name,s1,s2;
protected double perct;
void getdata1()
{
try
{
super.getdata11();
System.out.println("ENTER THE STUDENT'S DATA.");
System.out.println("ENTER THE ROLLNO NAME AND
PERCENTAGE:");
s1=I1.readLine();
rollno=Integer.parseInt(s1);
name=I1.readLine();
s2=I1.readLine();
perct=Double.parseDouble(s2);
}
catch(Exception e){}
}
void putdata1()
{
super.putdata11();
try
{
System.out.println("THE STUDENT'S DATA.");
System.out.println("NAME: "+name);
System.out.println("ROL NO: "+rollno);
System.out.println("PERCENTAGE: "+perct);
}
catch(Exception e){}
}
}//END OF CLASS STUDENT IN PACKAGE P1

//package p1 => class -principal


package p1;
import java.io.*;
import java.lang.*;
import p1.student.*;

public class principal extends student


{
student ob=new student();
DataInputStream I2=new DataInputStream(System.in);
private String qualification;
public String name2,c2;
protected double age2;
public void getdata2()
{
ob.getdata1();

try
{
System.out.println("ENTER PRINCIPAL'S DATA. ");
System.out.println("ENTER THE PRINCIPAL'S DATA");
System.out.println("ENTER THE NAME QUALIFICATION AND
AGE:");
name2=I2.readLine();
qualification=I2.readLine();
c2=I2.readLine();
age2=Double.parseDouble(c2);
}
catch(Exception e){}
}
public void putdata2()
{
ob.putdata1();
try
{
System.out.println("PRINCIPAL'S DATA. ");
System.out.println("NAME: "+name2);
System.out.println("QUALIFICATION: "+qualification);
System.out.println("AGE: "+age2);
}
catch(Exception e){}
}
} //END OF CLASS PRINCIPAL IN PACKAGE P1
//END OF PACKAGE P1

//package p2=> class board


package p2;
import java.io.*;
import java.lang.*;
import p1.principal;

class college
{
principal ob2=new principal();
DataInputStream I3=new DataInputStream(System.in);
private int id3;
public String name3,c3;
protected String place;
void getdata3()
{
try
{
ob2.getdata2();
System.out.println("ENTER THE COLLEGE DATA.");
System.out.println("ENTER THE ID , NAME AND PLACE:");
c3=I3.readLine();
id3=Integer.parseInt(c3);
name3=I3.readLine();
place=I3.readLine();
}
catch(Exception e){}
}
void putdata3()
{
try
{
ob2.putdata2();
System.out.println(" THE COLLEGE DATA.");
System.out.println("NAME: "+name3);
System.out.println("ID: "+id3);
System.out.println("PLACE: "+place);
}
catch(Exception e){}
}
}
public class board extends college
{ DataInputStream I33=new DataInputStream(System.in);
String bdname,place3;
public void getdata33()
{ try
{
super.getdata3();
System.out.println("ENTER THE BOARD'S DATA.");
System.out.println("ENTER THE BOARD NAME AND PLACE");
bdname=I33.readLine();
place3=I33.readLine();
}
catch(Exception e){}
}
public void putdata33()
{ try
{ super.putdata3();
System.out.println("THE COLLEGE DATA.");
System.out.println("THE BOARD NAME:"+bdname);
System.out.println("PLACE:"+place3);
}
catch(Exception e){}
}

}//END OF CLASS STUDENT IN PACKAGE P2

//importing above packages in main program


import java.io.*;
import java.lang.*;
import p2.board;

class exp18
{
public static void main(String args[])
{
board obb=new board();
obb.getdata33();
obb.putdata33();
}
}
Output:
ENTER THE TEACHER'S DATA.
ENTER THE ID , NAME AND AGE:
123
PRAMOD MASKE
23
ENTER THE STUDENT'S DATA.
ENTER THE ROLLNO NAME AND PERCENTAGE:
309
AMOL EKLARE
78.98
ENTER PRINCIPAL'S DATA.
ENTER THE PRINCIPAL'S DATA
ENTER THE NAME QUALIFICATION AND AGE:
VIJAY PAWAR
M.E. P.H.D.
35
ENTER THE COLLEGE DATA.
ENTER THE ID , NAME AND PLACE:
1069
GRAMIN POLYTECHNIC
NANDED
ENTER THE BOARD'S DATA.
ENTER THE BOARD NAME AND PLACE
M.S.B.T.E.
MUMBAI
THE TEACHER'S DATA.
NAME: PRAMOD MASKE
ID: 123
AGE: 23.0
THE STUDENT'S DATA.
NAME: AMOL EKLARE
ROL NO: 309
PERCENTAGE: 78.98
PRINCIPAL'S DATA.
NAME: VIJAY PAWAR
QUALIFICATION: M.E. P.H.D.
AGE: 35.0
THE COLLEGE DATA.
NAME: GRAMIN POLYTECHNIC
ID: 1069
PLACE: NANDED
THE COLLEGE DATA.
THE BOARD NAME:M.S.B.T.E.
PLACE:MUMBAI

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy