Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LOG.JAVA
- package Util;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import javafx.scene.Scene;
- import javafx.scene.control.TextArea;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- public class Log {
- public static void Logger(String logText) {
- try (FileWriter fw = new FileWriter("log.pdf", true)){
- fw.write(logText);
- }
- catch(IOException exc){
- System.out.println("Du er jo en idiot!");
- }
- }
- public static List<String> fraLog() {
- List<String> list = new ArrayList<>();
- String s = "";
- try (BufferedReader br = new BufferedReader(new FileReader("Log.pdf"))) {
- while ((s = br.readLine()) != null) {
- list.add(s + "\r\n");
- }
- } catch (IOException exc) {
- System.out.println("I/O Error: " + exc);
- }
- return list;
- }
- public static void abc(Stage secondStage){
- TextArea logText = new TextArea();
- for (String log : Log.fraLog()) {
- logText.setText(logText.getText() + log);
- StackPane secondaryLayout = new StackPane();
- secondaryLayout.getChildren().add(logText);
- Scene secondScene = new Scene(secondaryLayout, 400, 375);
- secondStage.setTitle("Log");
- secondStage.setScene(secondScene);
- secondStage.show();
- }
- }
- }
- Button btnLog = new Button("Log");
- grid.add(btnLog, 5, 5);
- btnLog.setOnAction(new EventHandler<ActionEvent>() {
- public void handle(ActionEvent event) {
- Log.abc(new Stage());
- }
- });
- Button btnClog = new Button("Clog");
- grid.add(btnClog, 5, 6);
- btnClog.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- PrintWriter writer;
- try {
- writer = new PrintWriter("log.txt");
- writer.print(" ");
- writer.close();
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- });
- package Logic;
- import java.time.LocalDateTime;
- import Util.Log;
- public class Maths implements Calculator {
- LocalDateTime tid = LocalDateTime.now();
- Double svar, tal1,tal2;
- String icon;
- public double add(double a, double b) {
- double answer = a+b;
- svar=answer;
- icon = "+";
- tal1 = a; tal2 = b;
- String tilLog =tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- public double subtract(double a, double b) {
- double answer = a-b;
- tal1 = a; tal2 = b;
- icon = "-";
- svar=answer;
- String tilLog =tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- public double multiply(double a, double b) {
- double answer = a*b;
- tal1 = a; tal2 = b;
- icon = "*";
- svar=answer;
- String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- public double divide(double a, double b) {
- double answer = a/b;
- tal1 = a; tal2 = b;
- icon = "/";
- svar=answer;
- String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar +"\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- public double power(double a, double b){
- double answer =a;
- for (int x=2; x<=b; x++){
- answer *= a;
- }
- tal1 = a; tal2 = b;
- icon = "^";
- svar=answer;
- String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- public double rod(double inputB) {
- double answer;
- answer = Math.sqrt(inputB);
- svar=answer;
- String tilLog = tid +" "+tal1+" "+icon+" = "+svar + "\r\n";
- Log.Logger(tilLog);
- return answer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement