initial commit
This commit is contained in:
commit
3aca31de74
40 changed files with 1701 additions and 0 deletions
11
clock/.classpath
Executable file
11
clock/.classpath
Executable file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/cs/labs.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
clock/.project
Executable file
28
clock/.project
Executable file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>1. Alarm clock</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1678721711427</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
2
clock/.settings/org.eclipse.core.resources.prefs
Normal file
2
clock/.settings/org.eclipse.core.resources.prefs
Normal file
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
26
clock/src/ClockMain.java
Normal file
26
clock/src/ClockMain.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
import clock.AlarmClockEmulator;
|
||||
import clock.io.Choice;
|
||||
import clock.io.ClockInput;
|
||||
import clock.io.ClockInput.UserInput;
|
||||
import clock.io.ClockOutput;
|
||||
|
||||
public class ClockMain {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
|
||||
ClockInput in = emulator.getInput();
|
||||
ClockOutput out = emulator.getOutput();
|
||||
|
||||
out.displayTime(15, 2, 37); // arbitrary time: just an example
|
||||
|
||||
while (true) {
|
||||
UserInput userInput = in.getUserInput();
|
||||
Choice c = userInput.choice();
|
||||
int h = userInput.hours();
|
||||
int m = userInput.minutes();
|
||||
int s = userInput.seconds();
|
||||
|
||||
System.out.println("choice=" + c + " h=" + h + " m=" + m + " s=" + s);
|
||||
}
|
||||
}
|
||||
}
|
7
clock/src/clock/io/Choice.java
Normal file
7
clock/src/clock/io/Choice.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package clock.io;
|
||||
|
||||
public enum Choice {
|
||||
SET_TIME, // user set new clock time
|
||||
SET_ALARM, // user set new alarm time
|
||||
TOGGLE_ALARM; // user pressed both buttons simultaneously
|
||||
}
|
43
clock/src/clock/io/ClockInput.java
Normal file
43
clock/src/clock/io/ClockInput.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package clock.io;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* Input signals from clock hardware.
|
||||
*
|
||||
* NOTE: you are not expected to modify this interface,
|
||||
* nor to implement it yourself. Instead, to read from
|
||||
* the emulated hardware, do as follows:
|
||||
*
|
||||
* AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
* ClockInput in = emulator.getInput();
|
||||
*
|
||||
* Then use the reference 'in' to read the input signals.
|
||||
*/
|
||||
public interface ClockInput {
|
||||
|
||||
/** @return semaphore signaled on user input (via hardware interrupt) */
|
||||
Semaphore getSemaphore();
|
||||
|
||||
/** @return an item of user input (available only when semaphore is signaled) */
|
||||
UserInput getUserInput();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** An item of input, entered by the user. */
|
||||
interface UserInput {
|
||||
/** @return a value indicating the type of choice made by the user. */
|
||||
Choice choice();
|
||||
|
||||
/**
|
||||
* These methods return a time set by the user (clock time or alarm time).
|
||||
*
|
||||
* If choice() returns SET_TIME, these return the time the user entered.
|
||||
* If choice() returns SET_ALARM, these return the alarm time the user entered.
|
||||
* If choice() returns TOGGLE_ALARM, these return an invalid value.
|
||||
*/
|
||||
int hours();
|
||||
int minutes();
|
||||
int seconds();
|
||||
}
|
||||
}
|
26
clock/src/clock/io/ClockOutput.java
Normal file
26
clock/src/clock/io/ClockOutput.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package clock.io;
|
||||
|
||||
/**
|
||||
* Output signals to clock hardware.
|
||||
*
|
||||
* NOTE: you are not expected to modify this interface,
|
||||
* nor to implement it yourself. Instead, to control
|
||||
* the emulated hardware, do as follows:
|
||||
*
|
||||
* AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
* ClockInput out = emulator.getoutput();
|
||||
*
|
||||
* Then use the reference 'out' to control the output signals.
|
||||
*/
|
||||
public interface ClockOutput {
|
||||
|
||||
/** Display the given time on the display, for example (15, 2, 37) for
|
||||
15 hours, 2 minutes and 37 seconds since midnight. */
|
||||
void displayTime(int hours, int mins, int secs);
|
||||
|
||||
/** Indicate on the display whether the alarm is on or off. */
|
||||
void setAlarmIndicator(boolean on);
|
||||
|
||||
/** Signal the alarm. (In the emulator, only a visual alarm is given.) */
|
||||
void alarm();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue