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
finallyblock.
Develop a BankAccount system:
- Class
Account:- Methods for
withdrawanddepositwith exception handling. - Exceptions:
IllegalArgumentExceptionfor invalid amounts.Exceptionfor overdrawing or exceeding €100,000.
- Methods for
- Class
BankApp:- Test the
Accountclass 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.javaHelper class for inputOut.javaHelper class for outputDownloadHtmlExample.javaHandles exception-based URL readingAccount.javaImplements bank account functionalityBankApp.javaTests theAccountclassVehicle.javaAbstract base class for vehiclesCar.javaAbstract class for carsDieselCar.javaRepresents diesel-powered carsGasolineCar.javaRepresents gasoline-powered carsBike.javaRepresents bicyclesPrintable.javaInterface for displaying detailsRepairable.javaInterface for repairs and maintenanceVehicleApp.javaDemonstrates vehicle functionalities
tests/
Testprotokolle.txtTest cases and results for all tasks
- Programming Language: Java
- Editor: Visual Studio Code with JavaWiz extension
This project is licensed under the MIT License.