Associate Java
Associate Java
Instructions
This test consists of multiple programming problems, for each of which a Java
program must be written that achieves the desired output.
Treat each problem as a real-world problem and develop a production-quality
solution. Weightage will be given to the overall solution quality, including
completeness, correctness, extensibility, naming conventions, comments and
automated tests.
Submit your solutions through a Github repository. Each solution must be
submitted as a separate class file. Class files containing multiple solutions will be
ignored and not considered part of the submission.
Minimum 70% solutions must be correct for selection.
Problem 1
Write a program that prints the number of digits in an integer. For example, given the
integer “34” (without quotes) as the input, the program must print “2” (without quotes)
as the output, given “-7291” (without quotes), the program must print “4” (without
quotes), and so on.
Problem 2
A supermarket sells thousands of products. Every product is properly packaged and
the product packaging shows the total price a customer must pay for the product.
The total product price includes taxes and the rate of taxation varies from product to
product. For legal reasons, the supermarket must provide invoices to every customer
that show the price of each product before taxes, the tax rate and the tax amount.
Write a program that takes the net price of a product including taxes and the tax rate,
and computes the gross price before taxes. The table below shows some examples
for the expected output of the program.
Page 1 of 4
TechHaus Software Services Private Limited
Problem 3
Write a program that accepts two numbers and returns the larger of the two.
Problem 4
Write a program that finds the median of a sorted array of numbers, where the
median of an array is defined as the number exactly in the middle of the sorted array.
When the array contains an odd number of numbers, the median is the number
exactly in the middle and when the array contains an even number of numbers, the
median is the average of the two numbers exactly in the middle. The table below
shows some sorted arrays, their middle elements and their medians.
Array Median
10.7 10.7
1.0, 2.0, 3.0 2.0
17.4, 21.1, 39.7, 48.0 (21.1 + 39.7) / 2 = 60.8 / 2 = 30.4
-957.0, -493.0, -384.0, -268.0, -131.0 -384.0
If the array does not contain any number, the program must return -1.0.
Problem 5
Write a program that computes the income tax for a person having specified income,
using the income tax rates shown below.
Taxable Income Income Tax Rate
Up to Rs.2,50,000 0%
More than Rs.2,50,000 and up to 10% of income over Rs.2,50,000
Rs.5,00,000
More than Rs.5,00,000 and up to 10% of income over Rs.2,50,000 +
Rs.10,00,000 20% of income over Rs.5,00,000
More than Rs.10,00,000 10% of income over Rs.2,50,000 +
Page 2 of 4
TechHaus Software Services Private Limited
The table below shows some examples of how the tax rates shown above must be
applied for computing the income tax.
Problem 6
Write a program that finds the string having the most number of vowels from an array
of strings. For example, given the array “Sunshine” (3 vowels), “Umbrella” (3
vowels), “Major” (2 vowels), “Resourceful” (5 vowels), the program must return the
string “Resourceful”.
Problem 7
Retail inflation is the average yearly increase in prices of common goods sold in
retail. For example, if the prices of common goods increase on an average by 10% in
a year, the retail inflation is said to be 10%.
Write a program that accepts the rate of retail inflation and number of years, and
prints the compounded inflation at the end of the specified number of years. For
example, if the retail inflation rate is specified as 20% and number of years as 5, the
compounded retail inflation at the end of 5 years will be 1.25 = 2.49 = 149%.
Page 3 of 4
TechHaus Software Services Private Limited
Problem 9
A two-digit special integer is obtained by adding its individual digits to the product of
the digits. For example, the special two-digit integer “59” is obtained as “5 + 9 + 5 x 9
= 5 + 9 + 45”.
Write a program that accepts an integer and determines if it is a two-digit special
integer.
Problem 10
Write a program that finds the second largest number from an array of unsorted
numbers.
Page 4 of 4
TechHaus Software Services Private Limited