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
36 changes: 36 additions & 0 deletions Lesson2/HomeWork/Task1/Adapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package task1sensors;

import java.time.LocalDateTime;

public class Adapter implements MeteoSensor {
ST500Info sensor;

public Adapter(ST500Info sensor) {
this.sensor = sensor;
}

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

@Override
public Float getTemperature() {
return (float)sensor.getData().temperature();
}

@Override
public Float getHumidity() {
return 0f;
}

@Override
public Float getPressure() {
return 0f;
}

@Override
public LocalDateTime getDateTime() {
return LocalDateTime.now();
}
}
43 changes: 22 additions & 21 deletions Lesson2/HomeWork/Task1/MS200.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package task1sensors;
import java.time.*;

public class MS200 implements MeteoSensor{
int id;
public MS200(int id){
this.id = id;
}
public int getId(){
return id;
}
public Float getTemperature(){
return (float)20;
}
public Float getHumidity(){
return (float)60;
}
public Float getPressure(){
return (float)752.4;
}
public LocalDateTime getDateTime(){
return LocalDateTime.now();
}
int id;

public MS200(int id){
this.id = id;
}

public int getId(){
return id;
}
public Float getTemperature(){
return (float)20;
}
public Float getHumidity(){
return (float)60;
}
public Float getPressure(){
return (float)752.4;
}
public LocalDateTime getDateTime(){
return LocalDateTime.now();
}
}
18 changes: 10 additions & 8 deletions Lesson2/HomeWork/Task1/MeteoSensor.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import java.time.*;
package task1sensors;

public interface MeteoSensor{
int getId(); // идентификатор датчика
Float getTemperature(); // температура датчика
Float getHumidity(); // влажность
Float getPressure(); // давление
LocalDateTime getDateTime(); // время чтения данных датчика
}
import java.time.LocalDateTime;

public interface MeteoSensor {
int getId(); // идентификатор датчика
Float getTemperature(); // температура датчика
Float getHumidity(); // влажность
Float getPressure(); // давление
LocalDateTime getDateTime(); // время чтения данных датчика
}
27 changes: 17 additions & 10 deletions Lesson2/HomeWork/Task1/MeteoStation.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
public class MeteoStation{
public static void main(String[] args){
MeteoStore meteoDb = new MeteoStore();

MeteoSensor ms200_1 = new MS200(1);
meteoDb.save(ms200_1);

// Здесь надо вызвать метод getData у класса ST500Info. Полученные данные отправить в метод save объекта meteoDb
}
}
package task1sensors;

public class MeteoStation {
public static void main(String[] args){
MeteoStore meteoDb = new MeteoStore();

MeteoSensor ms200_1 = new MS200(1);
ST500Info st500_2 = new ST500Info();

Adapter adapter = new Adapter(st500_2);

meteoDb.save(ms200_1);
meteoDb.save(adapter);

// Здесь надо вызвать метод getData у класса ST500Info. Полученные данные отправить в метод save объекта meteoDb
}
}
15 changes: 8 additions & 7 deletions Lesson2/HomeWork/Task1/MeteoStore.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class MeteoStore{
// сохранение данных в базу
boolean save(MeteoSensor meteoSensor){
System.out.format("Saving data from sensor [%d] at %s%n temperature - %f ; humidity - %f ; pressure - %f \n\r", meteoSensor.getId(), meteoSensor.getDateTime(), meteoSensor.getTemperature(), meteoSensor.getHumidity(), meteoSensor.getPressure());
return true;
}
}
package task1sensors;

public class MeteoStore {
boolean save(MeteoSensor meteoSensor){
System.out.format("Saving data from sensor [%d] at %s%n temperature - %f ; humidity - %f ; pressure - %f \n\r", meteoSensor.getId(), meteoSensor.getDateTime(), meteoSensor.getTemperature(), meteoSensor.getHumidity(), meteoSensor.getPressure());
return true;
}
}
48 changes: 25 additions & 23 deletions Lesson2/HomeWork/Task1/ST500Info.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import java.time.*;
package task1sensors;

class ST500Info{
public SensorTemperature getData(){
return new SensorTemperature(){
public int identifier(){
return 1;
}
public double temperature(){
return 22.0;
}
public int year(){
return LocalDateTime.now().getYear();
}
public int day(){
return LocalDateTime.now().getDayOfYear();
}
public int second(){
LocalDateTime now = LocalDateTime.now();
return now.getHour()*3600 + now.getMinute()*60 + now.getSecond();
}
};
}
}
import java.time.LocalDateTime;

public class ST500Info {
public SensorTemperature getData(){
return new SensorTemperature(){
public int identifier(){
return 1;
}
public double temperature(){
return 22.0;
}
public int year(){
return LocalDateTime.now().getYear();
}
public int day(){
return LocalDateTime.now().getDayOfYear();
}
public int second(){
LocalDateTime now = LocalDateTime.now();
return now.getHour()*3600 + now.getMinute()*60 + now.getSecond();
}
};
}
}
16 changes: 9 additions & 7 deletions Lesson2/HomeWork/Task1/SensorTemperature.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
interface SensorTemperature{
int identifier(); // идентификатор датчика
double temperature(); // температура датчика
int year(); // Год
int day(); // День года
int second(); // Секунда дня
package task1sensors;

interface SensorTemperature {
int identifier(); // идентификатор датчика
double temperature(); // температура датчика
int year(); // Год
int day(); // День года
int second(); // Секунда дня

}

19 changes: 19 additions & 0 deletions Lesson2/HomeWork/Task2/PrintDecorator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package task2report_print;

import java.util.List;

public class PrintDecorator extends Report {
void showOnMonitor(){
System.out.println("Output to monitor");
for(ReportItem item : items){
System.out.format("* %s - %f \n\r", item.getDescription(), item.getAmount());
}
}

void saveToFile(String file){
System.out.println("Saving to file: " + file);
for(ReportItem item : items){
System.out.format("%s - %f \n\r", item.getDescription(), item.getAmount());
}
}
}
21 changes: 12 additions & 9 deletions Lesson2/HomeWork/Task2/PrintReport.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import java.util.*;
class PrintReport{
public void output(List<ReportItem> items){
System.out.println("Output to printer");
for(ReportItem item : items){
System.out.format("printer %s - %f \n\r", item.getDescription(), item.getAmount());
}
}
}
package task2report_print;

import java.util.List;

public class PrintReport {
public void output(List<ReportItem> items){
System.out.println("Output to printer");
for(ReportItem item : items){
System.out.format("printer %s - %f \n\r", item.getDescription(), item.getAmount());
}
}
}
26 changes: 19 additions & 7 deletions Lesson2/HomeWork/Task2/Programm.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
class Programm{
public static void main(String[] args){
Report report = new Report();
report.calculate();
report.output();
}
}
package task2report_print;

import java.time.LocalDateTime;

public class Programm {
public static void main(String[] args){


// Report report = new Report();
// report.calculate();
// report.output();

PrintDecorator report = new PrintDecorator();
report.calculate();
report.output();
report.saveToFile("C:/reports/"+ LocalDateTime.now().toString()+".txt");
report.showOnMonitor();
}
}
36 changes: 20 additions & 16 deletions Lesson2/HomeWork/Task2/Report.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import java.util.*;
class Report{
private List<ReportItem> items; // Отчетные данные

// расчет отчетных данных
public void calculate(){
items = new ArrayList<ReportItem>();
items.add(new ReportItem("First", (float)5));
items.add(new ReportItem("Second", (float)6));
}

public void output(){
PrintReport reportPrint = new PrintReport();
reportPrint.output(items);
}
}
package task2report_print;

import java.util.ArrayList;
import java.util.List;

public class Report {
protected List<ReportItem> items; // Отчетные данные

// расчет отчетных данных
public void calculate(){
items = new ArrayList<ReportItem>();
items.add(new ReportItem("First", (float)5));
items.add(new ReportItem("Second", (float)6));
}

public void output(){
PrintReport reportPrint = new PrintReport();
reportPrint.output(items);
}
}
32 changes: 17 additions & 15 deletions Lesson2/HomeWork/Task2/ReportItem.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
class ReportItem{
private String description;
private float amount;

public ReportItem(String description, float amount){
this.description = description;
this.amount = amount;
}
public String getDescription(){
return description;
}
public float getAmount(){
return amount;
}
}
package task2report_print;

public class ReportItem {
private String description;
private float amount;

public ReportItem(String description, float amount){
this.description = description;
this.amount = amount;
}
public String getDescription(){
return description;
}
public float getAmount(){
return amount;
}
}
Loading