What's new

Java Wake Up! activity

chaekayeon

Leecher
Joined
Oct 6, 2021
Posts
13
Reaction
1
1638515460286.png


I've already take no.1 to no.4 pero yung number 5 and 6 ones ang biggest concern ko lang po. I need some help for this.
 

Attachments

iyeah

Leecher
Penge source

Penge source po :)
import java.util.Scanner;
import java.time.LocalTime;

abstract class Weekday implements Alarm{

}
public class Monday extends Weekday{

private String time;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Monday mon = new Monday();

String alarm;
System.out.print("Enter time for alarm in this format (HH:MM): ");
alarm = scan.nextLine();

mon.setAlarm(alarm);
mon.showAlarm();
}

public void setAlarm(String time) {
this.time = time;
LocalTime alarm = LocalTime.parse(time);
LocalTime now = LocalTime.now();

if (alarm.isBefore(now)) {
System.out.println("Alarm is set for tomorrow!");
}
else {
System.out.println("I'll wake you up later!");
}
}

public String showAlarm() {
return time;
}
}

interface Alarm {
void setAlarm(String time);
String showAlarm();
}
 
Last edited:
Top