-
Notifications
You must be signed in to change notification settings - Fork 15
Hw 2 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Hw 2 #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| public class MeteoStation{ | ||
| public class MeteoStation{ | ||
| public static void main(String[] args){ | ||
| MeteoStore meteoDb = new MeteoStore(); | ||
|
|
||
| MeteoSensor ms200_1 = new MS200(1); | ||
| meteoDb.save(ms200_1); | ||
|
|
||
| MeteoSensor st500 = new ST500Info(); | ||
| meteoDb.save(st500); | ||
|
|
||
| // Здесь надо вызвать метод getData у класса ST500Info. Полученные данные отправить в метод save объекта meteoDb | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import java.time.*; | ||
|
|
||
| class ST500Info{ | ||
| class ST500Info implements MeteoSensor{ | ||
| public SensorTemperature getData(){ | ||
| return new SensorTemperature(){ | ||
| public int identifier(){ | ||
|
|
@@ -21,4 +21,30 @@ public int second(){ | |
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public int getId() { | ||
| return getData().identifier(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А если идентификатор тоже будет равен 1? |
||
| } | ||
|
|
||
| @Override | ||
| public Float getTemperature() { | ||
| double temperature = getData().temperature(); | ||
| return (float) temperature; | ||
| } | ||
|
|
||
| @Override | ||
| public Float getHumidity() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Float getPressure() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public LocalDateTime getDateTime() { | ||
| return LocalDateTime.now(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но даже, если вы пишете такой "карманный адаптер", то дату надо получать от интерфейса SensorTemperature, и компоновать ее в формат интерфейса MeteoSensor |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| public class DisplayReport implements ReportActions { | ||
|
|
||
| @Override | ||
| public void output(List<ReportItem> items) { | ||
| System.out.println("Output on display"); | ||
| for(ReportItem item : items){ | ||
| System.out.format("display %s - %f \n\r", item.getDescription(), item.getAmount()); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| class Programm{ | ||
| public static void main(String[] args){ | ||
| public static void main(String[] args){ | ||
|
|
||
| ReportActions print = new PrintReport(); | ||
| ReportActions display = new DisplayReport(); | ||
|
|
||
| Report report = new Report(); | ||
| report.calculate(); | ||
| report.output(); | ||
|
|
||
| report.output(print); | ||
| report.output(display); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| public interface ReportActions { | ||
| void output(List<ReportItem> items); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мы не должны трогать этот класс, считайте, что этот класс в либе от датчика
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Идея была в написании адаптера, а вы просто прикрутили интерфейс к классу.