Last active
February 19, 2023 13:50
-
-
Save dkrutskikh/d29031ee2050041119520f8da4b2bed8 to your computer and use it in GitHub Desktop.
code review
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// нужно сгенерировать 100 случайных чисел в диапазоне -50 до 50 | |
// если число положительное - вывести в консоль | |
// если отрицательно - вывести в stderr | |
// все числа логировать в файл | |
import 'dart:io'; | |
import 'dart:math'; | |
void main() { | |
Console console = Console(); | |
FileOutput fileOutput = FileOutput('out.txt'); | |
for (int i = 0; i < 100; i++) { | |
int value = Random().nextInt(100) - 50; | |
if (value >= 0) { | |
fileOutput.writeToFile(value); | |
console.write(value); | |
} else { | |
fileOutput.writeToFile(value); | |
stderr.writeln('$value'); | |
} | |
} | |
} | |
class Console { | |
IOSink out = stdout; | |
void write(int value) { | |
out.writeln(value.toString()); | |
} | |
} | |
class ErrorConsole { | |
void writeError(String text) { | |
stderr.writeln(text); | |
} | |
} | |
class FileOutput { | |
File out; | |
FileOutput(String reportPath) : out = File(reportPath); | |
void writeToFile(Object value) { | |
out.writeAsString(value.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment