java programs BBIT makaut

1.Program Name:- WAJP to display Hello world.
Program source code:-
class hello
{
public static void main(String args[])
{
System.out.println(“Hello world. “);
}
}
OUTPUT-
Hello world.
2.Program Name:- WAJP to print prime numbers from 1 to 100.
Program code:-
import java.io.*;
import java.util.*;
class Prime1To100{
public static void main(String args[]){
int i,j,num=100,flag;
for(i=1;i<=num;i++)
{
flag=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
flag++;
}
if(flag==2)
{
System.out.println(i);
}
}
}
}
OUTPUT-
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
3.Program Name: WAJP to display fibonacci series.
import java.io.*;
import java.util.*;
class fibonacci
{
public static void main(String args[])
{
int num,num1=0,num2=1,num3;
System.out.println(“Enter the limitn”);
Scanner sc= new Scanner(System.in);
num=sc.nextInt();
System.out.println(num1);
System.out.println(num2);
for(int i=2;i<num;i++) {
num3=num1+num2;
num1=num2;
num2=num3;
System.out.println(num3);
}
}
}
OUTPUT:-
Enter the limit
5
0
1
1
2
3
4.Program Name: WAJP to print binary triangle.
import java.io.*;
import java.util.*;
class Binary_triangle {
public static void main(String[] args) {
int num,row,coloumn;
System.out.println(“Enter the size of row”);
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
for(row=1;row<=num;row++)
{
for(coloumn=1;coloumn<=row;coloumn++)
System.out.print(coloumn%2+”t”);
System.out.print(“n”);
}
}
}
OUTPUT:-
Enter the size of row
6
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
1 0 1 0 1 0
5.Program Name:WAJP to print sum of series from 1+2+3+…N.
import java.io.*;
import java.util.*;
class sum_series{
public static void main(String args[])
{
int num1,num2=0;
System.out.println(“Enter the limit”);
Scanner sc=new Scanner(System.in);
num1=sc.nextInt();
for(int i=0;i<=num1;i++)
{
num2=num2+i;
}
System.out.println(“The sum of series is”+”t”+num2);
}
}
OUTPUT:-
Enter the limit
9
The sum of series is 45
6.Program Name:WAJP to print largest among three numbers.
import java.io.*;
import java.util.*;
class largest_number{
public static void main(String args[]){
int num1,num2,num3;
System.out.println(“Enter three numbers one by one”);
Scanner sc=new Scanner(System.in);
num1=sc.nextInt();
num2=sc.nextInt();
num3=sc.nextInt();
if(num1>num2 && num1>num3)
System.out.println(“The greater number isn”+num1);
if(num2>num1 && num2>num3)
System.out.println(“The greater number isn”+num2);
if(num3>num1 && num3>num2)
System.out.println(“The greater number isn”+num3);
}
}
OUTPUT:-
Enter three numbers one by one
45
12
78
The greater number is
78
7.Program Name:WAJP to find the following series
X+x^2+x^3+……X^N.
Source code:
import java.io.*;
import java.util.*;
import static java.lang.Math.pow;
class SeriesPro7{
public static void main(String args[]){
double num,sum=0,x,i;
System.out.println(“Enter the number to limit of N”);
Scanner obj1=new Scanner(System.in);
num=obj1.nextInt();
System.out.println(“enter the value of x”);
x=obj1.nextInt();
System.out.println(num);
for (i=1;i<=num;i++)
{
sum=sum+Math.pow(x,i);
}
System.out.println(“The sum of the series X^1+X^2+X^3+X^N is”+sum);
}
}
OUTPUT-
Enter the number to limit of N
5
enter the value of x
4
5.0
The sum of the series X^1+X^2+X^3+X^N is1364.0
8.Program Name: WAJP to print sorted array.
import java.io.*;
import java.util.*;
public class Arraysort {
public static void main(String[] args) {
int num,i,j,temp;
System.out.println(“Enter the size of array”);
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
System.out.println(“Enter elements in array one by one”);
int array[]=new int [50];
for(i=0;i<num;i++)
{
array[i]=sc.nextInt();
}
System.out.println(“The numbers entered in array is”);
for(i=0;i<num;i++){
System.out.println(array[i]);
}
for(i=0;i<=num-1;i++)
{
for(j=1+i;j<=num-1;j++){
if(array[i]>array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
System.out.println(“The sorted array is”);
for(i=0;i<num;i++){
System.out.println(array[i]);
}
}
}
OUTPUT:-
Enter the size of array
5
Enter elements in array one by one
12
23
56
89
15
The numbers entered in array is
12
23
56
89
15
The sorted array is
12
15
23
56
89
9.Program Name: WAJP to print sum of array.
import java.io.*;
import java.util.Scanner;
public class Array_sum {
public static void main(String[] args) { int num,i,sum=0;
System.out.println(“Enter the size of array”);
Scanner sc=new Scanner (System.in);
num=sc.nextInt();
int array[]=new int [100];
System.out.println(“Enter the elements in the array one by one”);
for(i=0;i<num;i++)
{
array[i]=sc.nextInt();
}
System.out.println(“The entered element in the array is”);
for(i=0;i<num;i++)
{
System.out.println(array[i]);
}
System.out.println(“The sum of the array is”);
for(i=0;i<num;i++)
{
sum=sum+array[i];
}
System.out.println(sum);
}
}
OUTPUT:-
Enter the size of array
5
Enter the elements in the array one by one
23
12
45
78
12
The entered element in the array is
23
12
45
78
12
The sum of the array is
170
10.Program Name:WAJP to find circumference and area of circle using command line argument.
Source code:-
import java.io.*;
import java.util.*;
class Areacir{
public static void main(String args[])
{
double r=Integer.parseInt(args[0]);
double a,c;
c=2*3.14*r;
a=3.14*r*r;
System.out.println(“circumference”+” “+ c);
System.out.println(“area”+” “+ a);
}
}
OUTPUT:-
java Areacir 10
circumference 62.800000000000004
11.Program Name:WAJP to find circumference and area of circle using buffer reader statement.
Source code:-
import java.io.*;
class Circle{
public static void main(String args[])throws IOException
{
double r,a,p;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“n Enter the radius of circle”);
r=Double.parseDouble(br.readLine());
a=3.141*r*r;
p=2*3.14*r;
System.out.println(“Area of circle “+a);
System.out.println(“Perimeter of circle “+p);
}
}
OUTPUT:-
Enter the radius of circle
5
Area of circle 78.525
Perimeter of circle 31.400000000000002
12.Program Name:WAJP to find circumference and area of circle using constructor.
Source code:
import java.io.*;
import java.util.*;
class Circumference
{
double diameter;
Circumference(double d)
{
diameter=d;
}
double Circumference()
{
return 3.14*diameter;
}
}
class Area
{
double radius;
Area(double r)
{
radius=r;
}
double Area()
{
return 3.14*radius*radius;
}
}
class CircleConstructor
{
public static void main(String args[])
{
Circumference CircleCircumference = new Circumference(8);
System.out.println(“The circumference of circle is ” + CircleCircumference.Circumference());
Area AreaofCircle = new Area(2);
System.out.println(“The area of circle is ” + AreaofCircle.Area());
}
}
OUTPUT:-
The circumference of circle is 25.12
The area of circle is 12.56
13.Program Name:WAJP to volume and surface area of cone using command line argument.
Source code:-
import java.io.*;
import java.util.*;
class Areavolconecomm{
public static void main(String args[])
{
double r=Integer.parseInt(args[0]);
double h=Integer.parseInt(args[1]);
double a,v;
v=3.14*r*r*(h/3);
a=3.14*r*r;
System.out.println(“volume”+” “+ v);
System.out.println(“Area”+” “+ a);
}
}
OUTPUT:-
java Areavolconecomm 3 5
volume 47.1
Area 28.259999999999998
14.Program Name:WAJP to find volume and surface area of cone using buffer reader statement.
Source code :-
import java.io.*;
class Conevolbuff{
public static void main(String args[])throws IOException
{
double r,a,h,v;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“n Enter the radius of cone”);
r=Double.parseDouble(br.readLine());
System.out.println(“n Enter the height of cone”);
h=Double.parseDouble(br.readLine());
a=3.141*r*r;
v=3.14*r*r*(h/3);
System.out.println(“Arae of cone”+a);
System.out.println(“volume of cone”+v);
}
}
OUTPUT:-
Enter the radius of cone
3
Enter the height of cone
6
Arae of cone28.269
volume of cone56.519999999999996
15.Program Name:WAJP to find volume and surface area of cone using constructor.
Source code :
import java.io.*;
import java.util.*;
import static java.lang.Math.sqrt;
class Area
{
double radius;
double height;
Area(double r,double h)
{
radius = r;
height = h;
}
double Area()
{
return 3.14*radius*(radius + Math.sqrt(height*height + radius*radius));
}
}
class Volume
{
double radius;
double height;
Volume (double r,double h)
{
radius= r;
height = h;
}
double Volume()
{
return 3.14*radius*radius *(height/3);
}
}
class ConeConstructor
{
public static void main(String args[])
{
Area AreaofCone = new Area(7,3);
System.out.println(“The area of cone ” + AreaofCone.Area());
Volume VolofCone = new Volume(4,5);
System.out.println(“The volume of the cone ” + VolofCone.Volume());
}
}
OUTPUT:
The area of cone 321.2546928668887
The volume of the cone 83.73333333333333
16.Program Name:WAJP to find volume and surface area of cylinder using command line argunment.
Source code :-
import java.io.*;
import java.util.*;
class Cylindercomm{
public static void main(String args[])
{
double r=Integer.parseInt(args[0]);
double h=Integer.parseInt(args[1]);
double a,v;
v=3.14*r*r*h;
a=2*3.14*r*(r+h);
System.out.println(“Volume of cylinder”+” “+ v);
System.out.println(“Area of cylinder”+” “+ a);
}
}
OUTPUT:-
java Cylindercomm 3 6
Volume of cylinder 169.56
Area of cylinder 169.56
17.Program Name:WAJP to find volume and surface area of cylinder using buffer reader statement.
Source code :-
import java.io.*;
class Cylinderbuff{
public static void main(String args[])throws IOException
{
double r,a,h,v;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“n Enter the radius of cone”);
r=Double.parseDouble(br.readLine());
System.out.println(“n Enter the height of cone”);
h=Double.parseDouble(br.readLine());
a=2 * 3.14 * r * (r + h);
v=3.14*r*r*h;
System.out.println(“Arae of cylinder “+a);
System.out.println(“Volume of cylinder “+v);
}
}
OUTPUT:-
Enter the radius of cone
3
Enter the height of cone
6
Arae of cylinder 169.56
Volume of cylinder 169.56
18.Program Name:WAJP to find volume and surface area of cylinder using constructor.
Source code:
import java.io.*;
import java.util.*;
class Vol{
double radius;
double height;
//here vol is constructor
Vol(double r,double h){
radius = r;
height = h;
}
double vol(){
return 3.14*radius*radius*height;
}
}
class Area{
double radius;
double height;
//Area is constructor
Area(double r,double h){
radius=r;
height=h;
}
double area(){
return (2*3.14*radius*height) + (2*3.14*radius*radius);
}
}
class Area_Vol_Cylin_Const{
public static void main(String args[]){
Vol cylinder=new Vol(7,10);
System.out.println(“volume of cylinder is “+cylinder.vol());
Area area=new Area(7,10);
System.out.println(“Area is “+area.area());
}
}
OUTPUT:
volume of cylinder is 1538.6000000000001
Area is 747.32
19.Program Name:WAJP to find the area of a square and a rectangle using overloading concepts.
Source code :
import java.io.*;
import java.util.*;
//Instance variable of Box.
class Box{
double length;
double width;
//Constructor for rectangle when two parameter are passed (area).
Box(double l,double w){
length=l;
width=w;
}
//method for calculating area of rectangle.
double AreaRectangle(){
return length*width;
}
//method for calculating perimeter of rectangle.
double PerimeterRectangle(){
return 2*(length + width);
}
//Constructor for square when one value is initialized(area).
Box(double l){
length=l;
}
//method for calculating area of square.
double AreaSquare(){
return length*length*length;
}
//method for calculating perimeter of square.
double perimeterSquare(){
return 4*length;
}
}
//Main class from where program execution begins.
class Square_Rectangle_Const_Overloading{
public static void main(String args[]){
//creating object Rectangle name rectangle.
Box rectangle = new Box(10,20);
//creting object name square.
Box square = new Box(10);
System.out.println(“Area of rectangle is ” + rectangle.AreaRectangle());
System.out.println(“Area of square is ” + square.AreaSquare());
System.out.println(“Perimeter of Rectangle ” + rectangle.PerimeterRectangle());
System.out.println(“Perimeter of Square ” + square.perimeterSquare());
}
}
OUTPUT :
Area of rectangle is 200.0
Area of square is 1000.0
Perimeter of Rectangle 60.0
Perimeter of Square 40.0
20.Program Name:WAJP to find the area of two rectangles using overriding concepts.
Source code :-
import java.io.*;
import java.util.*;
class Rect{
double len,bre;
Rect(double a, double b)
{
len=a;
bre=b;
}
double area()
{
System.out.println(” Area is for rectangle 1 &2″);
return 0;
}
}
class Rectangle1 extends Rect{
Rectangle1(double a, double b)
{
super(a,b);
}
double area()
{
System.out.println(“Inside of Rectangle 1”);
System.out.println(“Area of rectangle 1”);
return len*bre;
}
}
class Rectangle2 extends Rect{
Rectangle2(double a, double b)
{
super(a,b);
}
double area()
{
System.out.println(“Inside of Rectangle 2”);
System.out.println(“Area of rectangle 2”);
return (len*bre);
}
}
class Rectoveride{
public static void main(String args[])
{
Rect r;
Rectangle1 ob1=new Rectangle1(8,5);
Rectangle2 ob2=new Rectangle2(9,6);
r= ob1;
System.out.println(“Area of first rectangle”+” “+r.area());
r=ob2;
System.out.println(“Area of second rectangle”+” “+r.area());
}
}
OUTPUT:-
Inside of Rectangle 1
Area of rectangle 1
Area of first rectangle 40.0
Inside of Rectangle 2
Area of rectangle 2
Area of second rectangle 54.0
21.Program Name:WAJP to whether a given string is palindrome or not .
Source code:-
import java.io.*;
import java.util.*;
class Palindrome{
public static void main(String args[]){
String s1,s2=””;
Scanner in=new Scanner(System.in);
System.out.println(“Enter a string”);
s1=in.nextLine();
int len=s1.length();
for(int i=len-1;i>=0;i–)
{
s2=s2+s1.charAt(i);
}
if(s1.equals(s2))
System.out.println(“string is palindrome”);
else
System.out.println(“string is not palindrome”);
}
}
OUTPUT:-
Enter a string
bum
string is not palindrome
22.Program Name:WAJP to compare and find length of the string find uppercase lowercase and replace N by I in the string ENCYCLOPEDIA.
Source code:-
import java.io.*;
import java.util.*;
class Stringcomp
{
public static void main(String args[])
{ String s1,s2;
Scanner in=new Scanner(System.in);
System.out.println(“Enter the first string”);
s1=in.nextLine();
System.out.println(“Enter the second string”);
s2=in.nextLine();
if(s1.compareTo(s2)>0)
System.out.println(“first string is greater than second string”);
if(s1.compareTo(s2)<0)
System.out.println(“first string is less than second string”);
else
if(s1.compareTo(s2)==0)
System.out.println(“both string are equal”);
String s=”bum kailash kumar”;
String upper=s.toUpperCase();
String lower=s.toLowerCase();
System.out.println(“uppercase”+” “+upper);
System.out.println(“lowercase”+” “+lower);
String str=”ENCYCLOPEDIA”.replace(‘N’,’I’);
System.out.println(“string after replacement “+” “+str);
}
}
OUTPUT:-
Enter the first string
bum
Enter the second string
bum
both string are equal
uppercase BUM KAILASH KUMAR
lowercase bum kailash kumar
string after replacement EICYCLOPEDIA
27.Program Name:WAJP to create an interface to find the inner volume and outer volume of a part.
Source code:-
import java.io.*;
import java.util.*;
interface Volume{
void volumeouter(int R);
void volumeinner(int r);
}
class Findvolume implements Volume{
public void volumeouter(int R)
{
double v1= (4/3)*R*R*R;
System.out.println(“volume”+” “+v1);
}
public void volumeinner(int r)
{
double v2= (4/3)*r*r*r;
System.out.println(“volume”+” “+v2);
}
}
class Interfac
{
public static void main(String args[])
{
Volume c=new Findvolume();
c.volumeouter(7);
c.volumeinner(5);
}
}
OUTPUT:-
volume 343.0
volume 125.0
28.Program Name:WAJP to check arithmetic exception using try catch block.
Source code:-
import java.io.*;
import java.util.*;
class Arithmetic{
public static void main(String args[]){
int d,a;
try{
d=0;
a=51/0;
System.out.println(“This will not be printed”);
}
catch (ArithmeticException e)
{
System.out.println(“Division by zero”);
}
System.out.println(“After catch statement”);
}
}
OUTPUT:-
Division by zero
After catch statement
29.Program Name:WAJP to check array index exception.
Source code:-
import java.io.*;
import java.util.*;
class Arrayout{
public static void main(String args[])
{
int arr[]={10,11,12};
try{
int a1=arr[3];
System.out.println(“Array element is”+” “+a1);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(“Array element is out of bound”+e);
}
}
}
OUTPUT:-
Array element is out of boundjava.lang.ArrayIndexOutOfBoundsException: 3
30.Program Name:WAJP to check array negative array index exception.
Source code:-
import java.io.*;
import java.util.*;
class NegativeArray{
public static void main(String args[])
{ int s1=-5;
Scanner in=new Scanner(System.in);
try{
System.out.println(“Enter the number of elements”);
int[] arr=new int[s1];
}
catch(NegativeArraySizeException e)
{
System.out.println(“Can’t create negative array”+” “+e);
}
}
}
OUTPUT:-
Enter the number of elements
Can’t create negative array java.lang.NegativeArraySizeException
31.Program Name:WAJP implement multithreading concept.
Source code:-
class NewThread extends Thread{
String name;
Thread t;
NewThread(String threadname){
super(“DemoThread”);
name=threadname;
System.out.println(“child Thread:”+” “+this);
start();
}
public void run(){
try{
for(int i=5;i>0;i–){
System.out.println(“child Thread” + i);
Thread.sleep(500);
}
}
catch(InterruptedException e){
System.out.println(“childInterrupted”);
}
System.out.println(“Exiting child Thread”);
}
}
class MultiThread{
public static void main(String args[])
{
new NewThread(“one”);
new NewThread(“two”);
new NewThread(“three”);
try{
for(int i=5;i>0;i–){
System.out.println(“Main Thread” + i);
Thread.sleep(500);
}
}
catch(InterruptedException e){
System.out.println(” Main child Interrupted”);
}
System.out.println(“Main Thread exiting”);
}
}
OUTPUT:-
child Thread: Thread[DemoThread,5,main]
child Thread: Thread[DemoThread,5,main]
child Thread: Thread[DemoThread,5,main]
child Thread5
child Thread5
Main Thread5
child Thread5
child Thread4
Main Thread4
child Thread4
child Thread4
child Thread3
child Thread3
Main Thread3
child Thread3
child Thread2
Main Thread2
child Thread2
child Thread2
child Thread1
Main Thread1
child Thread1
child Thread1
Exiting child Thread
Main Thread exiting
Exiting child Thread
Exiting child Thread
33.Program Name:-Write an applet to display a message on screen and set background color to red.
Source code:
//applet displaying welcome
import java.applet.*;
import java.awt.*;
/*<applet code =”appletwelcome” width=100 height =300></applet>*/
public class appletwelcome extends Applet
{
public void init()
{
setBackground(Color.red);
}
public void paint(Graphics g)
{
String msg=”welcome”;
g.drawString(msg,10,10);
}
}
OUTPUT:-

