/
V.S.Femit
/
Lab1
Обзор
Документация
Войти
/
V.S.Femit
/
Lab1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/example/lab1/Signal.java
45 строк
1 KB
V.S.Femit
upload files
02 фев 2026, 11:19
Верифицирован
02 фев 2026, 11:19
44f5903
Код
Авторство
О чём код?
package com.example.lab1; public class Signal implements IObserver { private Subject subject; private int count; private int start; private boolean state; private int targetTime; public Signal(Subject subject, int interval) { this.subject = subject; this.subject.attach(this); this.count = interval; this.state = true; this.start = ((TimeServer) subject).getState(); this.targetTime = start + count; } @Override public void update(Subject subject) { if (!state) return; int currentTime = ((TimeServer) subject).getState(); if (currentTime >= targetTime) { System.out.println("Signal: Воспроизведение звука в " + currentTime + " секунд"); targetTime += count; } } public void onComp(int count) { this.count = count; this.state = true; this.targetTime = ((TimeServer) subject).getState() + count; } public void offComp() { this.state = false; } public void detach() { subject.detach(this); offComp(); } }