A class Adder has been defined to add any two accepted time.
Example: Time A – 6 hours 35 minutes
Time B – 7 hours 45 minutes
Their sum is – 14 hours 20 minutes ( where 60 minutes = 1 hour)
The details of the members of the class are given below:
Class name:Adder
Data member/instance variable:
a[ ]:integer array to hold two elements (hours and minutes)
Member functions/methods:
Adder( ):constructor to assign 0 to the array elements
void readtime():to enter the elements of the array
void addtime( Adder X, Adder Y):adds the time of the two parameterized objects X and Y and stores the sum in the current calling object
void disptime( ):displays the array elements with an appropriate message (i.e. hours = and minutes = )
Specify the class Adder giving details of the constructor( ), void readtime( ), void addtime(Adder, Adder) and void disptime( ). Define the main( ) function to create objects and call the functions accordingly to enable the task.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram


					import java. util.Scanner;
public class Adder
    int a[]=new int[2];
    Scanner sc=new Scanner( System.in);

    void readtime()
        System.out.println("Enter hours and minutes");
        a[0]=sc. nextInt();
        a[1]=sc. nextInt();
    void disptime()
        System. out.println("Hours=" + a[0]);
        System.out.println("Minutes="  + a[ 1]);
    void addtime(Adder X,Adder Y)
        /* adds minutes */
        a[1]=X.a[1] + Y.a[1];
        /*if minutes is greater than 60 than add hours(a[1]/60) to a[0] position*/ 
        a[0] += X.a[0] + Y.a[0];
    public static void main()
        Adder ob1=new Adder(); 
        Adder ob2=new Adder();
        Adder ob3=new Adder();
        ob2.readtime() ;



Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *