0% found this document useful (0 votes)
7 views5 pages

Lab Tasks Java

The document outlines a series of programming exercises for a Java lab, each requiring the creation of a program to solve specific problems such as determining if a number is even or odd, identifying vowels, calculating the number of days in a month, and more. Each exercise includes clear instructions on user input and expected output, covering various topics like conditional statements, loops, and mathematical calculations. The exercises aim to enhance programming skills through practical applications and problem-solving.

Uploaded by

sumbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Lab Tasks Java

The document outlines a series of programming exercises for a Java lab, each requiring the creation of a program to solve specific problems such as determining if a number is even or odd, identifying vowels, calculating the number of days in a month, and more. Each exercise includes clear instructions on user input and expected output, covering various topics like conditional statements, loops, and mathematical calculations. The exercises aim to enhance programming skills through practical applications and problem-solving.

Uploaded by

sumbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Java Lab

Submission Link:
https://forms.gle/2q5QDEBTAknUPUNn7
1) Write a program that reads an integer from the user. Then your program should
display a message indicating whether the integer is even or odd.
2) In this exercise you will create a program that reads a letter of the alphabet from the
user. If the user enters a, e, i, o or u then your program should display a message
indicating that the entered letter is a vowel. If the user enters y then your program
should display a message indicating that sometimes y is a vowel, and sometimes y is a
consonant. Otherwise your program should display a message indicating that the letter
is a consonant.
3) The length of a month varies from 28 to 31 days. In this exercise you will create a
program that reads the name of a month from the user as a string. Then your program
should display the number of days in that month. Display “28 or 29 days” for
February so that leap years are addressed.
4) The following table lists the sound level in decibels for several common noises.

Write a program that reads a sound level in decibels from the user. If the user enters a
decibel level that matches one of the noises in the table then your program should
display a message containing only that noise. If the user enters a number of decibels
between the noises listed then your program should display a message indicating
which noises the level is between. Ensure that your program also generates reasonable
output for a value smaller than the quietest noise in the table, and for a value larger
than the loudest noise in the table
5) A triangle can be classified based on the lengths of its sides as equilateral, isosceles or
scalene. All 3 sides of an equilateral triangle have the same length. An isosceles
triangle has two sides that are the same length, and a third side that is a different
length. If all of the sides have different lengths then the triangle is scalene. Write a
program that reads the lengths of 3 sides of a triangle from the user. Display a
message indicating the type of the triangle.
6) Pakistan has three national holidays which fall on the same dates each year. 23 march
Pakistan day, 14 August Independence Day, 6 September Defence Day. Write a
program that reads a month and day from the user. If the month and day match one of
the holidays listed previously then your program should display the holiday’s name.
Otherwise your program should indicate that the entered month and day do not
correspond to a fixed-date holiday
7) The year is divided into four seasons: spring, summer, fall and winter. While the exact
dates that the seasons change vary a little bit from year to year because of the way that
the calendar is constructed, we will use the following dates for this exercise:

Create a program that reads a month and day from the user. The user will enter the
name of the month as a string, followed by the day within the month as an integer.
Then your program should display the season associated with the date that was
entered
8) The horoscopes commonly reported in newspapers use the position of the sun at the
time of one’s birth to try and predict the future. This system of astrology divides the
year into twelve zodiac signs, as outline in the table below:

Write a program that asks the user to enter his or her month and day of birth. Then
your program should report the user’s zodiac sign as part of an appropriate output
message.
9) The following table contains earthquake magnitude ranges on the Richter scale and
their descriptors:
Write a program that reads a magnitude from the user and displays the appropriate
descriptor as part of a meaningful message. For example, if the user enters 5.5 then
your program should indicate that a magnitude 5.5 earthquake is considered to be a
moderate earthquake.
10) A univariate quadratic function has the form f (x) = ax2 + bx + c, where a, b and c are
constants, and a is non-zero. The roots of a quadratic function can be found by finding
the values of x that satisfy the quadratic equation ax2 + bx + c = 0. A quadratic
function may have 0, 1 or 2 real roots. These roots can be computed using the
quadratic formula, shown below: root = (−b ± √ b2 − 4ac) / 2a The portion of the
expression under the square root sign is called the discriminant. If the discriminant is
negative then the quadratic equation does not have any real roots. If the discriminant
is 0, then the equation has one real root. Otherwise the equation has two real roots,
and the expression must be evaluated twice, once using a plus sign, and once using a
minus sign, when computing the numerator. Write a program that computes the real
roots of a quadratic function. Your program should begin by prompting the user for
the values of a, b and c. Then it should display a message indicating the number of
real roots, along with the values of the real roots (if any).
11) At a particular university, letter grades are mapped to grade points in the following
manner: Write a program that begins by reading a letter grade from the user. Then
your program should compute and display the equivalent number of grade points.
Ensure that your program generates an appropriate error message if the user enters an
invalid letter grade.
In the previous exercise you created a program that converts a letter grade into the
equivalent number of grade points. In this exercise you will create a program that
reverses the process and converts from a grade point value entered by the user to a
letter grade. Ensure that your program handles grade point values that fall between
letter grades. These should be rounded to the closest letter grade. Your program
should report A+ for a 4.0 (or greater) grade point average.
12) The wavelength of visible light ranges from 380 to 750 nanometers (nm). While the
spectrum is continuous, it is often divided into 6 colors as shown below:

Write a program that reads a wavelength from the user and reports its color. Display
an appropriate error message if the wavelength entered by the user is outside of the
visible spectrum.
13) Write a program that reads a date from the user and computes its immediate
successor. For example, if the user enters values that represent 2013-11-18 then your
program should display a message indicating that the day immediately after 2013-11-
18 is 2013-11-19. If the user enters values that represent 2013-11-30 then the program
should indicate that the next day is 2013-12-01. If the user enters values that represent
2013-12-31 then the program should indicate that the next day is 2014-01-01. The
date will be entered in numeric form with three separate input statements; one for the
year, one for the month, and one for the day. Ensure that your program works
correctly for leap years.

You might also like