Programming Assignment 3
Programming Assignment 3
Programming Assignment-III
(Conditional Statements)
Question-1:
Write a program to input the age of a person and check if the age of the person is
greater than or equal to 18 then print the message:
“You are eligible to cast your vote”.
Question-2:
Alice visited SUM hospital to get treatment for her fever and illness. Doctor advised
her to drink at least 5000 ml of water each day. Alice drank x ml of water today. Write
a program that print the following message depending on the value of x.
Question-3:
Write a program that reads three integers from the user and prints "Increasing" if the
numbers are in increasing order, "Decreasing" if the numbers are in decreasing order,
and "Neither increasing nor decreasing order" otherwise.
Question-6:
Write a java program to calculate the monthly electricity bill. The tariff is given as
follows:
Price per unit Unit range
Rs. 3/- First 50 units
Rs. 4.80/- 50-200 units
Rs. 5.80/- 200-400 units
Rs. 6.20/- Above 400 units
Question-7:
From the above question no. (6) write a java program with a choice if the consumer
wants to pay bill online. Consumer who pays their electricity bill online will get a
discount of 3%.
Here is the sample output:
No. of units consumed: 867
Do you want to pay online(y/n): y
Total amount: 4925.4
Discount: 147.762
Amount payable: 4777.638
Question-8:
Write a java program that takes the x – y coordinates of a point in the Cartesian plane
and prints a message telling either an axis on which the point lies or the quadrant in
which it is found.
Here is the sample output:
(-1.0, -2.5) is in quadrant III
(0.0, 4.8) is on the y-axis
Question-9:
Write a program to input 3 integer number a, b, c. Find the largest number among 3.
Also find the 2nd largest number among 3. Here is the sample output:
Enter the value of a, b, c:10 30 50
Largest number: 50
2nd largest number: 30
Question-10:
A University conducts a 100-mark exam for its student and grades them as follows.
Assigns a grade based on the value of the marks. Write a java program to print the
grade according to the mark secured by the student. [Use switch-case].
Question-2:
Write a java program that prompts the user to enter an integer for today’s day of the
week (Sunday is 0, Monday is 1… and Saturday is 6). Also prompt the user to enter
the number of days after today for a future day and display the future day of the week.
Here is a sample run:
Enter today's day: 1
Enter the number of days elapsed since today: 3
Today is Monday and the future day is Thursday
Enter today's day: 0 Enter the number of days elapsed
since today: 31
Today is Sunday and the future day is Wednesday
Question-3:
Write a java program that randomly generates an integer between 1 and 12 and displays
the English month name January, February… December for the number 1, 2… 12,
accordingly.
Question-4:
Write a java program that prompts the user to enter an integer and determines whether
it is divisible by 5 and 6, whether it is divisible by 5 or 6, and whether it is divisible
by 5 or 6, but not both.
Here is a sample run of this program:
Enter an integer: 10
Is 10 divisible by 5 and 6? false
Is 10 divisible by 5 or 6? true
Is 10 divisible by 5 or 6, but not both? True
Question-5:
Write a java program which displays an appropriate name for a person, using a
combination of nested ifs and compound conditions. Ask the user for a gender, first
name, last name and age. If the person is female and 20 or over, ask if she is married.
If so, display "Mrs." in front of her name. If not, display "Ms." in front of her name. If
the female is under 20, display her first and last name. If the person is male and 20 or
over, display "Mr." in front of his name. Otherwise, display his first and last name. Note
that asking a person if they are married should only be done if they are female and 20
or older, which means you will have a single if and else nested inside one of your if
statements. Also, did you know that with an if statements (or else), the curly braces are
optional when there is only one statement inside?
What is your gender (M or F): F
First name: Gita
Last name: Pattanayak
Age: 32
Are you married, Gita (y or n)? y
Then I shall call you Mrs. Gita Pattanayak.
What is your gender (M or F): F
First name: Anjali
Last name: Mishra
Age: 48
Are you married, Anjali (y or n)? n
Then I shall call you Ms. Anjali.
What is your gender (M or F): M
First name: Ashok
Last name: Mohanty
Age: 23
Then I shall call you Mr. Ashok.
What is your gender (M or F): M
First name: Rahul
Last name: Pati
Age: 15
Then I shall call you Rahul Pati
***********************