Browse Source

Umrechner von Celsius nach Kelvin

remotes/origin/develop
fdai7460 2 years ago
parent
commit
a6924a4707
  1. 52
      src/main/java/src/TasksFrame.java
  2. 6
      src/test/java/src/TasksFrameTest.java

52
src/main/java/src/TasksFrame.java

@ -69,6 +69,8 @@ public class TasksFrame extends JFrame {
setupDate();
setupTemperatur();
setupSum();
setupDiff();
@ -723,9 +725,59 @@ public class TasksFrame extends JFrame {
public double temperatur(double tem){
double x=0;
x = tem + 273.15;
x = Math.round(x * 100.0) / 100.0;
return x;
}
private void setupTemperatur()
{
JPanel jPanel = setupPanel("Temperatur Rechner");
JTextField a = new JTextField();
a.setVisible(true);
a.setBounds(10,30,35,30);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setBounds(45,35,20,20);
jLabel.setText("°C");
jLabel.setVisible(true);
jLabel.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JButton jButton = new JButton();
jButton.setText("Umwandle zum Kelvin");
jButton.setBounds(10,60,200,30);
jButton.setVisible(true);
jButton.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField result = new JTextField();
result.setBounds(10, 100, 60, 20);
result.setVisible(true);
result.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel k = new JLabel();
k.setBounds(70,100,20,20);
k.setText("K");
k.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String texta = a.getText();
double val_a = Double.valueOf(texta);
double res = temperatur(val_a);
result.setText(String.valueOf(res));
}
});
jPanel.add(a);
jPanel.add(jLabel);
jPanel.add(result);
jPanel.add(jButton);
jPanel.add(k);
}
public void setupArea()
{
JPanel jPanel = setupPanel("Area and perimeter of a Rectangle:");

6
src/test/java/src/TasksFrameTest.java

@ -30,11 +30,11 @@ class TasksFrameTest {
{
TasksFrame tasksFrame = new TasksFrame();
double x = tasksFrame.temperatur(-10.6);
assertEquals(262.55,x);
assertEquals(262.55,x, 0.01);
double x2 = tasksFrame.temperatur(8.0);
assertEquals(281.15,x2);
assertEquals(281.15,x2,0.01);
double x3 = tasksFrame.temperatur(0);
assertEquals(273.15,x3);
assertEquals(273.15,x3,0.01);
}

Loading…
Cancel
Save