Exercises - Individual Workshop Session - Java Advanced - Coding
Exercises - Individual Workshop Session - Java Advanced - Coding
www.sdacademy.pl
Exercise 1.
Reverse a number using while Loop. The program will prompt user to input the number
and then it will reverse the same number using while loop.
www.sdacademy.pl
Exercise 2.
Write a program that receives array size (n) from user (System.in). Next, receive n
numbers from user and put them in the array. Implement bubble sort algorithm to sort
this array in ascending order.
www.sdacademy.pl
Exercise 3.
Write a method that returns the average of a list of integers using streams.
www.sdacademy.pl
Exercise 4.
Write a method that converts all strings in a list to their upper case using streams.
www.sdacademy.pl
Exercise 5.
Given a list of strings, write a method that returns a list of all strings that start with the
letter 'a' (lower case) and have exactly 3 letters using streams.
www.sdacademy.pl
Exercise 6.
Write a method that returns a comma-separated string based on a given list of integers.
Each element should be preceded by the letter 'e' if the number is even, and preceded by
the letter 'o' if the number is odd. For example, if the input list is (3,44), the output
should be 'o3,e44'. Use streams.
www.sdacademy.pl
Exercise 7.
Create Employee class with id, name and salary fields. Create necessary methods and
constructor. Create 3 instances of the Employee class and add them to a list. Using
streams, find first Employee that is not null and has salary of at least 30000. If not found,
throw exception.
www.sdacademy.pl
Exercise 8.
Based on employees list from previous exercise, using streams create new list with
employees sorted by name.
www.sdacademy.pl
Exercise 9.
Based on employees list from exercise 7, using streams get a number representing
maximum salary of all employees.
www.sdacademy.pl
Exercise 10.
Create a shop imitating application. Create Basket class that will allow for adding,
removing and retrieving all items in the basket. Each item is an instance of Product
interface that defines two methods, one to get price of an item and one to check for
availability based on a provided date.
Create GenericProduct class that implements Product interface and will have supplier
supplying price and function checking availability based on a provided date for a
particular product.
Make sure that Basket does not expose it’s internal list storing products (meaning it will
not return a reference to it’s internal list but rather a copy), all operations on that list
should be done through Basket methods.
www.sdacademy.pl
Exercise 11.
Add some products to the Basket from exercise 11. Verify if everything works as
expected.
www.sdacademy.pl
Exercise 12.
Improve Basket from exercise 10 so that it also tracks quantity of a particular product
and allows for increment or decrement by a specified amount.
www.sdacademy.pl
Exercise 13.
Create OrderService class that accepts instance of the Basket class from exercise 12 and
returns total price for all the items in the Basket that are available. Remember about
quantity - you will have to improve Basket class again. Use streams.
www.sdacademy.pl