Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone explain the instructions to me and help me with the codes? Below are the codes/error and instructions. import java . util . Scanner

Can someone explain the instructions to me and help me with the codes? Below are the codes/error and instructions.

image text in transcribedimage text in transcribedimage text in transcribed
import java . util . Scanner ; 3 import java. time. LocalTime; 5 interface Alarm{ 6 public void setAlarm(String time); public void showAlarm( ) ; 8 9 abstract class Weekday implements Alarm{ 10 11 } 12 13 public class Monday extends Weekday{ 14 public void setAlarm(String time) { 15 System. out . print("Enter time for alarm in this format (HM : MM) : "); 16 Scanner sc = new Scanner (System. in) ; 17 time = sc. nextLine( ); 18 } 19 public void showAlarm( ) { 20 LocalTime alarm = LocalTime. parse(time); 21 LocalTime now = LocalTime. now( ) ; 22 if(alarm. isAfter (now) ) { 23 System. out. printIn("Alarm set tomorrow! "); 24 if (alarm. isBefore(now) ){ 25 System. out . printIn("I'll wake you up later! " ) 26 27 } 28 29 public static void main(String args) { 30 Monday monday = new Monday ( ) ; 31 monday . setAlarm(time) ; 32 monday . showAlarm( ) ; 33Result CPU Time: sec(s), Memory: kilobyte(s)compiled and executed in 0. /Monday . java : 19: error: cannot find symbol LocalTime alarm = LocalTime . parse(time); symbol : variable time location: class Monday /Monday . java:30: error: cannot find symbol monday . setAlarm(time) ; symbol: variable time location: class Monday 2 errorsProcedure: 1. Create a public class named Monday. This class shall contain the main method. 2. Define an interface (without a modifier) named Alarm. This interface shall contain two (2) void methods named setAlarm() and showAlarm(). The setAlarm() method has a String parameter named time. 3. Add two (2) classes without modifiers named Weekday (abstract) and Monday. 4. For the Weekday class, implement the Alarm interface. Leave this class empty. 5. Set Weekday as the parent of Monday. Import Scanner from java.util and LocalTime from java.time. For showAlarm(), add these two (2) statements: LocalTime alarm = LocalTime. parse(time); LocalTime now = LocalTime. now(); Explanation: parse() converts String to time, while now ( ) obtains the current time. 7. The output shall ask the user to enter the time for the alarm. If the time entered is past the current time, then display "Alarm is set for tomorrow!"; otherwise, display "I'll wake you up later!". See sample output below. Use isAfter() or isBefore() in the showAlarm() definition to compare alarm and now

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions