Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Lesson2/HomeWork/Task1/MeteoStation.java
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
}
}
28 changes: 27 additions & 1 deletion Lesson2/HomeWork/Task1/ST500Info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.time.*;

class ST500Info{
class ST500Info implements MeteoSensor{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы не должны трогать этот класс, считайте, что этот класс в либе от датчика

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Идея была в написании адаптера, а вы просто прикрутили интерфейс к классу.

public SensorTemperature getData(){
return new SensorTemperature(){
public int identifier(){
Expand All @@ -21,4 +21,30 @@ public int second(){
}
};
}

@Override
public int getId() {
return getData().identifier();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Но даже, если вы пишете такой "карманный адаптер", то дату надо получать от интерфейса SensorTemperature, и компоновать ее в формат интерфейса MeteoSensor

}
}
10 changes: 10 additions & 0 deletions Lesson2/HomeWork/Task2/DisplayReport.java
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());
}
}
}
10 changes: 8 additions & 2 deletions Lesson2/HomeWork/Task2/Programm.java
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);
}
}
7 changes: 3 additions & 4 deletions Lesson2/HomeWork/Task2/Report.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import java.util.*;
import java.util.*;
class Report{
private List<ReportItem> items; // Отчетные данные

Expand All @@ -9,8 +9,7 @@ public void calculate(){
items.add(new ReportItem("Second", (float)6));
}

public void output(){
PrintReport reportPrint = new PrintReport();
reportPrint.output(items);
public void output(ReportActions actions){
actions.output(items);
}
}
3 changes: 3 additions & 0 deletions Lesson2/HomeWork/Task2/ReportActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface ReportActions {
void output(List<ReportItem> items);
}