Browse Source

Zahlenfelder Vers1. Objektorientiert

main
moritz 1 month ago
parent
commit
6b11baff87

+ 124
- 0
.idea/uiDesigner.xml View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

+ 3
- 0
prog3.iml View File

@@ -4,8 +4,11 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testTriangel01" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="junit.jupiter" level="application" />
</component>
</module>

+ 1
- 0
src/praktikum01/Zahlenfilter.java View File

@@ -23,6 +23,7 @@ public class Zahlenfilter {
} catch (NumberFormatException e) {
// Fehlermeldung, wenn das Argument keine gültige Zahl ist
System.out.println("Fehler: Bitte eine gültige Zahl als Programmargument eingeben.");
return; // Programm beenden
}
}


+ 56
- 0
src/praktikum02/TriangleChecker.java View File

@@ -0,0 +1,56 @@
package praktikum02;

import java.util.Scanner;

public class TriangleChecker {

public enum TriangleType {
NONE,
NORMAL,
ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig
}


public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Geben Sie die Seitenlängen ein.");
float a = enterFloat(s, "a: ");
float b = enterFloat(s, "b: ");
float c = enterFloat(s, "c: ");
s.close();
printAnalysis(a, b, c);
}

// Eingabe einer Seitenlänge
private static float enterFloat(Scanner s, String prompt) {
System.out.print(prompt);
return s.nextFloat();
}

// Ausgabe der ermittelten Dreiecksart
private static void printAnalysis(float a, float b, float c) {
TriangleType type = checkTriangle(a, b, c);
switch (type) {
case NONE:
System.out.println("Kein Dreieck");
break;
case NORMAL:
System.out.println("Dreieck");
break;
case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck");
break;
case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck");
break;
}
}

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
return TriangleType.NORMAL;
}


}

+ 63
- 0
src/praktikum02/Zahlenfilter02.java View File

@@ -0,0 +1,63 @@
package praktikum02;

//Zahlenfilter
public class Zahlenfilter02 {

private int start;

private int end;

public Zahlenfilter02(int s, int e) {
start = s;
end = e;
}

public static void main(String[] args) {
// Standardendwert ist 200, falls keine Argumente übergeben werden
int end = 200;

// Überprüfen, ob ein Programmargument übergeben wurde
if (args.length > 0) {
try {
// Versuchen, das Argument in eine Zahl umzuwandeln
end = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
// Fehlermeldung, wenn das Argument keine gültige Zahl ist
System.out.println("Fehler: Bitte eine gültige Zahl als Programmargument eingeben.");
}
}

Zahlenfilter02 zf = new Zahlenfilter02(1, end);
zf.printNumbers();
}

private void printNumbers() {
for (int i = 1; i <= end; i++) {
if (filter(i))
System.out.print(i + " ");
}
}

public static boolean filter(int number) {
return !(checkDivByFive(number) || checkEndsWithNine(number) || checkSumDivByThree(number));
}

public static boolean checkDivByFive(int number) {
// Wenn durch 5 Teilbar
return (number % 5 == 0);
}

public static boolean checkEndsWithNine(int number) {
// Wenn Zahl auf 9 endet
return (number % 10 == 9);
}

public static boolean checkSumDivByThree(int number) {
int vorgaenger = number - 1;
int summe = number + vorgaenger;


// Überprüfen, ob die Summe durch 3 teilbar ist
return (summe % 3 == 0);
}
}

+ 13
- 0
test/praktikum02/TriangleCheckerTest.java View File

@@ -0,0 +1,13 @@
package praktikum02;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class TriangleCheckerTest {

@Test
void checkTriangleNormal() {
assertEquals(TriangleChecker.TriangleType.NORMAL,TriangleChecker.checkTriangle( 10 ,5,6) );
}
}

+ 30
- 0
test/praktikum02/Zahlenfilter02Test.java View File

@@ -0,0 +1,30 @@
package praktikum02;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class Zahlenfilter02Test {

@Test
void filter() {
}

@Test
void checkDivByFive() {
assertTrue( Zahlenfilter02.checkDivByFive( 5 ) );
assertFalse( Zahlenfilter02.checkDivByFive( 6 ) );
}

@Test
void checkEndsWithNine() {
assertTrue( Zahlenfilter02.checkEndsWithNine( 9 ) );
assertFalse( Zahlenfilter02.checkEndsWithNine( 10 ) );
}

@Test
void checkSumDivByThree() {
assertTrue( Zahlenfilter02.checkSumDivByThree( 2 ) );
assertFalse( Zahlenfilter02.checkSumDivByThree( 7 ) );
}
}

Loading…
Cancel
Save