0% found this document useful (0 votes)
68 views6 pages

Java Solve

This document contains code snippets from multiple Java programs. It includes examples of classes like Box, Complex, Add, Number_Objects that demonstrate object-oriented concepts like inheritance, constructors, and static variables. It also includes implementations of common data structures like stacks and queues using both arrays and built-in classes. Methods are defined to perform operations on these classes and data structures like calculating volume, adding numbers, and pushing/popping elements. Main methods are included to create objects, call methods, and print output to demonstrate the code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views6 pages

Java Solve

This document contains code snippets from multiple Java programs. It includes examples of classes like Box, Complex, Add, Number_Objects that demonstrate object-oriented concepts like inheritance, constructors, and static variables. It also includes implementations of common data structures like stacks and queues using both arrays and built-in classes. Methods are defined to perform operations on these classes and data structures like calculating volume, adding numbers, and pushing/popping elements. Main methods are included to create objects, call methods, and print output to demonstrate the code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//Set 1

//Question 1
import [Link];
class Box {
int length,width,height;
Box(int length,int width,int height){
[Link]=height;
[Link]=length;
[Link]=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([Link]);
[Link]("Enetr the Values: ");
int l=[Link]();
int w=[Link]();
int h=[Link]();
BoxWeight b1=new BoxWeight(l,w,h);
int h1=[Link]();
[Link](h1);

}
}

//Set 2
//Question 1(Lab Copy: Exp-3(Q-1))
class Complex {
private double re, im;
public Complex(double re, double im)
{
[Link] = re;
[Link] = im;
}
void dis(){
[Link](re+"+i."+im);
}
}
class GFG {
public static void main(String[] args)
{
Complex c1 = new Complex(10, 15);
[Link]();
}
}
//Question No 2(Lab Copy: Exp-3(Q-2))
import [Link];
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(){
[Link](this.a+this.b);
}
}
public class Set_1{
public static void main (String[] args) {
Scanner sc= new Scanner ([Link]);
[Link]("Enter 2 nos: ");
int a = [Link]();
int b = [Link]();
Add sum = new Add(a,b);
[Link]();
}
}

//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();
[Link]("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()) {
[Link]("Stack OverFlow");
[Link](1);
}
[Link]("Inserting " + x);
arr[++top] = x;
}
public int pop() {
if (isEmpty()) {
[Link]("STACK EMPTY");
[Link](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++) {
[Link](arr[i] + ", ");
}
}

public static void main(String[] args) {


Stack stack = new Stack(5);

[Link](1);
[Link](2);
[Link](3);

[Link]("Stack: ");
[Link]();
[Link]();
[Link]("\nAfter popping out");
[Link]();

}
}
//Alternate(Using Stack Class)
import [Link];
class Mai {
public static void main(String[] args) {
Stack<String> animals= new Stack<>();
[Link]("Dog");
[Link]("Horse");
[Link]("Cat");
[Link]("Stack: " + animals);
[Link]();
[Link]("Stack after pop: " + animals);
}
}
//Set-5
//Question-1(Implementing queue)
import [Link];
import [Link];
class Mai {
public static void main(String[] args) {
Queue<Integer> numbers = new LinkedList<>();
[Link](1);
[Link](2);
[Link](3);
[Link]("Queue: " + numbers);
int removedNumber = [Link]();
[Link]("Removed Element: " + removedNumber);
[Link]("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<[Link]();i++)
if ([Link](i)==' ')
count+=1;
[Link](count);
}
}

//Set-6
//Question-1
class A{
int a,b;
int c=2;
void sum(int a,int b){
[Link]("Addition="+(a+b));
}
}
class B{
int a,b;
int d=3;
void sub(int a,int b){
[Link]("Subtraction="+(a-b));
}
}
public class Main {
public static void main(String[] args) {
A a=new A();
B b=new B();
[Link](2,5);
[Link](8,2);
[Link](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();
[Link]([Link](10, 20,30));
[Link]([Link](10.11, 20.12, 30.13));
String s1="I";
String s2="am";
String s3="Tanay";
[Link]([Link](s1,s2,s3));
}
}

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

}
class Rectangle extends Shape{
void print_Area(){
[Link](d1*d2);
}
}
class Triangle extends Shape{
void print_Area(){
[Link](.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<[Link]();i++){
if([Link](i)>='A' && [Link](i)<='Z')
ans+=[Link](i);
else if([Link](i)==' ')
ans+='.';
else
continue;
}
[Link](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