2BA19CS011 Javalab-Merged
2BA19CS011 Javalab-Merged
2BA19CS011 Javalab-Merged
class Box
double width;
double height;
double depth;
double volume()
double vol;
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
vol = mybox1.volume();
vol= mybox2.volume();
}
//2BA19CS011
import java.util.Scanner;
while(true)
type_of_op = s.nextInt();
//reading type value
switch(type_of_op)
//s.nextInt();
break;
case 2: System.out.println("Element you want to pop is "+ ob1.pop());
break;
ob1.print();
break;
return ;
class Mystack
int tos;
Mystack()
public void push(int item) //for inserting element into stack in stack order
if(tos==2)
{
System.out.println("stack is full");
return;
else
st_elements[++tos] = item;
if(tos<0)
System.out.println("stack underflow");
return 0;
else
System.out.println("top"+tos);
return st_elements[tos--];
//{
//return true;
//else return false;
//}
int temp=0;
if(tos<0)
System.out.println("stack underflow");
else
for (temp=tos;temp>=0;temp--)
System.out.println("element"+st_elements[temp]);
};
//2BA19CS011
import java.util.Scanner;
int n1;
t1.setTime();
t2.setTime();
t1.show();
t2.show();
t3.ADD(t1,t2);
t3.show();
System.out.println("Enter integer");
n1=s1.nextInt();
t4.ADD(t1,n1);
t4.show();
class Time
{ int h,m,s;
public Time()
// void setTime();
int a,b;
a = t1.s+t2.s;
s = a%60;
b = (a/60)+t1.m+t2.m;
m = b%60;
h = (b/60)+t1.h+t2.h;
h = h%12;
// return t;
Time t;
int a,b;
a = t1.s+n;
s = a%60;
b = (a/60)+t1.m;
m = b%60;
h = (b/60)+t1.h;
h= h%12;
// return t;
{
Scanner s1 = new Scanner(System.in);
System.out.println("enter hour");
h=s1.nextInt();
System.out.println("enter minute");
m=s1.nextInt();
System.out.println("enter seconds");
s=s1.nextInt();
}
//2BA19CS011
class Point
int x;
int y;
Point()
x = 10;
y = 20;
Point(int a,int b)
x = a;
y = b;
Point(Point p)
x=p.x;
y=p.y;
p1.display();
p2.display();
p3.display();
}
//2BA19CS011
import java.util.Scanner;
import java.io.*;
class string {
// create a string
String Given_string ;
String sub_str;
String str2 ;
Given_string = sc.nextLine();
sub_str=sc.nextLine();
// using contains()
if(result) {
else {
String ch = sc.nextLine();
int Index=0;
Index = Given_string.indexOf(ch);
boolean r = Given_string.contains(ch);
if (r) {
else{
}
//2BS19CS011
import java.util.Scanner;
class Exception {
do {
try {
tryAgain = false;
System.out.println("* The number you entered is not between 15 and 25. Try again.");
System.out.println();
input.nextLine();
}
} while(tryAgain);
}
//2BA19CS011
//LAB ASSIGNMENT-5
import java.util.Scanner;
class person
{
private String name;
private int age;
private String addr;
void input()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the name, adress and age");
name=s.nextLine();
addr=s.nextLine();
age=s.nextInt();
}
void output()
{
System.out.println("name : "+name+"\nage : "+age+"\naddress : "+addr);
}
}
class student extends person
{
private float cgpa;
void input()
{
Scanner in=new Scanner(System.in);
super.input();
System.out.println("enter the cgpa");
cgpa=in.nextFloat();
}
void output()
{
{
if(cgpa>8.5)
{
super.output();
System.out.println("cgpa : "+cgpa);
}
}
}
}
class professor extends person
{
private int p;
void input()
{
Scanner in=new Scanner(System.in);
super.input();
System.out.println("enter the number of publication");
p=in.nextInt();
}
void output()
{
{
if(p>25)
{
super.output();
System.out.println(" number of publication : "+p);
}
}
}
}
while(true)
{
System.out.println("enter your choice");
int c=in.nextInt();
if(c==3)
break;
switch(c)
{
case 1:
System.out.println("enter the number of
students");
int n=in.nextInt();
student s[]=new student[n];
for(int i=0;i<n;i++)
s[i]=new student();
for(int i=0;i<n;i++)
{
System.out.println("enter "+(i+1)+"
student information");
s[i].input();
}
System.out.println("students having cgpa
more than 8.5 are");
for(int i=0;i<n;i++)
{
s[i].output();
}
break;
case 2:
System.out.println("enter the number of
professor");
int m=in.nextInt();
professor q[]=new professor[m];
for(int i=0;i<m;i++)
q[i]=new professor();
for(int i=0;i<m;i++)
{
System.out.println("enter "+(i+1)+"
professor information");
q[i].input();
}
System.out.println("prfessor having
more than 25 publication are");
for(int i=0;i<m;i++)
{
q[i].output();
}
break;
default:
System.out.println("invalied
option");
break;
}
}
}
}
//2BA19CS011
//LAB ASSIGNMENT-6
import java.util.*;
interface geomatricobjects
{
void getparameter();
void getarea();
}
class circle implements geomatricobjects
{
protected float radius;
public void getparameter()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the radius of the circle");
radius=s.nextFloat();
}
public void getarea()
{
float area;
area=3.142f*radius*radius;
System.out.println("area of the circle having radius
"+radius+" is "+area);
}
}
interface resizable
{
void resize();
}
class resizeablecircle extends circle implements resizable
{
public void resize()
{
super.getparameter();
super.getarea();
Scanner s=new Scanner(System.in);
System.out.println("enter the percentage of resize");
float per;
per=s.nextFloat();
per=per/100.0f;
radius=radius*per;
}
public void getarea()
{
float area;
area=3.142f*radius*radius;
System.out.println("area of the circle of changed radius
"+radius+" is"+area);
}
}
class Ass6
{
public static void main(String[] args)
{
resizeablecircle r=new resizeablecircle();
r.resize();
r.getarea();
}
}
//2BA19CS011
//LAB ASSIGNMENT-9
// Java Program to Write a java program to implement interthread communication
// for producer and consumers problem.
import java.io.*;
class Thread1
{
int n;
boolean valueset=false;
while(!valueset)
try
{
wait();
}catch(InterruptedException e)
{
System.out.println("Interrupted Excepton occur at : "+e);
}
System.out.println("get" +n);
valueset = false;
notify();
}
while (valueset)
try
{
wait();
}catch(InterruptedException e)
{
this.n=n;
valueset=true;
System.out.println("put"+n);
notify();
}
}
class Producer implements Runnable
{
Thread1 t;
Producer(Thread1 t)
{
this.t=t;
}
public void run()
{
for(int k=1;k<=5;k++)
{
t.put(k);
}
}
}
for(int i=1;i<=5;i++)
{
t.get();
}
}
}
class Ass9
{
public static void main(String[] args)
{
Thread1 t=new Thread1();
Producer p=new Producer(t);
Consumer c=new Consumer(t);
Thread p1 = new Thread(p);
Thread c1 = new Thread(c);
p1.start();
c1.start();
System.out.println("Press Control+c to exit");
}
}
//2BA19CS011
//LAB ASSIGNMENT-11b
import java.util.*;
interface division
{
int divby7(int n);
}
public class Ass11b
{
public static void main(String[] args)
{division d;
d=(n)->{
if((n%7)==0)
return 1;
else
return 0;
};
Scanner s=new Scanner (System.in);
System.out.println("enter the number");
int m=s.nextInt();
int res=d.divby7(m);
if (res==1)
System.out.println("The given number "+m+" is divisible by
7 ");
else
System.out.println("The given number "+m+" is not divisible
by 7 ");
}
}
//2BA19CS011
//LAB ASSIGNMENT-12
import java.util.*;
import java.util.Scanner;
class Ass12
{
public static void main(String[] args)
{
int i,j,n,t;
ArrayList<Integer> a=new ArrayList<Integer>();
n=s.nextInt();
System.out.println("enter the elements");
for(i=0;i<n;i++)
a.add(s.nextInt());
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(p[i]>p[j])
{
t=p[i];
p[i]=p[j];
p[j]=t;
}
}
}
System.out.println("sorted array is");
for(i=0;i<n;i++)
System.out.println(p[i]);
}
}