Skip to content

Commit adfd2d3

Browse files
committed
feat:Abstraction 1 and 2
1 parent b276d4d commit adfd2d3

File tree

5 files changed

+289
-0
lines changed

5 files changed

+289
-0
lines changed

Abstraction/abstraction_1.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package Abstraction;
2+
3+
import java.util.Scanner;
4+
5+
abstract class Shape
6+
{
7+
double len,bre,rad,side;
8+
abstract void squareArea();
9+
abstract void rectangleArea();
10+
abstract void circleArea();
11+
Shape(double len, double bre)
12+
{
13+
this.len=len;this.bre = bre;
14+
}
15+
Shape(double r)
16+
{
17+
this.rad = r;
18+
}
19+
Shape(double s,String n)
20+
{
21+
this.side = s;
22+
}
23+
}
24+
class Rect extends Shape
25+
{
26+
Rect(double len , double wid)
27+
{
28+
super(len , wid);
29+
}
30+
public void rectangleArea()
31+
{
32+
System.out.println((int)(len * bre));
33+
}
34+
public void squareArea(){}
35+
public void circleArea(){}
36+
}
37+
class Square extends Shape
38+
{
39+
40+
Square(double s, String n)
41+
{
42+
super(s , n);
43+
44+
}
45+
public void rectangleArea(){}
46+
public void squareArea(){System.out.println( (int)(side* side));}
47+
public void circleArea(){}
48+
}
49+
class Circle extends Shape
50+
{
51+
Circle(double rad)
52+
{
53+
super(rad);
54+
}
55+
56+
public void rectangleArea(){}
57+
public void squareArea(){}
58+
public void circleArea(){System.out.printf("%.2f",Math.PI * rad * rad);}
59+
}
60+
public class abstraction_1 {
61+
public static void main(String[] args) {
62+
double len,bre,side,rad;
63+
Scanner s = new Scanner(System.in);
64+
len = s.nextDouble();
65+
bre = s.nextDouble();
66+
side = s.nextDouble();
67+
rad = s.nextDouble();
68+
Shape rec = new Rect(len , bre);
69+
Shape sq = new Square(side , "s");
70+
Shape cir = new Circle(rad);
71+
rec.rectangleArea();
72+
sq.squareArea();
73+
cir.circleArea();
74+
}
75+
}

Abstraction/abstraction_2.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package Abstraction;
2+
3+
import java.util.Scanner;
4+
5+
abstract class marks
6+
{
7+
abstract void getPercentage();
8+
}
9+
class A extends marks
10+
{
11+
double marks1 , marks2, marks3;
12+
double percentA;
13+
void getPercentage()
14+
{
15+
percentA = ((marks1 + marks2 + marks3)/3);
16+
System.out.printf("%.2f\n" , percentA);
17+
}
18+
A(double m1,double m2,double m3)
19+
{
20+
this.marks1 = m1;
21+
this.marks2 = m2;
22+
this.marks3 = m3;
23+
}
24+
}
25+
class B extends A
26+
{
27+
double mark4,percentB;
28+
void getPercentage()
29+
{
30+
percentB = (marks1 + marks2 + marks3 + mark4)/4;
31+
System.out.printf("%.2f" , percentB);
32+
}
33+
B(double a,double b,double c , double d)
34+
{
35+
super(a,b,c);
36+
this.mark4 = d;
37+
}
38+
}
39+
public class abstraction_2 {
40+
public static void main(String[] args) {
41+
double m1,m2,m3,m4;
42+
Scanner s = new Scanner(System.in);
43+
m1=s.nextDouble();
44+
m2=s.nextDouble();
45+
m3=s.nextDouble();
46+
marks a = new A(m1,m2,m3);
47+
m1=s.nextDouble();
48+
m2=s.nextDouble();
49+
m3=s.nextDouble();
50+
m4=s.nextDouble();
51+
marks b = new B(m1 , m2 , m3,m4);
52+
a.getPercentage();
53+
b.getPercentage();
54+
}
55+
}

