# SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

### Sidebar

• Organisation:
• Knowledge:
• OO
• Tec
• Conventions

For instructions on setting up eclipse look at the first Warmup.

### Java Coding

Create a Subpackage “basics” in your package student.<login> and create a new class Circle with the methods:

Implement these methods using the following formulas (PI = 3.14159265):

• Area: F = PI * r^2
• Perimeter: U = 2 * PI * r
• Volume: V = 4.0/3.0 * PI * r^3

Write a test class CirlceTest which test the methods with example values. Include tests with neg. and “high” values.

The calculated values should be read from the keyboard. The result should be written to the screen.
Which values will be produced for the values: r = 4.0; 7.1; 18.5; ?

1. Create a class Loops in the package basics

2. Write a method “calcFac” calculating the faculty of n . Use a while loop for the implementation.

3. Write a method calcGeometricSeries using a for loop. The method should calculate and return the following sum:

`S(n) = 2^0 + 2^1 + 2^2 + ..... + 2^n`

4. Write a method “forBackwards”, which counts from n backwards, but does not decrement by one on each step, but by the half of the current number and stops if the value is smaller than 2. The method returns a string with all calculated values.
For n=100 the following List is returned:\ß

`100, 50, 25, 12.5, 7.25, 3.625, 1.8125`

5. Write a class LoopsTest, which tests all three methods with example values.

1. Create a class Circle in the package circle:

```class Circle {
protected boolean filled;
public Circle(int rad, int x, int y, boolean filled) { /*...*/ }
}```

Extend the class by providing a method “equals”, which compares two objects of the class Circle. Have a look at the Java API Documentation for the specification of the method in the class Object.

Write a “clone()”-method, which creates a new Cirlce object and initializes the new object with the state of the current object.

Write a test which creates, copies and compares Circle objects.

2. How do I have to change the class Circle if I add the attribut `protected int[] fillPattern;` ?

Write tests before you start coding!

#### Task 4: UML and Inheritance

Implement the classes specified in the UML class diagram below (except the JUnit class TestCase). The method “toString()” should print out the attribute values, also the assosiated ones.
The toString() method of the class Konto (bank account) also prints out the Inhaber (owner) of the bank account.

Ensure that the owner of the account must not exceed its credit limit.

1. Create a list (ArrayList) with 1400 random numbers between 0 and 98 (Integer). Use the nextInt() method from the class Random to create the numbers. Calculate the mean of the random numbers by using a ListIterator. Sort the random numbers with the help of the Collections algorithms.

2. Copy the content into a `LinkedList` and change the order of the elements randomly (method shuffle). Sort the list again.

#### Task 6: Specialized Container Objects

Create a class StudentenList which extends the class Vector. The class is a container for objects of class Student.

The following methods will be implemented

```public Student getStudent(int index);
public void sortListName();
public void sortListMatrikelnumber();```

Use the Comparator interface to sort the list.

How can you ensure that only Student objects will be used with the StudentenList?
Do you know a better solution than inheritance for this problem? 