Java Report 2
Java Report 2
COLLEGE OF ENGINEERING
SULLIA, D.K. – 574327, KARNATAKA
LABORATOTY REPORT
ON
OBJECT ORIENTED PROGRAMMING WITH JAVA (BCS306)
Submitted by
Name:Lismitha CP
USN:4KV23CI026
SEMESTER:3RD
Submitted to
PROF.SINDHU V
Professor, Dept. of CS &Engg.
Matrix multiplication
import java.util.Scanner;
{
int m,n;
m=scan.nextInt();
n=scan.nextInt();
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[j][j]=scan.nextInt();
System.out.println("");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
b[i][j]=scan.nextInt();
}
c[i][j]=a[i][j]+b[i][j];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
System.out.println(c[i][j]+"");
System.out.println("");
}
Stack demo
import java.util.Scanner;
class Stack
int top=-1;
int size=3;
void push(int i)
if(top==size-1)
System.out.println("Stack overflow");
else
s[++top]=i;
void pop()
if(top==-1)
System.out.println("Stack underflow");
else
System.out.println("Popped elements="+s[top]);
top--;
void display()
if(top==-1)
System.out.println("Stack is empty\n");
else
{
for(int i=top;i>=0;i--)
System.out.println(s[i]);
for(;;)
System.out.println("\n---Stack operation---");
System.out.println("1. Push");
System.out.println("2. Pop");
System.out.println("3. Display");
System.out.println("4. Exit");
int choice=scan.nextInt();
switch(choice)
case 1:
break;
case 2: stk.pop();
break;
case 3: stk.display();
break;
case 4: System.exit(0);
default:
System.out.println("Invalid choice\n");
break;
}
Employee demo
class Employee{
this.id=id;
this.name=name;
this.salary=salary;
if(percent>0){
double raiseAmount=salary*(percent/100);
salary+=raiseAmount;
}else{
System.out.println(emp);
double percent=sc.nextDouble();
emp.raiseSalary(percent);
System.out.println(emp);
}
Point demo
· A method called distance(int x, int y) that returns the distance from this
point to another point at the given(x,y) coordinate.
· Another overloaded distance() method that returns the distance from this
point to the origin (0,0).
Develop the code for the class MyPoint also develop a Java program(called Test
MyPoint) to test all the Methods defined in the class.
package pointdemo;
class MyPoints{
int x;
int y;
public MyPoints()
this.x=0;
this.y=0;
this.x=m;
this.y=n;
{
this.x=m;
this.y=n;
int[] coordinates={this.x,this.y};
return coordinates;
int Xdiff=this.x-m;
int Ydiff=this.y-n;
return Math.sqrt(Xdiff*Xdiff+Ydiff*Ydiff);
return distance(another.x,another.y);
{
return distance(0,0);
System.out.println("point1:"+point1);
System.out.println("point2:"+point2);
point1.setXY(3,4);
int[] coordinates=point2.getXY();