### oefening 1 ### <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".aView"> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/inputGetal1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="number" android:hint="geef geheel getal"/> <TextView android:id="@+id/tvLijstCijfers" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/btnAdd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Berekenen" android:onClick="onRefresh"/> <TextView android:id="@+id/tvGemCijfers" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > </TableRow> </TableLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Download hier het bestand.
### oefening 2 ### public class aView extends AppCompatActivity { aModel aModel1 = new aModel(); aController controller1 = new aController(aModel1); ... public void onRefresh(View view) { EditText etInputGetal = (EditText)findViewById(R.id.inputGetal1); int getal = Integer.valueOf(etInputGetal.getText().toString()); controller1.addToLijst(aModel1,getal); TextView tvLijstCijfers = (TextView)findViewById(R.id.tvLijstCijfers); TextView tvGemCijfers = (TextView)findViewById(R.id.tvGemCijfers); String strLijst = TextUtils.join(",", aModel1.getLijst()); String strGemid = String.valueOf(aModel1.getGemiddelde()); tvLijstCijfers.setText(strLijst); tvGemCijfers.setText(strGemid); } ... }
Download hier het bestand.
### oefening 3 ### public class aModel { ArrayList<Integer> cijferList = new ArrayList<>(); public aModel() { } public void addToLijst(int newNumber) { cijferList.add(newNumber); } public ArrayList getLijst() { return cijferList; } public double getGemiddelde() { double gemidDouble = calcGemiddelde(cijferList); return gemidDouble; } private double calcGemiddelde(ArrayList<Integer> numberList) { Integer sum = 0; if (!numberList.isEmpty()) { for (Integer numList: numberList) { sum = sum + numList; } } return sum.doubleValue() / numberList.size(); } }
Download hier het bestand.
### oefening 4 ### public class aController { aController(aModel aModel) { } public void addToLijst(aModel aModel2, int newGetal) { aModel2.addToLijst(newGetal); } }
Download hier het bestand.