Java Assignment
Java Assignment
1. Simplify fraction 2
3. Smith number 6
4. Keith number 8
7. DEQueue implementation 17
8. Employee - manager 22
9. Worker - wages 25
1
1. Create a java class that stores original num. and den. of a fraction. Then simplifies it to find num. and
den. Of simplified fraction. The class should have following details.
import java.io.*;
class RationalClass
{
int num, den, nr, dr, hcf;
RationalClass(int x, int y)
{
num=x;
den=y;
}
int gcd(int a, int b)
{
while(a!=b)
{
if(a<b)
b=b-a;
else if(b<a)
a=a-b;
}
return a;
}
void simplify()
{
hcf=gcd(num, den);
num=num/hcf;
den=den/hcf;
System.out.println("The simplified fraction is "+num+"/"+den+".");
}
class ex1
{
public static void main(String[] ars) throws IOException
{
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the numerator:");
int x = Integer.parseInt(br.readLine());
System.out.println("Enter the denominator:");
int y = Integer.parseInt(br.readLine());
RationalClass simp = new RationalClass(x, y);
simp.simplify();
}
catch(IOException e)
2
{}
}
}
Output:
F:\Milind\Java>java ex1
Enter the numerator:
12
Enter the denominator:
14
The simplified fraction is 6/7.
3
2. A class TelCall calculates the monthly phone bill of a consumer. Some of the members of the class are
given below.
Class name-
TelCall
Data member-
Phno- Phone no.
Name- name of the consumer
N- no. of calls made
Amt- bill amount
Methods-
Void compute()- to calculate the phone bill amount based on the slabs given below.
No. of calls Rate (Rs.)
1-100 500/- :: Rental
101-200 Rs. 1/call + Rental
201-300 Rs 1.20/call + Rental
above 300 Rs. 1.50/call + Rental
[the calculations need to be done as per the slabs]
Void dispdata()- to display the details in specified format.
constructor- to assign values to data members.
Specify the class TelCall giving the details of the constructor, void compute() and void dispdata().
In the main function, create an object of type TelCall and display the phone bill in the following format:
Phone no. Name Total calls Amount
xxxxxxxxxx xx xx xxx
import java.io.*;
class TelCall
{
int N;
String Name, Phno;
float Amt;
TelCall(String ph, int call, String na)
{
ph=Phno;
N=call;
Name=na;
}
float compute()
{
float tot, Rent=500;
if(N<=100)
tot=Rent;
else if(N<=200)
tot=(float) N+Rent;
else if(N<=300)
tot=(float) (1.2*N)+Rent;
else
4
tot=(float) (1.5*N)+Rent;
return tot;
}
void display()
{
Amt=compute();
System.out.println("The total payable amount is : "+Amt+".");
}
class ex2
{
public static void main(String[] ars) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Name:");
String name = br.readLine();
System.out.println("Enter the phone number :");
String phone = br.readLine();
System.out.println("Enter the number of calls :");
int calls = Integer.parseInt(br.readLine());
TelCall comp = new TelCall(phone, calls, name);
comp.display();
}
}
Output:
F:\Milind\Java>java ex2
Enter the Name:
Milind Chakraborty
Enter the phone number :
7568466303
Enter the number of calls :
223
The total payable amount is : 767.6.
5
3. Write a program to check whether a no. is Smith no. or not.
import java.util.*;
class Smith
{
static int num;
public static void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number:");
num=sc.nextInt();
}
public static int primeCheck(int key)
{
for(int i=2;i<=key/2;i++)
{
if(key%i==0)
return 0;
}
return 1;
}
public static int digSum(int key)
{
int s=0;
do{
s=s+key%10;
key=key/10;
}while(key>0);
return s;
}
6
return sum;
}
public static void disp()
{
if(digSum(num)==factsum())
System.out.println(num+" is a Smith number");
else
System.out.println(num+" is not a Smith number");
}
/*Output:
Enter number:
666
666 is a Smith number
Enter number:
999
999 is not a Smith number
*/
7
4. Write a program to check whether a no. is keith no. or not.
import java.util.*;
class Keith
{
static int num;
public static void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number:");
num=sc.nextInt();
}
public static int digCount()
{
int key=num,n=0;
do{
n++;
key/=10;
}while(key>0);
return n;
}
public static int check()
{
int d=digCount();
int ar[]=new int[d];
int key=num,j=d-1,sum=0;
do{
ar[j]=key%10;
key/=10;
sum=sum+ar[j];
j--;
}while(key>0);
j=0;
int temp;
do{
temp=sum*2-ar[j];
ar[j]=sum;
j++;
sum=temp;
if(j==3)
j=0;
}while(sum<num);
if(sum==num)
return 1;
else
return 0;
8
}
public static void view()
{
if(check()==1)
System.out.println(num+" is a Keith no.");
else
System.out.println(num+" is not a Keith no.");
}
/*Output:
Enter number:
197
197 is a Keith no.
Enter number:
208
208 is not a Keith no.
*/
9
5. Complex no. operations.
import java.util.Scanner;
class complex
{
float r1,i1,r2,i2,r3,i3;
complex(float a,float b,float c,float d)
{
r1=a;
i1=b;
r2=c;
i2=d;
}
void add()
{
r3=r1+r2;
i3=i1+i2;
}
void sub()
{
r3=r1-r2;
i3=i1-i2;
}
void mult()
{
r3=(r1*r2)-(i1*i2);
i3=(r1*i2)+(r2*i1);
}
void div()
{
if(r2==0 && i2==0)
{
System.out.println("denominator cannot be zero");
System.exit(1);
}
else
{
r3=(((r1*r2)-(i1*(-i2)))/((r2*r2)+(i2*i2)));
i3=(((r1*(-i2))+(i1*r2))/((r2*r2)+(i2*i2)));
}
}
void disp()
{
System.out.println("Solution:");
if(i3<0)
System.out.println(r3+"-"+(-i3)+"i");
else
10
System.out.println(r3+"+"+i3+"i");
}
}
class ex5
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
float p,q,r,s;
System.out.println("Real part of first complex number :");
p=sc.nextFloat();
System.out.println("Imaginary part of first complex number :");
q=sc.nextFloat();
System.out.println("Real part of second complex number :");
r=sc.nextFloat();
System.out.println("Imaginary part of second complex number :");
s=sc.nextFloat();
complex ob = new complex(p,q,r,s);
System.out.println("Choose among the following");
System.out.println("1.Addition");
System.out.println("2.Subtraction 2nd number from 1st number");
System.out.println("3.Multiplication");
System.out.println("4.Division 1st number by 2nd number");
int ch=sc.nextInt();
if(ch==1)
{
ob.add();
}
else if(ch==2)
{
ob.sub();
}
else if(ch==3)
{
ob.mult();
}
else if(ch==4)
{
ob.div();
}
else
{
System.out.println("incorrect input");
}
ob.disp();
}
11
}
Output:
F:\Milind\Java>java ex5
Real part of first complex number :
3
Imaginary part of first complex number :
-4
Real part of second complex number :
5
Imaginary part of second complex number :
-9
Choose among the following
1.Addition
2.Subtraction 2nd number from 1st number
3.Multiplication
4.Division 1st number by 2nd number
3
Solution:
-21.0-47.0i
F:\Milind\Java>java ex5
Real part of first complex number :
3
Imaginary part of first complex number :
-4
Real part of second complex number :
5
Imaginary part of second complex number :
-9
Choose among the following
1.Addition
2.Subtraction 2nd number from 1st number
3.Multiplication
4.Division 1st number by 2nd number
1
Solution:
8.0-13.0i
F:\Milind\Java>java ex5
Real part of first complex number :
3
Imaginary part of first complex number :
-4
Real part of second complex number :
5
12
Imaginary part of second complex number :
-9
Choose among the following
1.Addition
2.Subtraction 2nd number from 1st number
3.Multiplication
4.Division 1st number by 2nd number
2
Solution:
-2.0+5.0i
F:\Milind\Java>java ex5
Real part of first complex number :
3
Imaginary part of first complex number :
-4
Real part of second complex number :
5
Imaginary part of second complex number :
-9
Choose among the following
1.Addition
2.Subtraction 2nd number from 1st number
3.Multiplication
4.Division 1st number by 2nd number
4
Solution:
0.4811321+0.06603774i
13
6. A class sort contains any array of 50 integers. Some of the member fns or data members are given below
Class name-
Sort
Data member-
arr[]- integers
item- no. to be searched in the array
Member methods-
void inputdata()- to i/p 50 integers(no duplicate no.s are to be entered)
void bubblesort()- to sort the array in ascending order using the bubble sort technique and to display the sorted
list
void binarysearch()- to i/p item and search for it using the binary search technique. If found print the item
searched and its position in the sorted list. Otherwise print an appropriate message.
Write a main function to perform the following operation details.
import java.util.Scanner;
class Sort
{
void bubblesort()
{
int i,temp,j;
for(i=1;i<=n;i++)
{
for(j=0;j<=n-i-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
14
System.out.println("Sorted array :-");
for(j=0;j<n;j++)
System.out.print(arr[j]+" ");
}
class ex6
{
public static void main(String ar[])
{
Sort ob=new Sort();
Scanner scan=new Scanner(System.in);
try{
ob.inputdata();
ob.bubblesort();
System.out.println("Enter the item to search :");
int num=scan.nextInt();
ob.binarysearch(num);
}
catch(Exception e)
{
System.out.println("No. of elements cannot be more than 50");
}
}
15
}
Output:
F:\Milind\Java>java ex6
Number of elements(max 50)
6
22
34
2
1
54
10
Sorted array :-
1 2 10 22 34 54 Enter the item to search :
10
10 is present in 3 index
16
7. Chain is an entity which can hold atmost 50 integers. The chain enables the user to add and remove
integers from both the ends I.e. front and rear. Define a class chain with the following details.
Class name-
Chain
Data member-
ele[]- the array to hold the integer elements.
cap- stores the maximum capacity of the array
front- to point the index of the front
rear- to point the index of the rear
Member methods-
Chain(int max)- constructor to initialize the data cap=max,
front=-1,rear=-1 and to create the integer array.
void pushfront(int v)-to add integers from the front index if possible. Else display the message Full from front.
int popfront()- to remove the return element from front. If array is empty then return -999.
void pushrear(int v)- to add integers from the rear index if possible. Else display the message Full from rear.
int poprear()- to remove the return element from rear. If array is empty then return -999.
Write a main function to implement the Deque concept. import java.util.Scanner;
class Chain
{
int ele[];
int cap,front,rear;
Chain(int max)
{
cap=max;
front=-1;
rear=-1;
ele=new int[cap];
}
void pushfront(int v)
{
if(front==0)
{
System.out.println("Overflow");
}
else if(front==-1 && rear==-1)
{
front=0;
ele[front]=v;
rear=0;
}
else
ele[--front]=v;
}
int popfront()
{
17
int num;
if(front==-1 && rear==-1)
{
System.out.println("Underflow");
return(-999);
}
else if(front==rear)
{
num=ele[front];
front=-1;
rear=-1;
return num;
}
else
{
return(ele[front++]);
}
}
void pushrear(int v)
{
if(front==-1 && rear==-1)
{
ele[++rear]=v;
front++;
}
else if(rear==cap-1)
System.out.println("Overflow");
else
ele[++rear]=v;
}
int poprear()
{
int num;
if(rear==-1)
{
System.out.println("Underflow");
return(-999);
}
else if(rear==front)
{
num=ele[rear];
rear=-1;
front=-1;
return num;
}
else
18
return(ele[rear--]);
}
}
class ex7
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int no,m,f=0,el;
System.out.println("Enter the number of elements:");
no=sc.nextInt();
Chain ob=new Chain(no);
while(f!=1)
{
System.out.println("Enter the opeation which you want to implement:");
System.out.println("1.Push an element through the front of Chain");
System.out.println("2.Pop an element from the front of Chain");
System.out.println("3.Push an element through the rear of Chain");
System.out.println("4.Pop an element from the rear of Chain");
System.out.println("5.Exit the program");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("Enter the element");
el=sc.nextInt();
ob.pushfront(el);
}
else if(choice==2)
{
ob.popfront();
}
else if(choice==3)
{
System.out.println("Enter the element");
el=sc.nextInt();
ob.pushrear(el);
}
else if(choice==4)
{
ob.poprear();
}
else if(choice==5)
f=1;
else
System.out.println("Wrong Choice");
}
19
}
}
Output:
F:\Milind\Java>java ex7
Enter the number of elements:
5
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
1
Enter the element
12
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
2
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
2
Underflow
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
3
Enter the element
123
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
20
3
Enter the element
12
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
1
Enter the element
14
Overflow
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
1
Enter the element
15
Overflow
Enter the opeation which you want to implement:
1.Push an element through the front of Chain
2.Pop an element from the front of Chain
3.Push an element through the rear of Chain
4.Pop an element from the rear of Chain
5.Exit the program
5
21
8. Write a program to implement manager class that inherits from class employee. The specifications of
these classes are-
Class name-
Employee
Data member-
name
salary
hire_day
Method-
constructor- to initialize the data member
print- print name,salary along with hire date.
raisesalary- raise salary by the given percentage
Class name-
Manager
Data member-
secretary_name
Method-
constructor- to initialize data member
setsecretaryname- to set the secretary name
getsecretaryname- returns the secretary name
Write a main method to implement the above concept.
import java.util.*;
class Employee
{
String name;
double salary;
int hire_day;
Employee(String str, double sal, int h)
{
name = str;
salary = sal;
hire_day = h;
}
void print()
{
System.out.println("Employee Name : "+ name);
System.out.println("Salary : "+ salary);
System.out.println("Hire Day : "+ hire_day);
}
double raisesalary(double percentage)
{
return salary + salary * (percentage / 100);
}
}
class Manager extends Employee
{
22
String sec_name;
Manager(String str1,double sal,int h)
{
super(str1,sal,h);
sec_name = "";
}
void setssecname()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Secretary name :");
sec_name = sc.nextLine();
}
String getssecname()
{
return sec_name;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter employee name :");
String s1 = sc.nextLine();
Output:
F:\Milind\Java>java Manager
Enter employee name :
Milind Chakraborty
Enter employee salary :
23
10000000
Enter salary increase percentage :
12
Enter number of days employee has been hired for :
365
Enter Secretary name :
Shreyasi
24
9. A superclass worker has been defined to store the details of the worker. Define a subclass Wages to
compute the monthly wages for the worker. The details of the classes are given below.
Class name-
Worker
Data member-
name-to store the name of the worker
basic-to store the basic pay in decimals
Methods- Worker(….)- parameterized constructor assign values to the instance variables
void display()-display the worker’s details
Class name-
Wages
Data member-
hrs- to store the hours worked
rate- stores rate per hour
wage- store the overall wage of the worker
Methods-
Wages(….)-parameterized constructor assign values to the instance variables of both the classes
double overtime()-calculate the returns the overtime amount as hours*rate.
void display()-calculate the wage using the formula-
wage=overtime amount + basic pay
And display it along with other details.
Write a main function to perform the above operations.
import java.util.*;
class Worker
{
String name;
double basic;
Worker(String s, double p)
{
name = s;
basic = p;
}
void display()
{
System.out.println("Name : "+name);
System.out.println("Basic pay : "+basic);
}
}
class Wages extends Worker
{
double hrs;
double rate;
double wage;
Wages(double h, double r, String s1, double pa)
{
super(s1,pa);
25
hrs = h;
rate = r;
}
double overtime()
{
return hrs * rate;
}
void display()
{
wage = overtime() + basic;
super.display();
System.out.println("Hours worked :"+hrs);
System.out.println("Rate per hour :"+rate);
System.out.println("Overall Wage is :Rs."+wage);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter name :");
String n = sc.nextLine();
System.out.print("\nEnter basic basic in Rs.:");
double b = sc.nextDouble();
System.out.print("\nEnter hours worked :");
double h = sc.nextDouble();
System.out.print("\nEnter rate :");
double r = sc.nextDouble();
Wages ob = new Wages(h,r,n,b);
System.out.println();
ob.display();
}
}
Output:
F:\Milind\Java>java Wages
26
Rate per hour :12.0
Overall Wage is :Rs.200168.0
27
10. Create a class with following specifications
Class name-
Student_grade
Data members-
name[]– array of character
sex[]– array of character
age- int variable
p_marks- int variable
c_marks- int variable
m_marks- int variable
s_marks- int variable
Methods-
void inputdata()- takes name, age, sex, p_marks, m_marks and c_marks
void displaydata()- display name, age, sex, p_marks, m_marks and c_marks
void inputs_marks()- takes the s_marks
void displays_marks()- displays the s_marks
void calculate_grade()- calculates the grade and shows all details
The academic person can access inputdata(),displaydata() and calculate_grade(). The sports person can access
calculate_grade(),inputs_marks(),displays_marks().
import java.util.*;
interface academicPerson
{
void inputdata();
void displaydata();
void calculate_grade();
}
interface sportsPerson
{
void input_marks();
void display_marks();
void calculate_grade();
}
28
age=sc.nextInt();
System.out.print("Enter sex:");
sex=sc.next().toCharArray();
System.out.print("Enter Physics marks:");
p_marks=sc.nextInt();
System.out.print("Enter Chemistry marks:");
c_marks=sc.nextInt();
System.out.print("Enter Maths marks:");
m_marks=sc.nextInt();
}
29
System.out.print("\nSports marks:"+s_marks);
System.out.print("\nGrade is: ");
if(grade>=80)
{
System.out.print("A");
}
else if(grade>=60 && grade<80)
{
System.out.print("B");
}
else if(grade>=40 && grade<60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
}
class Main
{
public static void main(String[] args)
{
Student_grade ob=new Student_grade();
academicPerson ob1=ob;
sportsPerson ob2=ob;
ob1.inputdata();
ob2.input_marks();
ob1.displaydata();
ob2.display_marks();
ob.calculate_grade();
}
}
Output:
F:\Milind\Java>java Main
Enter name:Milind
Enter age:20
Enter sex:m
Enter Physics marks:89
Enter Chemistry marks:91
Enter Maths marks:99
30
Enter Sports marks:12
Academic Person:
Name is:Milind
Age is:20
Sex is:m
Physics marks:89
Chemistry marks:91
Maths marks:99
Sports Person:
Sports marks:12
Total Calculation:
Name is:Milind
Age is:20
Sex is:m
Physics marks:89
Chemistry marks:91
Maths marks:99
Sports marks:12
Grade is: B
31
//ex12
import Empinfo.Details;
class ex12
{
public static void main(String args[])//throws IOException
{
Details ob=new Details();
ob.inputdata();
ob.displaydata();
}
}
32
//DA
package DA;
public class calDA
{
public double calculateDA(double n)
{
return (0.75*n);
}
}
//HRA
package HRA;
public class calHRA
{
public double calculateHRA(double n)
{
return (0.25*n);
}
}
//NetSal
package NetSal;
import HRA.calHRA;
import DA.calDA;
public class calNetSal
{
public double calculate(double BS)
{
double h,d,net;
calHRA ob1=new calHRA();
calDA ob2=new calDA();
h=ob1.calculateHRA(BS);
d=ob2.calculateDA(BS);
net=h+d+BS;
return net;
}
}
//Empinfo
package Empinfo;
import java.io.*;
import java.util.*;
import NetSal.calNetSal;
public class Details
{
33
int Eid;
String Name,Degn;
double BS;
public void inputdata()
{
String desg[]={"Clerk","Manager","Salesman","Peon"};
int iloop;
Scanner sc=new Scanner(System.in);
//InputStreamReader in = new InputStreamReader(System.in);
//BufferedReader br = new BufferedReader(in);
//BufferedReader in=new BufferedReader(InputStreamReader(System.in));
System.out.println("Enter Employee ID no.:");
Eid=sc.nextInt();//Integer.parseInt(in.readLine());
System.out.println("Enter name of employee:");
String temp=sc.nextLine();
Name=sc.nextLine();//in.readLine();
try
{
System.out.println("Enter designation of employee:");
Degn=sc.nextLine();//in.readLine();
for(iloop=0;iloop<4;iloop++)
{
if(Degn.equalsIgnoreCase(desg[iloop])==true)
break;
if(iloop==3)
throw new NullPointerException();
}
}
catch(NullPointerException e)
{
System.out.println("Designation can only be Clerk/Manager/Salesman/Peon\nProgram ended");
System.exit(0);
}
System.out.println("Enter basic salary of employee:");
BS=sc.nextDouble();//Double.parseDouble(in.readLine());
}
public void displaydata()
{
double netsal;
calNetSal ob=new calNetSal();
netsal=ob.calculate(BS);
System.out.println("Name:\t"+Name);
System.out.println("Employee ID:\t"+Eid);
System.out.println("Designation:\t"+Degn);
System.out.println("Net salary:\t"+netsal);
}
34
}
/*Output:
D:\Milind\Java>java ex12
Enter Employee ID no.:
120
Enter name of employee:
Milind Chakraborty
Enter designation of employee:
Manager
Enter basic salary of employee:
2000000
Name: Milind Chakraborty
Employee ID: 120
Designation: Manager
Net salary: 4000000.0*/
35
13. Multiple users want to read multiple files but when one user read from a file, others must wait until the
reading is finished. Also print the waiting queue.
import java.io.*;
import java.util.*;
class fread
{
void ffread(String fname)throws Exception
{
FileInputStream fin=new FileInputStream(fname);
int x=0;
while(x!=-1)
{
x=fin.read();
if(x!=-1)
System.out.print((char)x);
//Thread.sleep(10);
}
fin.close();
}
}
class cth implements Runnable
{
fread ob;
String fname;
Thread t;
cth(fread ob1,String fname1,String tname)
{
ob=ob1;
fname=fname1;
t=new Thread(this);
t.start();
t.setName(tname);
}
public void run()
{
System.out.println("\nThread "+t.getName()+" waiting\n");
synchronized(ob){
System.out.println("\nThread "+t.getName()+" start executing\n");
try{
ob.ffread(fname);
}
catch(Exception e){}
System.out.println("\nThread "+t.getName()+" finished\n");
}
36
}
}
class ex13
{
public static void main(String ars[])throws Exception
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of threads you want:");
int num=sc.nextInt();
char c;
fread ob=new fread();
for(int i=65;i<=64+num;i++)
{/*c=Integer.toString((char)i).charAt(0);*/new cth(ob,"Assignment_13.java",(" "+(char)i));}
//new cth(ob,"main.java",);
//new cth(ob,"main.java","z");
//new cth(ob,"main.java","t");
}
}
/*Output:
D:\Milind\Java>java ex13
Enter number of threads you want:
15
Thread E waiting
Thread F waiting
Thread N waiting
Thread I waiting
Thread G waiting
Thread M waiting
Thread A waiting
Thread B waiting
37
Thread J waiting
Thread H waiting
Thread D waiting
Thread L waiting
Thread O waiting
Thread C waiting
Thread K waiting
Thread E finished
Thread K finished
Thread C finished
Thread O finished
38
Thread L start executing
Thread L finished
Thread D finished
Thread H finished
Thread J finished
Thread B finished
Thread A finished
Thread M finished
39
Thread G finished
Thread I finished
Thread N finished
Thread F finished*/
40