Problems
The following problems make modifications to the code given above.
- Read an integer directly instead of reading it as
a String and then converting it into an integer
using Integer.parseInt()
- If the input given by the user is either 1, 2, 5 or 10,
display them as Roman numerals I, II, V and X
respectively. You need to modify the symbol map in this case.
The following problems need you to write simple Java programs.
- Read in a string from the user and your program should
print The string is a valid roll number if it is a
correct roll number for any student in your class. Otherwise, it
should output Invalid Input.
- It is given that 1 January 2000 fell on a Saturday. Ask users
to input a year between 2000 and 2999 (both inclusive) and
output the day of the week of 1 January of that year. The
logic for implementation is:
- Day of the week advances by one for each non-leap year
and by two for each leap year. Thus, 1 January 2001
will be on Monday(Saturday + 2) while 1 January 2004
will be on Thursday (Monday + 3).
- For a given year, add as many days as the number of
years from 2000 and then add the correct number of
days for leap years which occur once every four
years. For 2004, we would add 4 days (2004 - 2000) and
1 day for the one leap year (2000) to add a total of 5
days. Saturday + 5 = Thursday.
You can verify whether your answer is correct by using the Linux
command cal as follows: cal
1 year If will output the calendar for
January of the specified year. For example, cal 1 2020
outputs the following.
January 2020
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
- Create a 2D array of size 10x15 and fill it with random
values between 0 and 100. Ask the user to input a number between 0
and 100 and print the array location where it first occurs. If it
does not occur at all, then output an appropriate
message. Implement this program (a)using
only break and (b)using labelled
break.
You can generate random numbers as:
int random_number;
Random rand = new Random();
random_number = rand.nextInt(100) +
1
The following problems ask you to define
classes. You need not implement them.
- Define a class Book such that it contains useful
information for a buyer.
- Define a class VisitingCard for the printer, and for a
user.
- Define a class TVRemote for the user.
- Define a class MovieSong for a Quiz participant on
movie songs.
In these problems, make sure you think about when to
define
set/get methods, when to use the constructor and when
to use
general methods.