You are on page 1of 4

Level 1:

1. Write a program that calculates the prime number up to the given integer.

2. Sales tax in New York City is 8.25%. Write a program that accepts a price on
the command line and prints out the appropriate tax and total purchase

3. Modify the sales tax program to accept an arbitrary number of prices, total
them and calculate the sales tax and print the total amount.

4. Write a program which has a method called determineDay() to determine the

day of a given date. If the given date is valid, then return the corresponding
day for that date, else return "Invalid Date".

5. Modify the previous program to add another method getDay() takes number
of days as input, adds this value to the current date and returns the day of
the resultant date as output.

6. Add tThe third method getMonth() to the same program that takes the same
input(number of days), adds this to the current date and returns the month of
the resultant date as output.

7. Return the "centered" average of an array of ints, which we'll say is the mean
average of the values, except not counting the largest and smallest values in
the array. Use int division to produce the final average. You may assume that
the array is of length 3 or more.

centeredAverage({1, 2, 3, 4, 100}) ? 3

centeredAverage({1, 1, 5, 5, 10, 8, 7}) ? 5

centeredAverage({-10, -4, -2, -4, -2, 0}) ? -3

8. Write a class that keeps a running total of all characters passed to it (one at a
time) and throws an exception if it is passed a non-alphabetic character.

Level 2:

1. Create a Circle class that contains a radius field. Give it a constructor where
you pass in the radius. Have your test routine create a few circles, assign a
value to the radius, then print out some information about the circles. Put
your Circle class and your test routine in two separate classes, like this:
public class Circle {
public double radius;
public class CircleTest {
public static void main(String[] args) {
• Give your Circle a getArea method that calculates its area, and a
printInfo method that prints out the radius and area.
• Make a program that creates an array of 100 circles, each with a
random radius. Print out the sum of the areas of the 100 circles. Also
print the biggest and smallest areas.
• Create a Rectangle class that contains width and height fields. Also
give it a getArea method.
• Create a Square class with width and getArea. Then, give both Square
and Circle setArea methods that let you specify a desired area.
• Have your Circle and Rectangle inherit from a common Shape class.
Change all your existing classes so that the fields are private and you
have getXxx and setXxx methods to lookup and change the values of
the fields. Make a method that will take an array of Shape objects and
sum their areas.
2. Create a Fraction class that will extend the abstract class Number in java.lang
package. The Fraction class will consist of a method to add two Fraction class
objects and a method to represent a Fraction object as String
3. Write a program to generate a random int in some large range. Make an
ArrayList containing that many Circle objects. Give each Circle a random
4. Loop down the list in the previous program and write a program to find the
Circle with the biggest and the smallest area. Print the result with exactly
three numbers after the decimal point.
5. Write a program to find all pairs of integers such that their sum is equal to
the given integer number N and the second number results from the first one
by striking out one of its digits. The first integer always has at least two digits
and starts with a non-zero digit. The second integer always has one digit less
than the first integer and also starts with a non-zero digit. The input number
consists of a single integer N (10 <= N <= 100000). If the given input
doesn’t satisfy the given constraints then return -1.

• The first integer must contain same number of digits of given
• The second integer must be less than one digits of given input.

Example 1:

Value : 256

Combinations are,
1. 233 + 23
2. 228 + 28
3. 214 + 42
4. 178 + 78

No. of Combinations : 4

Example 2:

Value : 7567

Combinations are,
1. 7324 + 243
2. 7289 + 278
3. 7280 + 287
4. 7243 + 324
5. 6869 + 698
6. 6807 + 760
7. 6798 + 769
8. 6781 + 786
9. 6698 + 869

No. of Combinations : 9

6. An organization decides to cross train the employees on multiple products.

Write a program that takes a list of employees and products as input. Assign
more than one product to each employee. Print the name and the no of
employees working in a product, if the user input is product. And print the
list of products is the user input is an employee.
7. Define and implement your own exception, for any one of the above

Level 3:

1. Write a coin-flipping class using Thread. The program to start 5 threads, have
each flip 1000 coins and print out whenever they get 3 consecutive heads. In
the printouts, you can use the Thread getName method to identify the
thread. Write the same thing with Runnable.

2. A person may play one or more of the following games (cricket, football,
basketball, tennis). Write a program that takes the player name as input and
displays the game he plays. Design the most optimal way to store this

3. Write a program to demonstrate the difference between shallow / deep copy

4. Company A wants a program for ticket booking. Later it realizes that it needs
a generalized template for ticket booking (Air ticket, Train, Bus). A
programmer raised a question why can’t we have a generalized booking
template(Hotel, Cab, Travel, Movie) so that the general booking template can
be used for ticket booking template from which classes can be developed
.Write a program for implementing the scenario.