34.Program Name:-Write an applet program to draw a polygon.
Source code:-
//applet displaying polygon
import java.applet.*;
import java.awt.*;
/*<applet code =”polygon” width=100 height =300></applet>*/
public class polygon extends Applet
{
public void init()
{
setBackground(Color.red);
}
public void paint(Graphics g)
{
int y[]={70,150,190,80,100};
int x[]={80,110,160,190,100};
g.drawPolygon(x,y,5);
}
}
OUTPUT:-

36.Program Name:-Write an applet program to draw a house.
Source code:-
//applet displaying basichome
import java.applet.*;
import java.awt.*;
/*<applet code =”basichome” width=100 height =300></applet>*/
public class basichome extends Applet
{
public void init()
{
setBackground(Color.red);
}
public void paint(Graphics g)
{
g.drawRect(30,200,350,400);
int y[]={200,20,200};
int x[]={30,210,380};
g.drawPolygon(x,y,3);
g.drawRect(50,300,30,30);
g.drawRect(300,300,30,30);
g.drawRect(170,500,40,90);
}
}
OUTPUT:-

23. WAJP with class tree take code(string),height(double),width(double), and amount spent (float).write a method to display th details and another method anualupdate to update.
Source code :-
import java.io.*;
import java.util.*;
class Tree{
Scanner in=new Scanner(System.in);
String code;
double height;
double width;
float amountspent;
void entry()
{
System.out.println(“enter the code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
void annualupdate()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display1()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
}
class Record{
public static void main(String args[])
{
Tree ob=new Tree();
ob.entry();
ob.display();
ob.annualupdate();
ob.display1();
}
}
OUTPUT:-
enter the code string
bvn
enter the height
4
enter the width
25
enter the amount spent
255
The code of the tree is bvn
The height of the tree is 4.0
The width of the tree is 25.0
The spent amount of the tree is 255.0
enter code string
enter the height
4
enter the width
3
enter the amount spent
352
The code of the tree is
The height of the tree is 4.0
The width of the tree is 3.0
The spent amount of the tree is 352.0
24.WAJP with class mango which extends tree take code(string),height(double),width(double) and amount spent (float) and yield(int).
Source code:-
import java.io.*;
import java.util.*;
class Tree{
Scanner in=new Scanner(System.in);
String code;
double height;
double width;
float amountspent;
void entry()
{
System.out.println(“enter the code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
void annualupdate()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display1()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
}
class Mangoes extends Tree{
int Yield;
void entrymango()
{
System.out.println(“enter the code string of mango”);
code=in.nextLine();
System.out.println(“enter the height of mango”);
height=in.nextDouble();
System.out.println(“enter the width of mango”);
width=in.nextDouble();
System.out.println(” enter the amount spent mango”);
amountspent=in.nextFloat();
System.out.println(“the yield of the tree is mango”);
Yield=in.nextInt();
}
void displaymango()
{
System.out.println(“The code of the mango tree is”+” “+code);
System.out.println(“The height of the mango tree is”+” “+height);
System.out.println(“The width of the mango tree is”+” “+width);
System.out.println(“The spent amount of mango the tree is”+” “+amountspent);
System.out.println(“the yield of mango tree is “+” “+Yield);
}
}
class Mango{
public static void main(String args[])
{
Tree ob=new Tree();
Mangoes ob1=new Mangoes();
ob.entry();
ob.display();
ob.annualupdate();
ob.display1();
ob1.entrymango();
ob1.displaymango();
}
}
OUTPUT:-
enter the code string
bhj
enter the height
5
enter the width
62
enter the amount spent
250
The code of the tree is bhj
The height of the tree is 5.0
The width of the tree is 62.0
The spent amount of the tree is 250.0
enter code string
nyt
enter the height
6
enter the width
45
enter the amount spent
142
The code of the tree is
The height of the tree is 6.0
The width of the tree is 45.0
The spent amount of the tree is 142.0
enter the code string of mango
bnj
enter the height of mango
45
enter the width of mango
85
enter the amount spent mango
412
the yield of the tree is mango
123
The code of the mango tree is bnj
The height of the mango tree is 45.0
The width of the mango tree is 85.0
The spent amount of mango the tree is 412.0
the yield of mango tree is 123
25.Write a method display to display the details and another method annual_update to update.
Source code:-
String code;
double height;
double width;
float amountspent;
void entry()
{
System.out.println(“enter the code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
void annualupdate()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display1()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
}
class Mangoes extends Tree{
int Yield;
void entrymango()
{
System.out.println(“enter the code string of mango”);
code=in.nextLine();
System.out.println(“enter the height of mango”);
height=in.nextDouble();
System.out.println(“enter the width of mango”);
width=in.nextDouble();
System.out.println(” enter the amount spent mango”);
amountspent=in.nextFloat();
System.out.println(“the yield of the tree is mango”);
Yield=in.nextInt();
}
void displaymango()
{
System.out.println(“The code of the mango tree is”+” “+code);
System.out.println(“The height of the mango tree is”+” “+height);
System.out.println(“The width of the mango tree is”+” “+width);
System.out.println(“The spent amount of mango the tree is”+” “+amountspent);
System.out.println(“the yield of mango tree is “+” “+Yield);
}
void annualupdatemango()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
System.out.println(“the yield of the tree is mango”);
Yield=in.nextInt();
}
void display1mango()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
System.out.println(“the yield of mango tree is “+” “+Yield);
}
}
class Mangoupdate{
public static void main(String args[])
{
Tree ob=new Tree();
Mangoes ob1=new Mangoes();
ob.entry();
ob.display();
ob.annualupdate();
ob.display1();
ob1.entrymango();
ob1.displaymango();
ob1.annualupdatemango();
ob1.display1mango();
}
}
OUTPUT:-
enter the code string
ghj
enter the height
7
enter the width
6
enter the amount spent
265
The code of the tree is ghj
The height of the tree is 7.0
The width of the tree is 6.0
The spent amount of the tree is 265.0
enter code string
enter the height
5
enter the width
6
enter the amount spent
456
The code of the tree is
The height of the tree is 5.0
The width of the tree is 6.0
The spent amount of the tree is 456.0
enter the code string of mango
kmj
enter the height of mango
8
enter the width of mango
6
enter the amount spent mango
412
the yield of the tree is mango
6
The code of the mango tree is kmj
The height of the mango tree is 8.0
The width of the mango tree is 6.0
The spent amount of mango the tree is 412.0
the yield of mango tree is 6
enter code string
ght
enter the height
8
enter the width
65
enter the amount spent
45
the yield of the tree is mango
9
The code of the tree is
The height of the tree is 8.0
The width of the tree is 65.0
The spent amount of the tree is 45.0
the yield of mango tree is 9
26.WAJP with class garden make two objects for tree T1 and T2 and two objects for mango M1 and
M2 .print all details.
Source code:-
import java.io.*;
import java.util.*;
class Tree{
Scanner in=new Scanner(System.in);
String code;
double height;
double width;
float amountspent;
void entry()
{
System.out.println(“enter the code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
void annualupdate()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
}
void display1()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
}
}
class Mangoes extends Tree{
int Yield;
void entrymango()
{
System.out.println(“enter the code string of mango”);
code=in.nextLine();
System.out.println(“enter the height of mango”);
height=in.nextDouble();
System.out.println(“enter the width of mango”);
width=in.nextDouble();
System.out.println(” enter the amount spent mango”);
amountspent=in.nextFloat();
System.out.println(“the yield of the tree is mango”);
Yield=in.nextInt();
}
void displaymango()
{
System.out.println(“The code of the mango tree is”+” “+code);
System.out.println(“The height of the mango tree is”+” “+height);
System.out.println(“The width of the mango tree is”+” “+width);
System.out.println(“The spent amount of mango the tree is”+” “+amountspent);
System.out.println(“the yield of mango tree is “+” “+Yield);
}
void annualupdatemango()
{
System.out.println(“enter code string”);
code=in.nextLine();
System.out.println(“enter the height”);
height=in.nextDouble();
System.out.println(“enter the width”);
width=in.nextDouble();
System.out.println(” enter the amount spent”);
amountspent=in.nextFloat();
System.out.println(“the yield of the tree is mango”);
Yield=in.nextInt();
}
void display1mango()
{
System.out.println(“The code of the tree is”+” “+code);
System.out.println(“The height of the tree is”+” “+height);
System.out.println(“The width of the tree is”+” “+width);
System.out.println(“The spent amount of the tree is”+” “+amountspent);
System.out.println(“the yield of mango tree is “+” “+Yield);
}
}
class Garden{
public static void main(String args[])
{
Tree T1=new Tree();
Tree T2=new Tree();
Mangoes M1=new Mangoes();
Mangoes M2=new Mangoes();
T1.entry();
T2.entry();
T1.display();
T2.display();
T1.annualupdate();
T2.annualupdate();
T1.display1();
T2.display1();
M1.entrymango();
M2.entrymango();
M1.displaymango();
M2.displaymango();
M1.annualupdatemango();
M2.annualupdatemango();
M1.display1mango();
M2.display1mango();
}
}
OUTPUT:-
enter the code string
man
enter the height
7
enter the width
4
enter the amount spent
67
enter the code string
buj
enter the height
8
enter the width
5
enter the amount spent
70
The code of the tree is man
The height of the tree is 7.0
The width of the tree is 4.0
The spent amount of the tree is 67.0
The code of the tree is buj
The height of the tree is 8.0
The width of the tree is 5.0
The spent amount of the tree is 70.0
enter code string
hgr
enter the height
9
enter the width
6
enter the amount spent
87
enter code string
enter the height
6
enter the width
9
enter the amount spent
78
The code of the tree is
The height of the tree is 9.0
The width of the tree is 6.0
The spent amount of the tree is 87.0
The code of the tree is
The height of the tree is 6.0
The width of the tree is 9.0
The spent amount of the tree is 78.0
enter the code string of mango
qwd
enter the height of mango
15
enter the width of mango
7
enter the amount spent mango
78
the yield of the tree is mango
98
enter the code string of mango
67
enter the height of mango
9
enter the width of mango
8
enter the amount spent mango
67
the yield of the tree is mango
90
The code of the mango tree is qwd
The height of the mango tree is 15.0
The width of the mango tree is 7.0
The spent amount of mango the tree is 78.0
the yield of mango tree is 98
The code of the mango tree is 67
The height of the mango tree is 9.0
The width of the mango tree is 8.0
The spent amount of mango the tree is 67.0
the yield of mango tree is 90
enter code string
mjk
enter the height
87
enter the width
7
enter the amount spent
8
the yield of the tree is mango
8
enter code string
try
enter the height
8
enter the width
8
enter the amount spent
8
the yield of the tree is mango
8
The code of the tree is
The height of the tree is 87.0
The width of the tree is 7.0
The spent amount of the tree is 8.0
the yield of mango tree is 8
The code of the tree is
The height of the tree is 8.0
The width of the tree is 8.0
The spent amount of the tree is 8.0
the yield of mango tree is 8
32.WAJP to check isAlive() AND join() of threads.
Source code:-
import java.io.*;
import java.util.*;
class NewThread implements Runnable{
String name;
Thread t;
NewThread(String threadname){
name=threadname;
t=new Thread(this,name);
System.out.println(“New Thread:”+” “+t);
t.start();
}
public void run(){
try{
for(int i=5;i>0;i–){
System.out.println(“name” + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println(name+” Interrupted “);
}
System.out.println(name+” Exiting “);
}
}
class Isali{
public static void main(String args[])
{
NewThread ob1=new NewThread(“one”);
NewThread ob2=new NewThread(“two”);
NewThread ob3=new NewThread(“three”);
System.out.println(“thread one is alive “+ ob1.t.isAlive());
System.out.println(“thread two is alive “+ob2.t.isAlive());
System.out.println(“thread three is alive “+ob3.t.isAlive());
try{
System.out.println(“waiting for thread to finish”);
ob1.t.join();
ob2.t.join();
ob3.t.join();
}
catch(InterruptedException e)
{
System.out.println(“main thread interrupted”);
}
}
System.out.println(“thread one is alive “+ob1.t.isAlive());
System.out.println(“thread two is alive “+ob2.t.isAlive());
System.out.println(“thread three is alive “+ob3.t.isAlive());
System.out.println(“main thread exiting”);
}
OUTPUT:-
New Thread: Thread[one,5,main]
New Thread: Thread[two,5,main]
New Thread: Thread[three,5,main]
waiting for thread to finish
name5
name5
name5
name4
name4
name4
name3
name3
name3
name2
name2
name2
name1
name1
name1
three Exiting
one Exiting
two Exiting

Leave a Comment

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat