Professional Documents
Culture Documents
Registration No.:20MID0080
Slot : L21+L22 Faculty
Name: Dr. Divya Laxami K
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) ;
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
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
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
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