Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the member function of Tiktok below, assume this being done in a separ

ID: 3756049 • Letter: I

Question

Implement the member function of Tiktok below, assume this being done in a separate source file. Be as neat and syntactically correct as possible.
a) Constructor :


b) addSeconds:



c) addMinutes:



d) addHours:



e) display24:


f) display12:







Implement the member function of Tiktok below, assume this being done in a separate source file. Be as neat and syntactically correct as possible.
a) Constructor :


b) addSeconds:



c) addMinutes:



d) addHours:



e) display24:


f) display12:








a) Constructor :


b) addSeconds:



c) addMinutes:



d) addHours:



e) display24:


f) display12:







Explanation / Answer

Please refer below code for the given requirement.

I have added comments also to understand in better way.

//Code for the given requirement

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class Test {

int seconds, minutes, hours;

Calendar calendar = Calendar.getInstance();

Date date = new Date();

SimpleDateFormat simpDate;

// Constructor to initialize the values

public Test(int seconds, int minutes, int hours) {

this.seconds = seconds;

this.minutes = minutes;

this.hours = hours;

}

// Add seconds

public void addSeconds() {

calendar.add(Calendar.SECOND, seconds);

System.out.println("Updated = " + calendar.getTime());

}

// Add minutes

public void addMinutes() {

calendar.add(Calendar.MINUTE, minutes);

System.out.println("Updated = " + calendar.getTime());

}

// Add hours

public void addHours() {

calendar.add(Calendar.HOUR, hours);

System.out.println("Updated = " + calendar.getTime());

}

// Display time in 24 format

public void display24() {

simpDate = new SimpleDateFormat("kk:mm:ss");

System.out.println(simpDate.format(date));

}

// Display time in 12 format

public void display12() {

simpDate = new SimpleDateFormat("k:mm:ss");

System.out.println(simpDate.format(date));

}

}