Browse Source

Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	src/main/java/src/TasksFrame.java
remotes/origin/develop
fdai7460 2 years ago
parent
commit
424bdc0be3
  1. 10
      src/main/java/src/GameField.java
  2. 96
      src/main/java/src/MainFrame.java
  3. 77
      src/main/java/src/Model.java
  4. 223
      src/main/java/src/SandboxFrame.java
  5. 405
      src/main/java/src/TasksFrame.java
  6. 5
      src/test/java/ModelTest.java
  7. 77
      src/test/java/src/TasksFrameTest.java

10
src/main/java/src/GameField.java

@ -122,8 +122,14 @@ public class GameField extends JPanel {
public void setValue(int x, int y, int value) {
JLabel jLabel = gameField[y][x].getjLabel();
jLabel.setText(String.valueOf(value));
jLabel.setVisible(true);
if (value <= 0) {
jLabel.setText("0");
jLabel.setVisible(false);
} else {
jLabel.setText(String.valueOf(value));
jLabel.setVisible(true);
}
}

96
src/main/java/src/MainFrame.java

@ -1,5 +1,10 @@
package src;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
@ -12,6 +17,11 @@ public class MainFrame extends JFrame {
private GameField gameField;
private JSONArray currentGameDifficulty;
private Model currentModel;
private JLabel currentGameLabel;
private int currentPosition;
public void run() {
this.setLayout(null);
@ -36,7 +46,6 @@ public class MainFrame extends JFrame {
gameField.setBounds(70, 50, 360, 360);
rootPanel.add(gameField);
int j = 0;
JPanel boxPanel = setupJPanel();
@ -72,10 +81,37 @@ public class MainFrame extends JFrame {
JButton back = new JButton();
back.setVisible(true);
back.setBounds(5, 5, 100, 25);
back.setBounds(120, 525, 100, 25);
rootPanel.add(back);
back.setText("Back");
currentGameLabel = new JLabel();
currentGameLabel.setVisible(true);
currentGameLabel.setBounds(250, 525, 40, 25);
currentGameLabel.setText("0/0");
rootPanel.add(currentGameLabel);
JButton next = new JButton();
next.setVisible(true);
next.setBounds(280, 525, 100, 25);
rootPanel.add(next);
next.setText("Next");
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentPosition+1 < currentGameDifficulty.size()) {
currentPosition++;
} else {
currentPosition = 0;
}
JSONObject jsonObject = (JSONObject) currentGameDifficulty.get(currentPosition);
loadDataToGameField(jsonObject);
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JButton newButton = new JButton();
newButton.setVisible(true);
newButton.setBounds(395, 5, 100, 25);
@ -97,6 +133,7 @@ public class MainFrame extends JFrame {
private JPanel setupNums(String number) {
JPanel jPanel = new JPanel();
jPanel.setBackground(Color.BLUE);
jPanel.setVisible(true);
@ -137,7 +174,6 @@ public class MainFrame extends JFrame {
return jPanel;
}
public JPanel setupJPanel() {
JPanel panel = new JPanel();
panel.setBounds(100, 450, 300, 30);
@ -172,6 +208,10 @@ public class MainFrame extends JFrame {
return jPanel;
}
private void loadDataToGameField(JSONObject jsonObject) {
currentModel = new Model(jsonObject, gameField);
}
private JMenuBar setupMenuBar() {
JMenuBar menu_mb=new JMenuBar();
@ -183,8 +223,58 @@ public class MainFrame extends JFrame {
JMenuItem menu_i1=new JMenuItem("Nochmal");
JMenuItem menu_i2=new JMenuItem("Tipp");
JMenuItem menu_i4=new JMenuItem("Einfach");
menu_i4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String data = Model.loadAllData();
JSONObject object = null;
try {
object = (JSONObject)new JSONParser().parse(data);
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
currentGameDifficulty = (JSONArray) object.get("easyGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JMenuItem menu_i5=new JMenuItem("Mittel");
menu_i5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String data = Model.loadAllData();
JSONObject object = null;
try {
object = (JSONObject)new JSONParser().parse(data);
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
currentGameDifficulty = (JSONArray) object.get("mediumGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JMenuItem menu_i6=new JMenuItem("Schwer");
menu_i6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String data = Model.loadAllData();
JSONObject object = null;
try {
object = (JSONObject)new JSONParser().parse(data);
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
currentGameDifficulty = (JSONArray) object.get("hardGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
m_menu.add(menu_i1);
m_menu.add(menu_i2);

77
src/main/java/src/Model.java

@ -100,7 +100,6 @@ public class Model {
public static String loadAllData() {
File file = new File("src/main/java/src/sudoku.json");
if (file.exists()) {
@ -110,6 +109,7 @@ public class Model {
throw new RuntimeException(e);
}
}
String line = "";
try {
Scanner scanner = new Scanner(file);
@ -120,6 +120,22 @@ public class Model {
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
if (line.equals("")) {
initJsonFile();
}
line = "";
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
line = line + scanner.nextLine();
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return line;
}
@ -155,18 +171,6 @@ public class Model {
}
}
public void loadNewMedium() {
}
public void loadNewHard() {
}
public void safeNewSandboxGame() {
}
@Override
public String toString() {
@ -203,7 +207,7 @@ public class Model {
JSONObject jsonObject = new JSONObject();
jsonObject.put("x", j);
jsonObject.put("y", i);
jsonObject.put("value", getField(i, j));
jsonObject.put("value", getField(j, i));
values.add(jsonObject);
}
@ -348,4 +352,49 @@ public class Model {
throw new RuntimeException(e);
}
}
public void createNewGame(String difficulty) {
JSONObject myNewGame = modelToJson();
String s = loadAllData();
JSONObject object = null;
try {
object = (JSONObject) new JSONParser().parse(s);
} catch (ParseException e) {
throw new RuntimeException(e);
}
JSONArray easyArray = (JSONArray) object.get("easyGame");
JSONArray mediumArray = (JSONArray) object.get("mediumGame");
JSONArray hardArray = (JSONArray) object.get("hardGame");
System.out.println();
if (difficulty.equals("easy")) {
easyArray.add(myNewGame);
} else if (difficulty.equals("medium")) {
mediumArray.add(myNewGame);
} else if (difficulty.equals("hard")) {
hardArray.add(myNewGame);
}
String jsonString = object.toJSONString();
try {
FileWriter writer = new FileWriter("src/main/java/src/sudoku.json");
writer.write(jsonString);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

223
src/main/java/src/SandboxFrame.java

@ -1,15 +1,236 @@
package src;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class SandboxFrame extends JFrame {
private GameField gameField;
private JPanel rootPanel;
private String difficulty = "easy";
public void run() {
this.setLayout(null);
this.setVisible(true);
this.setBounds(400, 200, 500, 500);
this.setBounds(400, 200, 500, 550);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setupLayout();
}
private void setupLayout() {
rootPanel = new JPanel();
rootPanel.setVisible(true);
rootPanel.setBounds(0, 0, 500, 500);
rootPanel.setBackground(Color.LIGHT_GRAY);
rootPanel.setLayout(null);
this.setContentPane(rootPanel);
JPanel header = setupHeader(20, 10);
header.setBounds(125, 5, 250, 50);
rootPanel.add(header);
gameField = new GameField(360);
gameField.setBounds(70, 50, 360, 360);
rootPanel.add(gameField);
JPanel diff = setupDifficulty();
diff.setBounds(80, 420, 300, 35);
rootPanel.add(diff);
JButton saveBtn = setupSaveButton();
saveBtn.setBounds(400, 420, 100, 30);
rootPanel.add(saveBtn);
JPanel numberField = setupNumberField();
numberField.setBounds(100, 470, 300, 35);
rootPanel.add(numberField);
}
private JButton setupSaveButton() {
JButton save = new JButton("Save");
save.setVisible(true);
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Model model = new Model(gameField);
model.createNewGame(difficulty);
SandboxFrame.this.dispose();
}
});
return save;
}
private JPanel setupNumberField() {
JPanel boxPanel = setupJPanel();
boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.X_AXIS));
JPanel jPanel1 = setupNums("1");
boxPanel.add(jPanel1);
JPanel jPanel2 = setupNums("2");
boxPanel.add(jPanel2);
JPanel jPanel3 = setupNums("3");
boxPanel.add(jPanel3);
JPanel jPanel4 = setupNums("4");
boxPanel.add(jPanel4);
JPanel jPanel5 = setupNums("5");
boxPanel.add(jPanel5);
JPanel jPanel6 = setupNums("6");
boxPanel.add(jPanel6);
JPanel jPanel7 = setupNums("7");
boxPanel.add(jPanel7);
JPanel jPanel8 = setupNums("8");
boxPanel.add(jPanel8);
JPanel jPanel9 = setupNums("9");
boxPanel.add(jPanel9);
return boxPanel;
}
private JPanel setupDifficulty() {
JPanel jPanel = new JPanel();
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS));
JButton easy = new JButton("Easy");
easy.setPreferredSize(new Dimension(100, 30));
easy.setVisible(true);
jPanel.add(easy);
easy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
difficulty = "easy";
}
});
jPanel.add(Box.createHorizontalStrut(10));
JButton medium = new JButton("Medium");
medium.setPreferredSize(new Dimension(100, 30));
medium.setVisible(true);
jPanel.add(medium);
medium.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
difficulty = "medium";
}
});
jPanel.add(Box.createHorizontalStrut(10));
JButton hard = new JButton("Hard");
hard.setPreferredSize(new Dimension(100, 30));
hard.setVisible(true);
jPanel.add(hard);
hard.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
difficulty = "hard";
}
});
return jPanel;
}
private JPanel setupHeader(int headerSize, int subheaderSize) {
JPanel jPanel = new JPanel();
jPanel.setVisible(true);
jPanel.setBackground(new Color(0, 0, 0, 0));
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
JLabel header = new JLabel();
header.setAlignmentX(Component.CENTER_ALIGNMENT);
header.setText("Sudoku Sandbox");
header.setVisible(true);
header.setForeground(Color.BLACK);
header.setFont(new Font("Times New Roman", Font.BOLD, headerSize));
jPanel.add(header);
JLabel subheader = new JLabel();
subheader.setAlignmentX(Component.CENTER_ALIGNMENT);
subheader.setText("Represented by Team Deep Thought");
subheader.setVisible(true);
subheader.setForeground(Color.BLACK);
subheader.setFont(new Font("Times New Roman", Font.ITALIC, subheaderSize));
jPanel.add(subheader);
return jPanel;
}
private JPanel setupNums(String number) {
JPanel jPanel = new JPanel();
jPanel.setBackground(Color.BLUE);
jPanel.setVisible(true);
jPanel.setBorder(new LineBorder(Color.PINK, 1));
jPanel.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
gameField.getActivePanel().setValue(Integer.valueOf(number));
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
JLabel numLabel1 = new JLabel();
numLabel1.setText(number);
numLabel1.setLayout(null);
numLabel1.setVisible(true);
jPanel.add(numLabel1);
return jPanel;
}
public JPanel setupJPanel() {
JPanel panel = new JPanel();
panel.setBounds(100, 450, 300, 30);
panel.setVisible(true);
panel.setBackground(Color.GREEN);
return panel;
}
}

405
src/main/java/src/TasksFrame.java

@ -1,12 +1,16 @@
package src;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Color;
import static java.lang.Double.valueOf;
public class TasksFrame extends JFrame {
@ -63,6 +67,8 @@ public class TasksFrame extends JFrame {
setupHelloWorld();
setupDate();
setupSum();
setupDiff();
@ -77,8 +83,370 @@ public class TasksFrame extends JFrame {
setupEulerschePhiFunk();
setupQuersumme();
setupKgV();
setupRoundSum();
setupExponent();
setupUmrechnen();
setupBmi();
}
private void setupExponent() {
JPanel jPanel = setupPanel("Potenzrechner");
JButton button = new JButton("calculate");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JLabel height = new JLabel("basis");
height.setVisible(true);
height.setBounds(10, 20, 60, 30);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 45, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel weight = new JLabel("exponent");
weight.setVisible(true);
weight.setBounds(80, 20, 60, 30);
JTextField textField = new JTextField();
textField.setVisible(true);
textField.setBounds( 80, 45, 30, 20);
textField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10, 90, 150, 30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(height);
jPanel.add(weight);
jPanel.add(textField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = jTextField.getText();
String text1 = textField.getText();
double val = Double.valueOf(text);
double val1 = Double.valueOf(text1);
double res = Double.valueOf(expo(val, val1));
jLabel.setText(String.valueOf(res));
}
});
}
public double expo(double base, double exp) {
double result = Math.pow(base, exp) ;
return result;
}
private void setupDate() {
JPanel jPanel = setupPanel("Datum");
String dateStr = String.format("%ta, %1$te. %1$tb %1$tY - %1$tT", System.currentTimeMillis());
JLabel label = new JLabel(dateStr);
label.setVisible(true);
label.setBounds(10, 45, 160, 50);
Border border = BorderFactory.createLineBorder(Color.BLUE, 3);
label.setBorder(border);
label.setForeground(Color.BLACK);
jPanel.add(label);
}
private void setupBmi() {
JPanel jPanel = setupPanel("BMI Calculator");
JButton button = new JButton("BMI");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JLabel height = new JLabel("Height/m");
height.setVisible(true);
height.setBounds(10, 20, 60, 30);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 45, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel weight = new JLabel("Weight/kg");
weight.setVisible(true);
weight.setBounds(80, 20, 60, 30);
JTextField textField = new JTextField();
textField.setVisible(true);
textField.setBounds( 80, 45, 30, 20);
textField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10, 90, 60, 30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(height);
jPanel.add(weight);
jPanel.add(textField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = jTextField.getText();
String text1 = textField.getText();
double val = Double.valueOf(text);
double val1 = Double.valueOf(text1);
double res = Double.valueOf(bmi(val, val1));
jLabel.setText(String.valueOf(res));
}
});
}
public double bmi(double height, double weight) {
double result = 0.0;
result = weight / (height * height);
double roundOff = Math.round(result * 100.0) / 100.0;
return roundOff;
}
private void setupUmrechnen() {
JPanel jPanel = setupPanel("Dezimal nach Binär");
JButton button = new JButton("calculate");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 40, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10, 90, 60, 30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = jTextField.getText();
Integer val = Integer.valueOf(text);
int res = Integer.valueOf(umrechnen(val));
jLabel.setText(String.valueOf(res));
}
});
}
public String umrechnen(int dez) {
String binaer = "";
while (dez > 0) {
if (dez % 2 == 0) {
binaer = "0" + binaer;
}
if (dez % 2 == 1) {
binaer = "1" + binaer;
}
dez = dez / 2;
}
return binaer;
}
private void setupRoundSum() {
JPanel jPanel = setupPanel("Runde Summe");
JButton button = new JButton("round sum");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField a = new JTextField();
a.setBounds(10, 40, 30, 20);
a.setVisible(true);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField b = new JTextField();
b.setBounds(50, 40, 30, 20);
b.setVisible(true);
b.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField c = new JTextField();
c.setBounds(90, 40, 30, 20);
c.setVisible(true);
c.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10,90,60,30);
jPanel.add(button);
jPanel.add(a);
jPanel.add(b);
jPanel.add(c);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String texta = a.getText();
String textb = b.getText();
String textc = c.getText();
Integer val_a = Integer.valueOf(texta);
Integer val_b = Integer.valueOf(textb);
Integer val_c = Integer.valueOf(textc);
int res = roundSum(val_a, val_b, val_c);
jLabel.setText(String.valueOf(res));
}
});
}
public int roundSum(int a, int b, int c) {
return round10(a) + round10(b) + round10(c);
}
public int round10(int n) {
if (n % 10 >= 5) {
return n + 10 - n % 10;
}
else {
return n - n % 10;
}
}
private void setupKgV() {
JPanel jPanel = setupPanel("kgV");
JButton button = new JButton("kgV");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField a = new JTextField();
a.setBounds(10, 40, 30, 20);
a.setVisible(true);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField b = new JTextField();
b.setBounds(50, 40, 30, 20);
b.setVisible(true);
b.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10,90,60,30);
jPanel.add(button);
jPanel.add(a);
jPanel.add(b);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String texta = a.getText();
String textb = b.getText();
Integer val_a = Integer.valueOf(texta);
Integer val_b = Integer.valueOf(textb);
int res = kgV(val_a, val_b);
jLabel.setText(String.valueOf(res));
}
});
}
public int kgV(int a, int b) {
int kgV= (a*b)/ggt(a,b);
return kgV;
}
private void setupQuersumme() {
JPanel jPanel = setupPanel("Quersumme");
JButton button = new JButton("Quersumme");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds(10, 40, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10,90,60,30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int r = quer(Integer.valueOf(jTextField.getText()));
jLabel.setText(String.valueOf(r));
}
});
}
public int quer(Integer n) {
int quersumme = 0;
for (int x = n; x > 0; x = x / 10) {
quersumme = quersumme + x % 10;
}
return quersumme;
}
public int calcMod(int n, int x)
{
int rest = n % x;
@ -89,13 +457,18 @@ public class TasksFrame extends JFrame {
JPanel jPanel = setupPanel("Eulersche Phi Funktion");
Button button = new Button("Calc Phi");
JButton button = new JButton("calc Phi");
button.setVisible(true);
button.setBounds(120, 50, 100, 30);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 40, 60, 20);
jTextField.setBounds( 10, 40, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
@ -156,6 +529,8 @@ public class TasksFrame extends JFrame {
Button button = new Button("Say Hello World");
button.setBounds(10, 50, 150, 30);
button.setVisible(true);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -175,6 +550,7 @@ public class TasksFrame extends JFrame {
JTextField a = new JTextField();
a.setBounds(10, 50, 30, 20);
a.setVisible(true);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel sum = new JLabel();
sum.setBounds(40, 50, 10, 20);
@ -184,6 +560,7 @@ public class TasksFrame extends JFrame {
JTextField b = new JTextField();
b.setBounds(50, 50, 30, 20);
b.setVisible(true);
b.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel equal = new JLabel();
equal.setBounds(90, 50, 30, 20);
@ -193,10 +570,13 @@ public class TasksFrame extends JFrame {
JTextField result = new JTextField();
result.setBounds(100, 50, 40, 20);
result.setVisible(true);
result.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JButton add = new JButton("add");
add.setBounds(10, 90, 100, 30);
add.setVisible(true);
add.setForeground(Color.WHITE);
add.setBackground(Color.BLUE);
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -230,6 +610,7 @@ public class TasksFrame extends JFrame {
JTextField x = new JTextField();
x.setBounds(10,50,30,20);
x.setVisible(true);
x.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel diff = new JLabel();
diff.setBounds(40, 50, 10, 20);
@ -239,6 +620,7 @@ public class TasksFrame extends JFrame {
JTextField y = new JTextField();
y.setBounds(50,50,30,20);
y.setVisible(true);
y.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel equal = new JLabel();
equal.setBounds(90, 50, 30, 20);
@ -248,10 +630,13 @@ public class TasksFrame extends JFrame {
JTextField result = new JTextField();
result.setBounds(100,50,40,20);
result.setVisible(true);
result.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JButton difference = new JButton("Difference");
difference.setBounds(10,90,100,30);
difference.setVisible(true);
difference.setForeground(Color.WHITE);
difference.setBackground(Color.BLUE);
difference.addActionListener(new ActionListener() {
@Override
@ -295,18 +680,23 @@ public class TasksFrame extends JFrame {
JTextField a = new JTextField();
a.setVisible(true);
a.setBounds(50,25,30,20);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField b = new JTextField();
b.setVisible(true);
b.setBounds(50,45,30,20);
b.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JButton area = new JButton("Calculate area");
area.setVisible(true);
area.setBounds(0, 80, 180,30);
area.setForeground(Color.WHITE);
area.setBackground(Color.BLUE);
JTextField areaRes = new JTextField();
areaRes.setBounds(200,80,30,20 );
areaRes.setVisible(true);
areaRes.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
area.addActionListener(new ActionListener() {
@Override
@ -330,10 +720,13 @@ public class TasksFrame extends JFrame {
JButton perimeter = new JButton("Calculate perimeter");
perimeter.setVisible(true);
perimeter.setBounds(0, 110, 180,30);
perimeter.setForeground(Color.WHITE);
perimeter.setBackground(Color.BLUE);
JTextField perimeterRes = new JTextField();
perimeterRes.setBounds(200,110,30,20 );
perimeterRes.setVisible(true);
perimeterRes.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
perimeter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -372,18 +765,23 @@ public class TasksFrame extends JFrame {
JTextField a = new JTextField();
a.setBounds(10, 50, 30, 20);
a.setVisible(true);
a.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField b = new JTextField();
b.setBounds(50, 50, 30, 20);
b.setVisible(true);
b.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JTextField result = new JTextField();
result.setBounds(100, 50, 40, 20);
result.setVisible(true);
result.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JButton sumFromTo = new JButton("calculate");
sumFromTo.setBounds(10,90,100,30);
sumFromTo.setVisible(true);
sumFromTo.setForeground(Color.WHITE);
sumFromTo.setBackground(Color.BLUE);
sumFromTo.addActionListener(new ActionListener() {
@Override
@ -422,6 +820,7 @@ public class TasksFrame extends JFrame {
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds(3, 40, 250, 30);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
for (int i = from; i < to; i++) {
int e = i % 5;

5
src/test/java/ModelTest.java

@ -46,6 +46,7 @@ public class ModelTest extends MainFrame {
"8 | 8 8 8 8 8 8 8 8 8\n";
assertEquals(model.toString(), staticCase, "tested Overridden toString of Model.class");
}
@ -247,7 +248,7 @@ public class ModelTest extends MainFrame {
GameField gameField = new GameField(360);
for (int i = 0, k = 13; i < 9; i++) {
for (int j = 0, l = 17; j < 9; j++) {
gameField.setValue(i, j, (i*l+j*k)%9);
gameField.setValue(j, i, (i*l+j*k)%9);
}
}
Model model = new Model(gameField);
@ -273,7 +274,7 @@ public class ModelTest extends MainFrame {
GameField gf = new GameField(360);
for (int i = 0, k = 13; i < 9; i++) {
for (int j = 0, l = 17; j < 9; j++) {
gf.setValue(i, j, (i*l+j*k)%9);
gf.setValue(j, i, (i*l+j*k)%9);
}
}
Model m = new Model(gf);

77
src/test/java/src/TasksFrameTest.java

@ -103,7 +103,84 @@ class TasksFrameTest {
assertEquals(1,p3);
}
@Test
void test_quer(){
TasksFrame tasksFrame = new TasksFrame();
int q = tasksFrame.quer(15);
assertEquals(6, q);
int q2 = tasksFrame.quer(23);
assertEquals(5, q2);
int q3 = tasksFrame.quer(235);
assertEquals(10, q3);
}
@Test
void test_kgV(){
TasksFrame tasksFrame = new TasksFrame();
int a = tasksFrame.kgV(5, 8);
assertEquals(40, a);
int b = tasksFrame.kgV(28, 64);
assertEquals(448, b);
int c = tasksFrame.kgV(35, 70);
assertEquals(70, c);
}
@Test
void test_roundSum(){
TasksFrame tasksFrame = new TasksFrame();
int a = tasksFrame.roundSum(15, 21, 12);
assertEquals(50, a);
int b = tasksFrame.roundSum(48, 25, 17);
assertEquals(100, b);
int c = tasksFrame.roundSum(13, 9, 26);
assertEquals(50, c);
}
@Test
void test_round10(){
TasksFrame tasksFrame = new TasksFrame();
int a = tasksFrame.round10(15);
assertEquals(20, a);
int b = tasksFrame.round10(56);
assertEquals(60, b);
int c = tasksFrame.round10(12);
assertEquals(10, c);
}
@Test
void test_umrechnen(){
TasksFrame tasksFrame = new TasksFrame();
int a = Integer.parseInt(tasksFrame.umrechnen(15));
assertEquals(1111, a);
int b = Integer.parseInt(tasksFrame.umrechnen(20));
assertEquals(10100, b);
int c = Integer.parseInt(tasksFrame.umrechnen(48));
assertEquals(110000, c);
}
@Test
void test_bmi(){
TasksFrame tasksFrame = new TasksFrame();
double a = tasksFrame.bmi(1.65, 60.0);
assertEquals(22.04, a);
double b = tasksFrame.bmi(1.95, 72);
assertEquals(18.93, b);
double c = tasksFrame.bmi(1.24, 30);
assertEquals(19.51, c);
}
@Test
void test_expo(){
TasksFrame tasksFrame = new TasksFrame();
double a = tasksFrame.expo(2, 3);
assertEquals(8, a);
double b = tasksFrame.expo(15, 3);
assertEquals(3375, b);
double c = tasksFrame.expo(10, 0);
assertEquals(1, c);
}
}
Loading…
Cancel
Save