Assignment 10
Assignment 10
University of Konstanz
Department of Computer and Information Science
Chair for Data Analysis and Visualization
Dr. Johannes Fuchs
Task 1:
Sort a collection of objects.
1. Implement a class Room.
2. A room is instantiated with a certain width (int) and height (int).
3. Initialize a list of at least 20 rooms
4. Each room has a random height and a random width (values between 0 - 9)
5. Implement the class RoomComparator, which implements the Comparator inter-
face. The Comparator interface is already implemented and is, therefore, part of the
Java library.
import java.util.Comparator;
6. Sort the list of rooms according to their square meters using the following command:
Collections.sort(listOfRooms, new RoomComparator());
Collections is a class already implemented in the Java library.
import java.util.Collections;
7. Print the results to the console showing the square meters (unsorted and sorted).
Task 2:
Implement an application to calculate the taxes a person has to pay (9% taxes). The person
has multiple accounts with different currencies (Dollar, Yen, Pound). The taxes should be
calculated in US-Dollar. Therefore, the other currencies should be transferred to US-Dollar.
1. Implement the abstract superclass Currency with the abstract method
dollarValue(), which returns a double value.
2. Add the subclasses Dollar, Yen and Pound which implement the abstract method
dollarValue().
3. Yen and Pound additionally need a static method to set their rate.
4. Implement the static method calculateTaxes(List<Currency> money)
Hint:
You can set the rates as follows:
1 Yen = 0.0088 Dollar
1 Pound = 1.2605 Dollar
Example:
Yen.setRate(0.0088);
Pound.setRate(1.2605);
List<Currency> money = new ArrayList<Currency>();
money.add(new USDollar(1000));
money.add(new Yen(1000));
money.add(new Pound(1000));
//Taxes are set to 9%
System.out.println("Based on your money you have to pay: " +
calculateTaxes(money) + " US-Dollar taxes");
Output: Based on your money you have to pay: 204.237 US-Dollar taxes
STYLE POINTS
Style:
To comply with the required code style you must have:
1. named your variables appropriately
2. used the different data types in a meaningful way.
3. used indention correctly
4. commented your methods e.g., JavaDoc-comments (description, parameters, return
values, …)
5. used loops or recursion for repeating code segments
6. the correct order of methods in your classes
7. commented your classes e.g., JavaDoc-comments
8. accessed class variables and methods using the respective class name
9. traversed lists using an iterator
10. commented your interfaces and abstract classes/methods e.g., JavaDoc-comments
11. used type parameters if necessary