added totalAP2Calc and comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//Import der für die GUI benötigten Bibliotheken
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -23,18 +23,21 @@ import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.Font;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.SpinnerModel;
|
||||
|
||||
|
||||
public class frame extends JFrame {
|
||||
|
||||
//Deklaration von Content Pane, der Tabelle sowie des Scroll Panes; werden später gefüllt
|
||||
private JPanel contentPane;
|
||||
private JTable table;
|
||||
private JScrollPane scrollPane;
|
||||
|
||||
// Array mit den IHK-Noten als Konstante. Das jeweilige Arrayfeld entspricht der Prozentanzahl
|
||||
// Array mit den IHK-Noten. Das jeweilige Arrayfeld entspricht der Prozentanzahl. Schlüsselwort final entspricht const (Konstante)
|
||||
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.
|
||||
* Launch the application. - automatisch generiert vom Eclipse Windowsbuilder
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
@@ -49,69 +52,105 @@ public class frame extends JFrame {
|
||||
});
|
||||
}
|
||||
|
||||
//Methode zum Berechnen der Prozente + IHK-Noten
|
||||
//Übergeben werden: die maximale Punktanzahl + wieviel Prozent die maximalen Punkte entsprechen
|
||||
//Ausgegeben wird ein Array, was später in die Tabellenspalten geschrieben wird
|
||||
public static String[][] calculateMarks (int maxPoints, int totalPercentage) {
|
||||
int pointPercentage = 0;
|
||||
double markIHK = 0.0;
|
||||
String[][] output = new String[maxPoints+1][4];
|
||||
|
||||
//Ausrechnen und Aufbereiten der Ergebnisse als Array für die Tabelle
|
||||
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);
|
||||
output[maxPoints-point][0] = String.format("%d", point); //Punkte
|
||||
output[maxPoints-point][1] = String.format("%d %%", pointPercentage); //Prozente
|
||||
output[maxPoints-point][2] = String.format("%.1f", markIHK); //IHK-Note
|
||||
output[maxPoints-point][3] = String.format("%.0f", markIHK); //ganze Note
|
||||
}
|
||||
else {
|
||||
output[maxPoints-point][0] = Integer.toString(point);
|
||||
output[maxPoints-point][1] = Integer.toString(pointPercentage) + " %";
|
||||
output[maxPoints-point][0] = String.format("%d", point); //Punkte
|
||||
output[maxPoints-point][1] = String.format("%d %%", pointPercentage); //Prozente
|
||||
}
|
||||
}
|
||||
return output;
|
||||
return output; //Rückgabe des Arrays
|
||||
}
|
||||
|
||||
public void updateTable(JSpinner spMaxPoints, JSpinner spTotalPercentage) {
|
||||
String[][] resWiso = calculateMarks((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
|
||||
String[] columnNames = {"Punkte",
|
||||
"Prozente",
|
||||
"IHK-Note",
|
||||
"ganze Note"
|
||||
};
|
||||
//Methode zum Anzeigen bzw. Aktualisieren der Tabelle
|
||||
//Übergeben werden: Die eingegebenen Werte für die Maximale Punktezahl und für die Prozente
|
||||
public void updateTable(int maxPoints, int totalPercentage) {
|
||||
String[][] res = calculateMarks(maxPoints, totalPercentage); //Aufruf der Methode zum Berechnen und Zwischenspeicherung in res
|
||||
String[] columnNames = {"Punkte", "Prozente", "IHK-Note", "ganze Note"}; //Spaltennamen für die Tabelle
|
||||
|
||||
table = new JTable(resWiso, columnNames) {
|
||||
table = new JTable(res, columnNames) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
public boolean isCellEditable(int row, int column) { //Editieren der Tabelle für alle Zellen deaktivieren
|
||||
return false;
|
||||
}
|
||||
};
|
||||
table.setRowSelectionAllowed(false);
|
||||
table.setRowSelectionAllowed(false); //Zeilenauswahl für die Tabelle deaktivieren
|
||||
|
||||
scrollPane.setViewportView(table);
|
||||
scrollPane.setViewportView(table); //Anzeigen der Tabelle im ScrollPane
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String[] calculatePart(int pointsA, int pointsB, int maxPointsA, int maxPointsB, int percentageA, int percentageB, boolean mitIHK) {
|
||||
//Methode zum Zusammenrechnen eines A- und B-Teils einer AP1 oder AP2
|
||||
//Übergeben werden: die erreichten Punkte im A-Teil, die erreichten Punkte im B-Teil, die erreichbaren Punkte im A-Teil, die erreichbaren Punkte im B-Teil, die prozentuale Gewichtung des A-Teils, die prozentuale Gewichtung des B-Teils
|
||||
public String[] calculatePart(int pointsA, int pointsB, int maxPointsA, int maxPointsB, int percentageA, int percentageB) {
|
||||
//Umrechnung der übergebenen Prozente in Faktoren
|
||||
double calcPercentageA = (double)percentageA/(double)100;
|
||||
double calcPercentageB = (double)percentageB/(double)100;
|
||||
|
||||
//Berechnung der gewichteten erreichten Prozente in Teil A und B
|
||||
double percentagePartA = (calcPercentageA*(double)pointsA/(double)maxPointsA)*(double)100;
|
||||
double percentagePartB = (calcPercentageB*(double)pointsB/(double)maxPointsB)*(double)100;
|
||||
|
||||
//Zusammenrechnen zu einem Gesamtergebnis (max. 100%)
|
||||
double totalPercentage = percentagePartA + percentagePartB;
|
||||
//heraussuchen der entsprechenden IHK-Note aus dem Array
|
||||
double markIHK = marksIHK[(int)totalPercentage];
|
||||
|
||||
//Initialisierung eines Arrays zum zwischenspeichern der Ergebnisse
|
||||
String[] res = new String[6];
|
||||
//Speichern der Ergebnisse im Array
|
||||
res[0] = String.format("%.2f", percentagePartA);
|
||||
res[1] = String.format("%.2f", percentagePartB);
|
||||
res[2] = String.format("%.2f", totalPercentage);
|
||||
res[3] = String.format("%.0f", totalPercentage);
|
||||
res[4] = String.format("%.2f", markIHK);
|
||||
res[5] = String.format("%.0f", markIHK);
|
||||
return res;
|
||||
return res; //Rückgabe der Ergebnisse als Array
|
||||
}
|
||||
|
||||
//Methode zum Zusammenrechnen der einzelnen AP2-Teile
|
||||
//Übergaben werden: Ein Array mit den Gewichtungen der einzelnen Teile, ein Array mit den erreichten Prozenten der einzelnen Teile (ungewichtet)
|
||||
public int calculateTotal(int[]w, int percentage[]) {
|
||||
String[] res = new String[6]; //Array zum Speichern der Ergebnisse
|
||||
double[] temp = new double[w.length]; //Array für Zwischenergebnisse
|
||||
int totalPercentage = 0; //Variable für das Endergebnis
|
||||
|
||||
// For-Schleife für alle Prüfungsteile
|
||||
for (int i=0; i<w.length; i++) {
|
||||
//Prozente in Faktoren umwandeln
|
||||
temp[i] = (double)w[i]/(double)100;
|
||||
//gewichtete erreichte Prozente des jeweiligen Teils
|
||||
temp[i] = (double)temp[i]*(double)percentage[i];
|
||||
//hinzurechnen des Teilergebnisses zum Gesamtergebnis
|
||||
totalPercentage += temp[i];
|
||||
}
|
||||
|
||||
return totalPercentage; //Rückgabe der gesamten erreichten Prozente
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public frame() {
|
||||
setResizable(false);
|
||||
|
||||
//maximal Erreichbare Punkte in den einzelnen Prüfungsteilen (für eine Anpassung müssen diese nur hie geändert werden)
|
||||
final int pointsAP1PartA = 20;
|
||||
final int pointsAP1PartB = 80;
|
||||
final int pointsAP2_SEPartA = 25;
|
||||
@@ -121,6 +160,7 @@ public class frame extends JFrame {
|
||||
final int pointsAP2_FusPartA = 25;
|
||||
final int pointsAP2_FusPartB = 80;
|
||||
|
||||
// Hier folgen die GUI-Elemente welche vom Eclipse WindowBuilder generiert wurden
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 815, 529);
|
||||
contentPane = new JPanel();
|
||||
@@ -150,11 +190,11 @@ public class frame extends JFrame {
|
||||
spTotalPercentage.setBounds(160, 74, 58, 26);
|
||||
contentPane.add(spTotalPercentage);
|
||||
|
||||
|
||||
//Tabelle aktualisieren wenn Punkte geändert werden
|
||||
spMaxPoints.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
updateTable(spMaxPoints, spTotalPercentage);
|
||||
updateTable((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -166,9 +206,10 @@ public class frame extends JFrame {
|
||||
|
||||
|
||||
Button btnCalc = new Button("Berechnen");
|
||||
//Event Listener, der wenn der Button gedrückt wird, die Tabelle aktualisiert
|
||||
btnCalc.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateTable(spMaxPoints, spTotalPercentage);
|
||||
updateTable((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
|
||||
}
|
||||
});
|
||||
btnCalc.setBounds(272, 73, 91, 27);
|
||||
@@ -288,9 +329,10 @@ public class frame extends JFrame {
|
||||
contentPane.add(spAP2_Wiso_PartB);
|
||||
|
||||
Button btnCalcAP1 = new Button("Berechnen");
|
||||
//Event Listener, der wenn der Button gedrückt wird, die Ergebnisse ausgibt
|
||||
btnCalcAP1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String[] resWiso = calculatePart((int)spAP1_PartA.getValue(), (int)spAP1_PartB.getValue(), pointsAP1PartA, pointsAP1PartB, 50, 50, true);
|
||||
String[] resWiso = calculatePart((int)spAP1_PartA.getValue(), (int)spAP1_PartB.getValue(), pointsAP1PartA, pointsAP1PartB, 50, 50);
|
||||
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"
|
||||
@@ -306,12 +348,16 @@ public class frame extends JFrame {
|
||||
contentPane.add(btnCalcAP1);
|
||||
|
||||
Button btnCalcAP2 = new Button("Berechnen");
|
||||
//Event Listener, der wenn der Button gedrückt wird, die Ergebnisse ausgibt
|
||||
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, 50, 50, false);
|
||||
String[] resFus = calculatePart((int)spAP2_Fus_PartA.getValue(), (int)spAP2_Fus_PartB.getValue(), pointsAP2_FusPartA, pointsAP2_FusPartB, 50, 50, false);
|
||||
String[] resWiso = calculatePart((int)spAP2_Wiso_PartA.getValue(), (int)spAP2_Wiso_PartB.getValue(), pointsAP2_WisoPartA, pointsAP2_WisoPartB, 40, 60, false);
|
||||
String textSE = "AP2\n\nSystementwurf\n=============\n"
|
||||
String[] resSE = calculatePart((int)spAP2_SE_PartA.getValue(), (int)spAP2_SE_PartB.getValue(), pointsAP2_SEPartA, pointsAP2_SEPartB, 50, 50);
|
||||
String[] resFus = calculatePart((int)spAP2_Fus_PartA.getValue(), (int)spAP2_Fus_PartB.getValue(), pointsAP2_FusPartA, pointsAP2_FusPartB, 50, 50);
|
||||
String[] resWiso = calculatePart((int)spAP2_Wiso_PartA.getValue(), (int)spAP2_Wiso_PartB.getValue(), pointsAP2_WisoPartA, pointsAP2_WisoPartB, 40, 60);
|
||||
int[] partsPercentage = {40, 40, 20};
|
||||
int[] resParts = {Integer.valueOf(resSE[3]), Integer.valueOf(resFus[3]), Integer.valueOf(resWiso[3])};
|
||||
int totalPercentage = calculateTotal(partsPercentage, resParts);
|
||||
String textSE = "Systementwurf\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"
|
||||
@@ -326,7 +372,8 @@ public class frame extends JFrame {
|
||||
+ "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";
|
||||
String textGes = String.format("Gesamtergebnis\n=============\n%d%%\nIHK-Note: %.1f", totalPercentage, marksIHK[totalPercentage]);
|
||||
String output = "AP2\n\n" + textGes + "\n\n" + textSE + "\n\n" + textFus + "\n\n" + textWiso + "\n";
|
||||
JTextPane txtpnGesamt = new JTextPane();
|
||||
txtpnGesamt.setText(output);
|
||||
txtpnGesamt.setEditable(false);
|
||||
|
||||
Reference in New Issue
Block a user