Repository navigation
Expand file tree
/
Copy pathCalculationWorker.java
More file actions
73 lines (60 loc) · 1.89 KB
/
Copy pathCalculationWorker.java
File metadata and controls
73 lines (60 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.practic;
import com.mycompany.practic.Exceptions.ExitException;
import com.mycompany.practic.calculation.*;
import java.util.Scanner;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
/**
*
* @author igore
*/
public class CalculationWorker {
CalculationResult result;
CalculationMakerInterface maker;
CalculationViewInterface view;
Scanner in = new Scanner(System.in);
double v = 0;
double t = 0;
double alpha = 0;
CalculationWorker(){
maker = new CalculationMaker();
}
public void setV () throws ExitException {
System.out.println("Please enter v: ");
this.v = Double.parseDouble(getInput());
}
public void setT () throws ExitException {
System.out.println("Please enter t: ");
this.t = Double.parseDouble(getInput());
}
public void setAlpha () throws ExitException {
System.out.println("Please enter alpha: ");
this.alpha = Double.parseDouble(getInput());
}
public void calculateAndShowResult() throws ExitException{
calculate();
showResult();
}
public void showResult(){
view.ViewResults();
}
public void calculate() throws ExitException{
tryGetVaribles();
result = maker.calculate(v, t, alpha);
view = new CalculationView(result);
}
private void tryGetVaribles() throws ExitException {
if(v == 0) setV();
if(t == 0) setT();
if(alpha == 0) setAlpha();
}
private String getInput() throws ExitException{
String res = in.nextLine();
if(res == "exit") throw new ExitException();
return res;
}
}