This exercise focuses on exception handling, abstract classes, and interfaces. The tasks are divided into three main sections:
Implement a program to read and display HTML content from a URL with proper exception handling:
- MalformedURLException: Retry until a valid URL is entered.
- IOException (openStream): Exit the program with an error message.
- IOException (read/close): Handle reading errors and ensure the input stream is closed in a
finally
block.
Develop a BankAccount
system:
- Class
Account
:- Methods for
withdraw
anddeposit
with exception handling. - Exceptions:
IllegalArgumentException
for invalid amounts.Exception
for overdrawing or exceeding €100,000.
- Methods for
- Class
BankApp
:- Test the
Account
class with various scenarios, ensuring expected exceptions are thrown and caught.
- Test the
Develop a vehicle simulation with a hierarchical design:
- Fields:
kind
,drivenDistance
,cumulativeCosts
. - Methods:
drive(double km)
: Updates distance and costs.abstract double costPerKM()
: To be implemented by subclasses.
- Fields:
fuelPer100km
. - Methods:
costPerLiter()
: Abstract method to calculate fuel cost.costPerKM()
: Implements the cost calculation for cars.
DieselCar
: Sets fuel cost to €1.70 per liter.GasolineCar
: Sets fuel cost to €1.60 per liter.
- Fixed cost of €0.80 per ride, regardless of distance.
Printable
: Methodvoid print()
to display vehicle details.Repairable
: Methods for repairs and maintenance.
- Test the vehicle hierarchy and methods using a predefined array of vehicles.
src/
In.java
Helper class for inputOut.java
Helper class for outputDownloadHtmlExample.java
Handles exception-based URL readingAccount.java
Implements bank account functionalityBankApp.java
Tests theAccount
classVehicle.java
Abstract base class for vehiclesCar.java
Abstract class for carsDieselCar.java
Represents diesel-powered carsGasolineCar.java
Represents gasoline-powered carsBike.java
Represents bicyclesPrintable.java
Interface for displaying detailsRepairable.java
Interface for repairs and maintenanceVehicleApp.java
Demonstrates vehicle functionalities
tests/
Testprotokolle.txt
Test cases and results for all tasks
- Programming Language: Java
- Editor: Visual Studio Code with JavaWiz extension
This project is licensed under the MIT License.