ERROR HANDLING AND RANDOM
1. A bag contains balls of 4 different colors- red, green, blue and yellow. Simulate picking up a ball at
random for ten times. If the same colored ball is picked more than thrice, throw SameC
...
ERROR HANDLING AND RANDOM
1. A bag contains balls of 4 different colors- red, green, blue and yellow. Simulate picking up a ball at
random for ten times. If the same colored ball is picked more than thrice, throw SameColorBallException
and proceed with the simulation once again.After 10 valid picks, print the number of balls chosen from
each of these colors.
2. Write a program to demonstrate the knowledge of students in working with user-defined packages
and sub-packages. Eg., Within the package named ‘primespackage’, define a class Primes which includes
a method checkForPrime() for checking if the given number is prime or not. Define another class named
TwinPrimes outside of this package which will display all the pairs of prime numbers whose difference is
2. (Eg, within the range 1 to 10, all possible twin prime numbers are (3,5), (5,7)). The TwinPrimes class
should make use of the checkForPrime() method in the Primes class.
3. Read the Register Number and Mobile Number of a student. If the Register Number does not contain
exactly 9 characters or if the Mobile Number does not contain exactly 10 characters, throw an
IllegalArgumentException. If the Mobile Number contains any character other than a digit, raise a
NumberFormatException. If the Register Number contains any character other than digits and alphabets,
throw a NoSuchElementException. If they are valid, print the message ‘valid’ else ‘invalid’
5. Define a class ‘Donor’ to store the below mentioned details of a blood donor.
Name, age, Address, Contact number, blood group, date of last donation Create ‘n’
objects of this class for all the regular donors at Vellore. Write these objects to a file.
Read these objects from the file and display only those donors’ details whose blood
group is ‘A+ve’ and had not donated for the recent six months.
9. Write a program to check if two given String is Anagram of each other. Your function should return
true if two Strings are Anagram, false otherwise. A string is said to be an anagram if it contains the same
characters and same length, but in a different order, e.g. army and Mary are anagrams.
10., If there are 4 batches in BTech - “CSE1007” course, read the count of the slow
learners (who have scored <25) in each batch. Tutors should be assigned in the
ratio of 1:4 (For every 4 slow learners, there should be one tutor). Determine the
number of tutors for each batch. Create a 2-D jagged array with 4 rows to store the
count of slow learners in the 4 batches. The number of columns in each row should
be equal to the number of groups formed for that particular batch ( Eg., If there are
23 slow learners in a batch, then there should be 6 tutors and in the jagged array,
the corresponding row should store 4, 4, 4, 4, 4,3). Use for-each loop to traverse the
array and print the details. Also print the number of batches in which all tutors have
exactly 4 students.
11. Write a program to read a chemical equation and find out the count of the
reactants and the products. Also display the count of the number of molecules of
each reactant and product. Eg., For the equation, 2NaOH + H2SO4 -> Na2SO4+
2H2O, the O/P should be as follows: (1) Reactants are 2 moles of NaOH, 1 mole of
H2SO4. (2) Products are 1 mole of Na2SO4 and 2 moles of H2O.
12. Assume that a bank maintains two kinds of accounts for customers, one called as
savings account and the other as current account. The savings account provides
compound interest and withdrawal facilities but no cheque book facility. The current
account provides cheque book facility but no interest. Current account holders
should maintain a minimum balance and if the balance falls below this level, a
service charge is imp
13. Assume only a maximum of 3 courses can be registered by a student for week
end semester classes. Create a hashmap ‘h1’ with ‘n’ key-value pairs where keys
are the names of students and values are the courses registered by them. Create
another hashmap ‘h2’ with ‘m’key-value pairs where keys are the names of courses
offered for B.Tech and values are the names of faculty handling the courses. Write
appropriate code to:
14. Write a program to continuously read input values from the user. The program
should terminate if exactly three String values have been inputted. Display the
count of integer values and float values entered so far. Also display the average of
all integer values and all float values individually.
15. Create a class StudentGrade with member determineGrade( ) that accepts
register number (String) and marks (float-type) of a student in all courses he has
registered for a particular semester.
16. Write a program to define a static method sum_Squares( ) to find the sum of the
squares of the first 'n' natural numbers and a non-static method square_Sum( ) to
find the square of the sum of those 'n' natural numbers. Invoke these methods
frommain( ) method to evaluate the difference between the values returned by
them.
17. The following list gives the amount of rainfall (in cms) recorded at a
particular place for 12 month. Store these values in an array. Find the
average rainfall and display the count of the number of months in which the
rainfall is more than the average. Ans
18. Write a program to print the following patterns using loops. Ans
19. Write a program called NumberGuess to play the number guessing game. The
program shall generate a random number between 0 and 99. The player inputs
his/her guess and the program shall response with "Too higher", "Too lower" or
"Congratulations! You got it.." accordingly.
20. Create a class Film with string objects which stores name, language and
lead_actor and category (action/drama/fiction/comedy). Also include an integer data
member that stores the duration of the film. Include parameterized constructor,
default constructor and accessory functions to film class. Film objects can be
initialized either using a constructor or accessor functions.
21. Write a program to demonstrate the knowledge of students in advanced
concepts of Java string handling.
22. Write a program to demonstrate the knowledge of students in creation of
abstract classes and working with abstract methods.
23. Write a program to demonstrate the knowledge of students in working
with Inheritance. Create classes to implement the following hierarchy.
24. Create Exception class called BookQuantityNotAvailableException and use it in
the class called “Store” which is described by its bookId title, author, price and
quantityAvailable. Include a method called purchase() taking the purchase quantity
as a parameter and update the quantityAvailable appropriately. Create a package
containing the Store and a Exception class. Write a java program to test the working
of the Store class. Book Store
25. You are required to compute the power of a number by implementing a
calculator. Create a class MyCalculator which consists of a single method long
power(int, int). This method takes two integers, n and p, as parameters and finds
np. If either n or p is negative, then the method must throw an exception which says
"n and p should not be negative". Also, if both n and p are zero, then the method
must throw an exception which says " n and p should not be zero " Complete the
function power in class MyCalculator and return the appropriate result after the
power operation or an appropriate exception as detailed above. Ans
26. Write a Java program to Print alternate numbers using 2 Threads. Ans
27. Write a program to generate the Tribonacci sequence. (Tribonacci numbers are a
sequence of numbers T(n) similar to Fibonacci numbers, except that a number is
formed by adding the three previous numbers, i.e., T(n)=T(n-1)+T(n-2)+T(n-3),
T(1)=T(2)=1, and T(3)=2). Ans
28. Student volunteers from three batches of B.Tech are selected to ensure the
smooth conduct of a Technical event. Assume that only 4 volunteers from batch1, 3
volunteers from batch2, 1 volunteer from batch3 are selected. Create a 2-D ragged
array of strings to store their register numbers batch wise. The first row stores
register numbers of the volunteers in batch1, second row – batch2 and so forth. Use
for-each loop to traverse the array elements.
29. An ISBN (International Standard Book Number) consists of 10
digits d1d2d3d4d5d6d7d8d9d10. The last digit d10 is a checksum,
which is calculated from the other nine digits using the following
formula:
30. VIT honors its employees with 100% attendance in an academic year
with a certificate of appreciation. Assume there are 2000 employees.
Create an array to store their attendance percentage. The array can be
populated with random numbers. Create two threads so that thread1
determines the total count of employees eligible for certificate in the first
half of the array and thread2 in second half of the array. The main( ) has
to wait till both the threads complete their task and arrive at a final count
indicating the total number of employees eligible for the certificate of
appreciation. VIThonors.java
[Show More]