0% found this document useful (0 votes)
25 views

Assignment

The document contains code for several methods and classes: 1) A getMax method that returns the larger of two integer parameters. 2) A Praac class with a main method that reads in two Time objects, compares their hours, minutes, and seconds to determine which time is greater. 3) A Time class with methods to read, display, and get the hour, minute, and second of a time.

Uploaded by

Akashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Assignment

The document contains code for several methods and classes: 1) A getMax method that returns the larger of two integer parameters. 2) A Praac class with a main method that reads in two Time objects, compares their hours, minutes, and seconds to determine which time is greater. 3) A Time class with methods to read, display, and get the hour, minute, and second of a time.

Uploaded by

Akashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

A.

Parameters list: int num1 , int num2


Returned value: result

Return type: int

Method header: public int getMax(int num1,int num2)

Access Modifier: public

Method Signature: getMax(int num1,int num2)

Method Body: {int result = 0;

if (num1>num2)

result = num1;

else
result = num2;

return result;}

Method name: getMax

B.

package praac;

import java.util.Scanner;

public class Praac {

public static void main(String[] args) {

Time t1 = new Time();


Time t2 = new Time();

System.out.println("Enter the first time:");

t1.readTime();

System.out.println("Enter the second time:");

t2.readTime();

System.out.println("Time 1: ");

t1.display();

System.out.println("Time 2: ");

t2.display();

if (t1.getHour() > t2.getHour()) {

System.out.println("Time 1 is greater than Time 2.");

} else if (t1.getHour() < t2.getHour()) {

System.out.println("Time 2 is greater than Time 1.");

} else {

if (t1.getMin() > t2.getMin()) {

System.out.println("Time 1 is greater than Time 2.");


} else if (t1.getMin() < t2.getMin()) {

System.out.println("Time 2 is greater than Time 1.");

} else {

if (t1.getSec() > t2.getSec()) {

System.out.println("Time 1 is greater than Time 2.");

} else if (t1.getSec() < t2.getSec()) {

System.out.println("Time 2 is greater than Time 1.");

} else {

System.out.println("Both times are equal.");

}
}class Time {

private int sec;


private int min;

private int hour;


public void readTime() {
Scanner input = new Scanner(System.in);

System.out.print("Enter hour: ");

hour = input.nextInt();

System.out.print("Enter minute: ");

min = input.nextInt();

System.out.print("Enter second: ");

sec = input.nextInt();

fixTime();

public void fixTime() {

if (sec < 0) {

sec = 0;

} else if (sec > 59) {

min += sec / 60;


sec = sec % 60;

}
if (min < 0) {

min = 0;

} else if (min > 59) {

hour += min / 60;

min = min % 60;

}if(hour<0){

hour=0;

public void display() {

System.out.printf("%02d:%02d:%02d\n", hour, min, sec);

public int getHour() {

return hour;

}
public int getMin() {

return min;

}
public int getSec() {

return sec;
}}

C1-

--Inside m2()--
--Inside main()—

C2-
0 --Inside m1()--
1 --Inside m2()--

2 --Inside m1()--
3 --Inside m2()--

4 --Inside m1()—

C3-
--Inside m1()-- x=0

--Inside m1()-- x=1


--Inside m1()-- x=4

--Inside m1()-- x=9


--Inside m1()-- x=16
C5-

a1=5

---entering m1()---

p1=105

---exiting m1()---

a1=5

C7-
a1=5

---entering m1()---

p1=105
g=10

---exiting m1()---
a1=5

g=10

C9-
---entering m1()---

g=10
---exiting m1()---

g=20

---entering m1()---
g=20

---exiting m1()---
g=40
C10-

24

248

2 4 8 16

2 4 8 16 32

2 4 8 16 32 64

You might also like