Inheritance/Matrix_Multiple.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package Inheritance;
2+
3+
import java.util.Scanner;
4+
5+
class Matrix
6+
{
7+
static int row,col;
8+
static int arr[][];
9+
Matrix(int r , int c)
10+
{
11+
Scanner s = new Scanner(System.in);
12+
row = r;
13+
col = c;
14+
this.arr = new int[row][col];
15+
for(int i=0;i<row;i++)
16+
for(int j=0;j<col;j++)
17+
arr[i][j] = s.nextInt();
18+
}
19+
20+
}
21+
class Clock
22+
{
23+
24+
}
25+
class Anticlockwise
26+
{
27+
28+
}
29+
30+
public class Matrix_Multiple {
31+
public static void main(String[] args) {
32+
Scanner s = new Scanner(System.in);
33+
int row = s.nextInt();
34+
int col = s.nextInt();
35+
Matrix m = new Matrix(row, col);
36+
}
37+
}

Inheritance/Shape_Portal.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package Inheritance;
2+
3+
import java.util.Scanner;
4+
5+
abstract class Shape
6+
{
7+
double area,peri;
8+
abstract public void setLengthAndWidth(double l,double w);
9+
abstract void display();
10+
11+
}
12+
class Square extends Shape
13+
{
14+
public void setLengthAndWidth(double l,double w)
15+
{
16+
super.area = l*l;
17+
super.peri = 4*l;
18+
}
19+
void display()
20+
{
21+
System.out.printf("Perimeter : %.2f",peri);
22+
System.out.printf("Area : %.2f",area);
23+
}
24+
}
25+
class Triangle extends Shape
26+
{
27+
public void setLengthAndWidth(double a ,double b)
28+
{
29+
30+
}
31+
public void setPoints(double a , double b , double c)
32+
{
33+
super.area = a * b * c;
34+
}
35+
void display()
36+
{
37+
System.out.printf("Perimeter : %.2f",peri);
38+
System.out.printf("Area : %.2f",area);
39+
}
40+
}
41+
class Rectangle extends Shape
42+
{
43+
double len,wid;
44+
public void setLengthAndWidth(double l,double w)
45+
{
46+
this.len = l;
47+
this.wid = w;
48+
}
49+
void display()
50+
{
51+
System.out.printf("Perimeter : %.2f",peri);
52+
System.out.printf("Area : %.2f",area);
53+
}
54+
}
55+
class Circle extends Shape
56+
{
57+
double rad;
58+
public void setLengthAndWidth(double r, double b)
59+
{
60+
rad = r;
61+
super.area = Math.PI * r * r;
62+
super.peri = Math.PI * 2 * r;
63+
}
64+
void display()
65+
{
66+
System.out.printf("Perimeter : %.2f",peri);
67+
System.out.printf("Area : %.2f",area);
68+
}
69+
}
70+
public class Shape_Portal {
71+
public static void main(String[] args) {
72+
73+
Scanner s = new Scanner(System.in);
74+
char type = s.next().charAt(0);
75+
if(type=='S')
76+
{
77+
double side = s.nextDouble();
78+
Shape sq = new Square();
79+
sq.setLengthAndWidth(side,0);;
80+
sq.display();
81+
82+
}
83+
else if(type== 'R')
84+
{
85+
double len,bre;
86+
len = s.nextDouble();
87+
bre = s.nextDouble();
88+
Shape rec = new Rectangle();
89+
rec.setLengthAndWidth(len, bre);
90+
rec.display();
91+
}
92+
else if(type== 'C')
93+
{
94+
Shape cir = new Circle();
95+
double rad = s.nextDouble();
96+
cir.setLengthAndWidth(rad, 0);
97+
cir.display();
98+
}
99+
100+
}
101+
}

multiple.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Mythread implements Runnable
2+
{
3+
int i;
4+
public void run()
5+
{
6+
int i = (int)Thread.currentThread().getId();
7+
System.out.println("Running Thread : " + (i + 2));
8+
}
9+
10+
}
11+
public class multiple {
12+
public static void main(String[] args) {
13+
Thread th[]= new Thread[5];
14+
Runnable a = new Mythread();
15+
for(int i=0;i<5;i++)
16+
{
17+
th[i] = new Thread(a);
18+
th[i].start();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)