You are on page 1of 15

Name:ALINA HASAN

Registration No.:20MID0080
Slot : L21+L22 Faculty
Name: Dr. Divya Laxami K

code and output


code and output
code and output
code and output
code and output

code and output


code and output
code and output
. Time
Variables- hours, minutes, seconds which corresponds to time of a day
Method Name Description
all the variables initialized to zero
Time0
Time (int.int, int) initializes with the given hours. minutes
andseconds values
add(Time) adds two time values

Code:
5 class me

i n hourss
t
int
min
sec;
public void time()¬
his.hours
this.min = e;
t h i s . sec = ®;
System. out.println (this . hours " : "*this . min+" : "*this. sec) ;

public void time(int hr, int mi, int se)(


2t(hr>25 T min,39.1ec
System.out. println("Invalid Input");
th:
lseours
" urs nri
mij
hi
22
23
System.out.println (this. hours+": "+this . min+"; "+this. sec);
24

25 public void add(Time t)(


26 int hr =
t.hours
this.hours;
27 int min t.min this.min;
28 int sec = t.sec this. sec;
29 if(sec>59)(
min+=l;
sec sec 60,
32
33 if(min>59) (
34
hr+=l
36
min= min-68
37
if(hr>23)(
38 Dr hr-24;

39
40 System.out. intin("New time= "+hr+": "*min+": "+sec);

14 class DApartB(
public
public static void main(strinElI args) {

annerSC
Tme t =
newScanner(System.in);
new Time ();
t1.time()i
t1.time(23,
Time t 2 =
42, 30); new
Time ();
t2.time(22, 55, 34);
t2.add(ti);
0:0:0
23:42:30
22:55:34
New time 22:38:4

12. Point

Variables -xco-ordinate. y-co-ordinate values ofapoint


Method Name Description
Point) initializeXand y co-ordinates to 0
Point(double, double) initialize x and y coordinates to given
values
distance(Point) Find the Euclidean distance between two
point objects
Code:

44 elass Point{
15 int x,y;
46 public void point(){
47 this.x = 0;
48 this.y 0
9 System.out.printIn (this.x*","+this .y);
51 public void point(int a,int b){
2 this.x = a,
53 this.y = b;
54 System.out.println(this.x*", "+this.y);
5
S69 public void distance (Point p){
this.x = this.x Pp.x;
8 this.y =

this.y - p.y;
9 System.out.println("New point: "+this.x+", "+this.y);
60
61

98 public elass DApartB{


99 public static void main(String[] args){
l60 Scanner sc = new Scanner (System. in) ;
LO
102 Point pl= new Point();
103 p1.point();
104
pl.point
Point
(16, 16);
105 p2 new Point();
106 p2.point(45,45);
167 p2.distance(pl)
0,0
16,16
45,,45
New point: 29,29

13. Circle
Variables radius of the circle_
Method Name Description
Circle) Initializeradius to -I
Initialize radius to the given value
Circle(double)
double Area() Return the area of the circle

Code:

63 class Circle{
b4 double r
65 public void circle(0{
this.r -1;
67 System.out.println(this.r);
68
69 public void circle(double r1)
this.r = rl;
1
/2
System.out.println(this.r);
73 public double area(){
4 double area = Math.PI*this.r*this.r;
75 return area;
76

78
98 public class DApartB{
99 public static void main(String[] args)
Scanner sc = new Scanner(System. in);
L01
L02 Circle c1 =
new Circle();
L03 c1.circle();
L04 c1.circle (5) ;
L05
System.out.printf("%.26",c1.area());
-1.0
5.0
78.5

14. Complex number

Variables -real part,imaginary parts ofacomplex number


Method Name Description
Complex Number() Initialize real and imaginary parts to zero
ComplexNumber(double, double) Initialize real and imaginary with given
double values_
Magnitude(0 Return the magnitude from the given real
andimaginary parts
Code:

class complex{
double x;
double y

public complex(){
this.x=0
11
this.y=0
12
System.out.println (this. x+"+"+this.y+'j');
13 public complex(double a , double b ){
14 this.x=a;
15 this.y=b;
16
17
18 public void mag(){
19 double l = (x*x * y*y);
20
21
double q =
Math.abs(Math.sqrt(1));
System.out.println (q);
22
23
24
25 public class ComplexNumber {
26 public static void main(String[] args) {
27 complex x1 new =
complex(6,10);
28
29
x1.mag()
30
11.661903789690601

15. Rectangle
Variables- length, breadth values of the
rectangle
Method Name Description
Rectangle()0 Initialize length and breadth values to zero
Rectangle(double, double) Initial1ze length and breadth with the given
values
double
Area()_ Return the area of the rectangle

Code:

79 class Rectangle{
80 double 1;
81 double b;
82 public void rectangle (){
83 this.l = 0;
84 this.b = 8;
85
86
System.out.printIn("Length"+this.l+", "+"Breadth"+this .b);
87 public void rectangle (double 11,double b1){
88 this.l = T1,
9 this.b b1;
System.out.println("Length"+this.l+", "+"Breadth"+this.b) ;
91
92 public double area(){
93 double area this.1*this.b;
94 return area;
95
96
97
98 public class DApartB{
static void {
99
100
public
Scanner SC
main(String[] args)
new Scanner(System.in);
101
102 Rectangle rl = new
Rectangle ();
103 r1.rectangle ();
104
r1.rectangle (5,10));
105
System.out.printf("%.26*,r1.area()):
'

Output:
Lengthe.0,Breadthe.0
Length5.0, Breadth10.0
50.600

You might also like