You are on page 1of 6

//Set 1

//Question 1
import java.util.Scanner;
class Box {
int length,width,height;
Box(int length,int width,int height){
this.height=height;
this.length=length;
this.width=width;

}
int vol(){
return (length*width*height);
}
}
class BoxWeight extends Box{
int a,b,c;
BoxWeight(int a,int b, int c) {
super(a,b,c);
//super(length,width,height);
}
}
public class Set_1{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enetr the Values: ");
int l=sc.nextInt();
int w=sc.nextInt();
int h=sc.nextInt();
BoxWeight b1=new BoxWeight(l,w,h);
int h1=b1.vol();
System.out.println(h1);

}
}

//Set 2
//Question 1(Lab Copy: Exp-3(Q-1))
class Complex {
private double re, im;
public Complex(double re, double im)
{
this.re = re;
this.im = im;
}
void dis(){
System.out.println(re+"+i."+im);
}
}
class GFG {
public static void main(String[] args)
{
Complex c1 = new Complex(10, 15);
c1.dis();
}
}
//Question No 2(Lab Copy: Exp-3(Q-2))
import java.util.Scanner;
class Add {
int a, b;

Add(int a, int b) {
this.a = a;
this.b = b;
}
Add(Add sum) {
this.a = sum.a;
this.b = sum.b;
}
void dis(){
System.out.println(this.a+this.b);
}
}
public class Set_1{
public static void main (String[] args) {
Scanner sc= new Scanner (System.in);
System.out.println("Enter 2 nos: ");
int a = sc.nextInt();
int b = sc.nextInt();
Add sum = new Add(a,b);
sum.dis();
}
}

//Question 3
public class Number_Objects
{
static int count=0;
Number_Objects()
{
count++;
}
public static void main(String[] args)
{
Number_Objects obj1 = new Number_Objects();
Number_Objects obj2 = new Number_Objects();
Number_Objects obj3 = new Number_Objects();
Number_Objects obj4 = new Number_Objects();
System.out.println("Number of objects created:"+count);
}
}

//Set 3
Last question of Lab report
//Set 4
//Question -1(Experiment -1(Lab Copy Expt-5))
//Question -2(Implementing Stack)
// Stack implementation in Java

class Stack {
private int arr[];
private int top;
private int capacity;
Stack(int size) {
arr = new int[size];
capacity = size;
top = -1;
}
public void push(int x) {
if (isFull()) {
System.out.println("Stack OverFlow");
System.exit(1);
}
System.out.println("Inserting " + x);
arr[++top] = x;
}
public int pop() {
if (isEmpty()) {
System.out.println("STACK EMPTY");
System.exit(1);
}
return arr[top--];
}
public int getSize() {
return top + 1;
}
public Boolean isEmpty() {
return top == -1;
}
public Boolean isFull() {
return top == capacity - 1;
}
public void printStack() {
for (int i = 0; i <= top; i++) {
System.out.print(arr[i] + ", ");
}
}

public static void main(String[] args) {


Stack stack = new Stack(5);

stack.push(1);
stack.push(2);
stack.push(3);

System.out.print("Stack: ");
stack.printStack();
stack.pop();
System.out.println("\nAfter popping out");
stack.printStack();

}
}
//Alternate(Using Stack Class)
import java.util.Stack;
class Mai {
public static void main(String[] args) {
Stack<String> animals= new Stack<>();
animals.push("Dog");
animals.push("Horse");
animals.push("Cat");
System.out.println("Stack: " + animals);
animals.pop();
System.out.println("Stack after pop: " + animals);
}
}
//Set-5
//Question-1(Implementing queue)
import java.util.Queue;
import java.util.LinkedList;
class Mai {
public static void main(String[] args) {
Queue<Integer> numbers = new LinkedList<>();
numbers.offer(1);
numbers.offer(2);
numbers.offer(3);
System.out.println("Queue: " + numbers);
int removedNumber = numbers.poll();
System.out.println("Removed Element: " + removedNumber);
System.out.println("Queue after deletion: " + numbers);
}
}

//Question-2
class T{
public static void main(String[] args) {
int count=1;
String str=new String("I am going to school");
for (int i=0;i<str.length();i++)
if (str.charAt(i)==' ')
count+=1;
System.out.println(count);
}
}

//Set-6
//Question-1
class A{
int a,b;
int c=2;
void sum(int a,int b){
System.out.println("Addition="+(a+b));
}
}
class B{
int a,b;
int d=3;
void sub(int a,int b){
System.out.println("Subtraction="+(a-b));
}
}
public class Main {
public static void main(String[] args) {
A a=new A();
B b=new B();
a.sum(2,5);
b.sub(8,2);
System.out.println(a.c*b.d);
}
}
//Question-2
class Sum {
String sum(String x, String y,String z) {
return (x+y+z);
}
int sum(int x, int y, int z)
{
return (x + y + z);
}
double sum(double x, double y,double z)
{
return (x + y+z);
}
public static void main(String args[])
{
Sum s = new Sum();
System.out.println(s.sum(10, 20,30));
System.out.println(s.sum(10.11, 20.12, 30.13));
String s1="I";
String s2="am";
String s3="Tanay";
System.out.println(s.sum(s1,s2,s3));
}
}

//Set-7
//Question - 1
class Shape{
int d1=5,d2=6;

}
class Rectangle extends Shape{
void print_Area(){
System.out.println(d1*d2);
}
}
class Triangle extends Shape{
void print_Area(){
System.out.println(.5*d1*d2);
}
}
class Result{
public static void main(String[] args){
Rectangle rc=new Rectangle();
Triangle tc=new Triangle();
rc.print_Area();
tc.print_Area();
}
}

//Question 2
public class Abrige {
public static void main(String[] args){
String str="Raja Rammohan Roy";
String ans="";
for (int i=0;i<str.length();i++){
if(str.charAt(i)>='A' && str.charAt(i)<='Z')
ans+=str.charAt(i);
else if(str.charAt(i)==' ')
ans+='.';
else
continue;
}
System.out.println(ans);
}
}
//Set - 8
//Question 1(Lab copy Exp-3(Question -4(Age Calculator)))
//Question 2
Question is Misleading
//Set - 9
//Question 1(Lab copy Exp-4(Question -2))
//Question 2(Lab copy Exp-2(Question -4))

You might also like