01 · Basics
- variables
- primitive types
- if / else
- for/while loops
End of the Java Course
Congratulations: you have made it through the 4 modules of the Java Course — from basic variables and loops to OOP encapsulation, inheritance, interfaces, and using ArrayList. Below is a map of everything you have mastered and a three-step final challenge.
Reminder: Java exercises are verified statically (keywords). To actually run the code, each exercise provides a OneCompiler button that copies the code and opens the sandbox.
Combine what you have learned about Java by building three components: a method to calculate discounted prices, a class hierarchy for bank accounts, and a billing utility using interfaces and dynamic lists.
Write a static method that calculates the total price, applying a 10% discount if the purchased quantity is at least 10. Module 1 (variables and control flow).
Define the method public static double getDiscountedPrice(double price, int quantity) that returns the total price. If quantity is 10 or more, apply a 10% discount (multiply by 0.9).
Use an if statement to check if the quantity is greater than or equal to 10 and multiply accordingly.
Solution available after 3 attempts
Implement the SavingsAccount class extending Account, calling the parent constructor and adding a method to accumulate interest. Modules 2 & 3 (OOP).
Write the SavingsAccount class extending Account. Define a constructor accepting balance and interestRate and call super(balance). Implement the method public void addInterest() that increases balance by adding balance * interestRate.
Use extends Account to inherit, super(balance) in the constructor to initialize the balance, and modify the protected balance field in addInterest().
Solution available after 3 attempts
Implement a Taxable interface and an Invoice class that stores product prices in an ArrayList to calculate the total tax. Module 4 (interfaces and collections).
Complete the Invoice class which implements the Taxable interface. Add the addItem(double price) method to insert items into items, implement getTaxRate() to return 0.22 (22% tax), and getTaxAmount() to calculate the total tax (sum of items multiplied by the tax rate).
addItem should call items.add(price). getTaxAmount() should iterate through the list using a for-each loop, sum the elements, and multiply the sum by getTaxRate().
Solution available after 3 attempts
A single page with all the essential syntax of modern Java, ready to keep handy while you code.
Consistent practice is the best way to strengthen your skills. Open the Java Playground to experiment freely with complex scenarios or to prepare your code snippets before testing them on OneCompiler.