1
0

initial AP1 + AP2 Calculation

This commit is contained in:
Joel Baldauf
2020-12-10 16:49:53 +01:00
parent 7ad2bea191
commit 81d132278e
+217 -10
View File
@@ -9,6 +9,7 @@ import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SpinnerNumberModel;
import javax.swing.JLabel;
import java.awt.TextField;
@@ -21,12 +22,17 @@ import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import javax.swing.event.ChangeListener;
import javax.swing.SpinnerModel;
public class frame extends JFrame {
private JPanel contentPane;
private JTable table;
private JScrollPane scrollPane;
// Array mit den IHK-Noten als Konstante. Das jeweilige Arrayfeld entspricht der Prozentanzahl
public static final double marksIHK[] = {6.0,6.0,6.0,6.0,6.0,6.0,5.9,5.9,5.9,5.9,5.9,5.9,5.8,5.8,5.8,5.8,5.8,5.7,5.7,5.7,5.7,5.7,5.7,5.6,5.6,5.6,5.6,5.6,5.6,5.5,5.4,5.4,5.3,5.3,5.2,5.2,5.1,5.1,5.0,5.0,5.0,4.9,4.9,4.8,4.8,4.7,4.7,4.6,4.6,4.5,4.4,4.4,4.3,4.3,4.2,4.1,4.1,4.0,4.0,3.9,3.9,3.8,3.7,3.7,3.6,3.6,3.5,3.4,3.3,3.3,3.2,3.1,3.1,3.0,2.9,2.9,2.8,2.7,2.7,2.6,2.5,2.4,2.3,2.2,2.1,2.0,2.0,1.9,1.8,1.7,1.6,1.5,1.4,1.4,1.3,1.3,1.2,1.2,1.1,1.1,1.0};
/**
* Launch the application.
*/
@@ -43,16 +49,37 @@ public class frame extends JFrame {
});
}
public static String[][] calculateMarks (int maxPoints, int totalPercentage) {
int pointPercentage = 0;
double markIHK = 0.0;
String[][] output = new String[maxPoints+1][4];
for (int point=maxPoints; point>=0; point--) {
pointPercentage = (int) (((double)point/(double)maxPoints)*(double)totalPercentage);
markIHK = marksIHK[pointPercentage];
if (totalPercentage == 100) {
output[maxPoints-point][0] = Integer.toString(point);
output[maxPoints-point][1] = Integer.toString(pointPercentage) + " %";
output[maxPoints-point][2] = String.format("%.1f", markIHK);
output[maxPoints-point][3] = String.format("%.0f", markIHK);
}
else {
output[maxPoints-point][0] = Integer.toString(point);
output[maxPoints-point][1] = Integer.toString(pointPercentage) + " %";
}
}
return output;
}
public void updateTable(JSpinner spMaxPoints, JSpinner spTotalPercentage) {
String[][] result = PunkteInNoten.calculateMarks((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
String[][] resWiso = calculateMarks((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
String[] columnNames = {"Punkte",
"Prozente",
"IHK-Note",
"ganze Note"
};
table = new JTable(result, columnNames) {
table = new JTable(resWiso, columnNames) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
@@ -64,12 +91,36 @@ public class frame extends JFrame {
}
public String[] calculatePart(int pointsA, int pointsB, int maxPointsA, int maxPointsB, boolean mitIHK) {
double percentagePartA = (0.5*(double)pointsA/(double)maxPointsA)*(double)100;
double percentagePartB = (0.5*(double)pointsB/(double)maxPointsB)*(double)100;
double totalPercentage = percentagePartA + percentagePartB;
double markIHK = marksIHK[(int)totalPercentage];
String[] resWiso = new String[6];
resWiso[0] = String.format("%.2f", percentagePartA);
resWiso[1] = String.format("%.2f", percentagePartB);
resWiso[2] = String.format("%.2f", totalPercentage);
resWiso[3] = String.format("%.0f", totalPercentage);
resWiso[4] = String.format("%.2f", markIHK);
resWiso[5] = String.format("%.0f", markIHK);
return resWiso;
}
/**
* Create the frame.
*/
public frame() {
final int pointsAP1PartA = 20;
final int pointsAP1PartB = 80;
final int pointsAP2_SEPartA = 25;
final int pointsAP2_SEPartB = 80;
final int pointsAP2_WisoPartA = 15;
final int pointsAP2_WisoPartB = 50;
final int pointsAP2_FusPartA = 25;
final int pointsAP2_FusPartB = 80;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 815, 369);
setBounds(100, 100, 815, 529);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
@@ -86,7 +137,6 @@ public class frame extends JFrame {
// 0 als Startwert, von 0 bis ..., Schrittweite 1
SpinnerNumberModel modelMaxPoints = new SpinnerNumberModel(0, 0, null, 1);
JSpinner spMaxPoints = new JSpinner(modelMaxPoints);
spMaxPoints.setBounds(14, 74, 58, 26);
contentPane.add(spMaxPoints);
@@ -107,7 +157,7 @@ public class frame extends JFrame {
});
scrollPane = new JScrollPane();
scrollPane.setBounds(399, 16, 379, 281);
scrollPane.setBounds(399, 16, 379, 422);
scrollPane.setBorder(null);
contentPane.add(scrollPane);
@@ -122,11 +172,168 @@ public class frame extends JFrame {
btnCalc.setBounds(272, 73, 91, 27);
contentPane.add(btnCalc);
JLabel lblNewLabel = new JLabel("Test");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel.setBounds(15, 12, 69, 20);
contentPane.add(lblNewLabel);
JLabel lblTest = new JLabel("Test");
lblTest.setFont(new Font("Tahoma", Font.BOLD, 18));
lblTest.setBounds(15, 12, 69, 20);
contentPane.add(lblTest);
JLabel lblAP1 = new JLabel("AP1");
lblAP1.setFont(new Font("Tahoma", Font.BOLD, 18));
lblAP1.setBounds(14, 132, 69, 20);
contentPane.add(lblAP1);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP1_PartA = new SpinnerNumberModel(0, 0, pointsAP1PartA, 1);
JSpinner spAP1_PartA = new JSpinner(modelAP1_PartA);
spAP1_PartA.setBounds(14, 183, 58, 26);
contentPane.add(spAP1_PartA);
// 0 als Startwert, von 0 bis ..., Schrittweite 1
SpinnerNumberModel modelAP1_PartB = new SpinnerNumberModel(0, 0, pointsAP1PartB, 1);
JSpinner spAP1_PartB = new JSpinner(modelAP1_PartB);
spAP1_PartB.setBounds(160, 183, 58, 26);
contentPane.add(spAP1_PartB);
JLabel lblAP1_PartA = new JLabel("Teil A");
lblAP1_PartA.setBounds(14, 157, 131, 20);
contentPane.add(lblAP1_PartA);
JLabel lblAP1_PartB = new JLabel("Teil B");
lblAP1_PartB.setBounds(160, 157, 131, 20);
contentPane.add(lblAP1_PartB);
JLabel lblAP2 = new JLabel("AP2");
lblAP2.setFont(new Font("Tahoma", Font.BOLD, 18));
lblAP2.setBounds(15, 225, 69, 20);
contentPane.add(lblAP2);
JLabel lblAP2_SE_PartA = new JLabel("Teil A");
lblAP2_SE_PartA.setBounds(40, 247, 131, 20);
contentPane.add(lblAP2_SE_PartA);
JLabel lblAP2_SE_PartB = new JLabel("Teil B");
lblAP2_SE_PartB.setBounds(160, 245, 131, 20);
contentPane.add(lblAP2_SE_PartB);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_SE_PartA = new SpinnerNumberModel(0, 0, pointsAP2_SEPartA, 1);
JSpinner spAP2_SE_PartA = new JSpinner(modelAP2_SE_PartA);
spAP2_SE_PartA.setBounds(40, 273, 58, 26);
contentPane.add(spAP2_SE_PartA);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_SE_PartB = new SpinnerNumberModel(0, 0, pointsAP2_SEPartB, 1);
JSpinner spAP2_SE_PartB = new JSpinner(modelAP2_SE_PartB);
spAP2_SE_PartB.setBounds(160, 271, 58, 26);
contentPane.add(spAP2_SE_PartB);
JLabel lblAP2_SE = new JLabel("SE");
lblAP2_SE.setFont(new Font("Tahoma", Font.BOLD, 15));
lblAP2_SE.setBounds(14, 277, 69, 20);
contentPane.add(lblAP2_SE);
JLabel lblAP2_Fus = new JLabel("Fus");
lblAP2_Fus.setFont(new Font("Tahoma", Font.BOLD, 15));
lblAP2_Fus.setBounds(14, 347, 69, 20);
contentPane.add(lblAP2_Fus);
JLabel lblAP2_Fus_PartA = new JLabel("Teil A");
lblAP2_Fus_PartA.setBounds(40, 317, 131, 20);
contentPane.add(lblAP2_Fus_PartA);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_Fus_PartA = new SpinnerNumberModel(0, 0, pointsAP2_FusPartA, 1);
JSpinner spAP2_Fus_PartA = new JSpinner(modelAP2_Fus_PartA);
spAP2_Fus_PartA.setBounds(40, 343, 58, 26);
contentPane.add(spAP2_Fus_PartA);
JLabel lblAP2_Fus_PartB = new JLabel("Teil B");
lblAP2_Fus_PartB.setBounds(160, 315, 63, 20);
contentPane.add(lblAP2_Fus_PartB);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_Fus_PartB = new SpinnerNumberModel(0, 0, pointsAP2_FusPartB, 1);
JSpinner spAP2_Fus_PartB = new JSpinner(modelAP2_Fus_PartB);
spAP2_Fus_PartB.setBounds(160, 341, 58, 26);
contentPane.add(spAP2_Fus_PartB);
JLabel lblAP2_Wiso = new JLabel("Wiso");
lblAP2_Wiso.setFont(new Font("Tahoma", Font.BOLD, 15));
lblAP2_Wiso.setBounds(3, 418, 69, 20);
contentPane.add(lblAP2_Wiso);
JLabel lblAP2_Wiso_PartA = new JLabel("Teil A");
lblAP2_Wiso_PartA.setBounds(40, 389, 131, 20);
contentPane.add(lblAP2_Wiso_PartA);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_Wiso_PartA = new SpinnerNumberModel(0, 0, pointsAP2_WisoPartA, 1);
JSpinner spAP2_Wiso_PartA = new JSpinner(modelAP2_Wiso_PartA);
spAP2_Wiso_PartA.setBounds(40, 415, 58, 26);
contentPane.add(spAP2_Wiso_PartA);
JLabel lblAP2_Wiso_PartB = new JLabel("Teil B");
lblAP2_Wiso_PartB.setBounds(160, 387, 131, 20);
contentPane.add(lblAP2_Wiso_PartB);
// 0 als Startwert, von 0 bis 20, Schrittweite 1
SpinnerNumberModel modelAP2_Wiso_PartB = new SpinnerNumberModel(0, 0, pointsAP2_WisoPartB, 1);
JSpinner spAP2_Wiso_PartB = new JSpinner(modelAP2_Wiso_PartB);
spAP2_Wiso_PartB.setBounds(160, 413, 58, 26);
contentPane.add(spAP2_Wiso_PartB);
Button btnCalcAP1 = new Button("Berechnen");
btnCalcAP1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] resWiso = calculatePart((int)spAP1_PartA.getValue(), (int)spAP1_PartB.getValue(), pointsAP1PartA, pointsAP1PartB, true);
JTextPane txtpnGesamt = new JTextPane();
txtpnGesamt.setText("AP1 \n\nAnzahl der richtig gelösten gebundenen Aufgaben " + spAP1_PartA.getValue() + ": 0,5 = " + resWiso[0] + "\n"
+ "Erreichte Punkte bei den ungebundenen Aufgaben " + spAP1_PartB.getValue() + ": 1,6 =" + resWiso[1] + "\n"
+ "Ergebnis in Punkten (max.100) \t" + resWiso[2] + "\n \t\t\t" + resWiso[3] + "\n"
+ "IHK-Note:" + resWiso[4] + "\nganze Note:" + resWiso[5]);
txtpnGesamt.setEditable(false);
txtpnGesamt.setBackground(getBackground());
scrollPane.setViewportView(txtpnGesamt);
}
});
btnCalcAP1.setBounds(272, 183, 91, 27);
contentPane.add(btnCalcAP1);
Button btnCalcAP2 = new Button("Berechnen");
btnCalcAP2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] resSE = calculatePart((int)spAP2_SE_PartA.getValue(), (int)spAP2_SE_PartB.getValue(), pointsAP2_SEPartA, pointsAP2_SEPartB, false);
String[] resFus = calculatePart((int)spAP2_Fus_PartA.getValue(), (int)spAP2_Fus_PartB.getValue(), pointsAP2_FusPartA, pointsAP2_FusPartB, false);
String[] resWiso = calculatePart((int)spAP2_Wiso_PartA.getValue(), (int)spAP2_Wiso_PartB.getValue(), pointsAP2_WisoPartA, pointsAP2_WisoPartB, false);
String textSE = "AP2\n\nSystementwurf\n=============\n"
+ "Anzahl der richtig gelösten gebundenen Aufgaben " + spAP2_SE_PartA.getValue() + ": 0,5 = " + resSE[0] + "\n"
+ "Erreichte Punkte bei den ungebundenen Aufgaben " + spAP2_SE_PartB.getValue() + ": 1,6 =" + resSE[1] + "\n"
+ "Ergebnis in Punkten (max.100) \t" + resSE[2] + "\n \t\t\t" + resSE[3] + "\n"
+ "IHK-Note:" + resSE[4] + "\nganze Note:" + resSE[5];
String textFus = "Funktions- und Systemanalyse\n=============\n"
+ "Anzahl der richtig gelösten gebundenen Aufgaben " + spAP2_Fus_PartA.getValue() + ": 0,5 = " + resFus[0] + "\n"
+ "Erreichte Punkte bei den ungebundenen Aufgaben " + spAP2_Fus_PartB.getValue() + ": 1,6 =" + resFus[1] + "\n"
+ "Ergebnis in Punkten (max.100) \t" + resFus[2] + "\n \t\t\t" + resFus[3] + "\n"
+ "IHK-Note:" + resFus[4] + "\nganze Note:" + resFus[5];
String textWiso = "Wirtschafts- und Sozialkunde\n=============\n"
+ "Anzahl der richtig gelösten gebundenen Aufgaben " + spAP2_Wiso_PartA.getValue() + ": 0,375 = " + resWiso[0] + "\n"
+ "Erreichte Punkte bei den ungebundenen Aufgaben " + spAP2_Wiso_PartB.getValue() + "* 1,2 =" + resWiso[1] + "\n"
+ "Ergebnis in Punkten (max.100) \t" + resWiso[2] + "\n \t\t\t" + resWiso[3] + "\n"
+ "IHK-Note:" + resWiso[4] + "\nganze Note:" + resWiso[5];
String output = textSE + "\n\n" + textFus + "\n\n" + textWiso + "\n";
JTextPane txtpnGesamt = new JTextPane();
txtpnGesamt.setText(output);
txtpnGesamt.setEditable(false);
txtpnGesamt.setBackground(getBackground());
scrollPane.setViewportView(txtpnGesamt);
}
});
btnCalcAP2.setBounds(272, 325, 91, 27);
contentPane.add(btnCalcAP2);
}
}