0% found this document useful (0 votes)
12 views1 page

Assignment 2

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

Assignment 2

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

Object Oriented Programming Lab

Assignment - 2

1. Write a Java program to read age of a person (Be sure that age is a positive
number) and check whether a person is eligible to vote or not.
2. Write a Java program to read age of three persons and print who is younger.
3. Write a program that asks the user to enter two numerical values (integers) and
then select an operation (addition, subtraction, multiplication and division) then
prints the result based on operation selected. (use switch statement)
Enter first number: 4
Enter second number: 2
1. Addition (+).
2. Subtraction (-).
3. Multiplication (*).
4. Division (/).
Enter operation number: 3
The result is 8

4. Write a Java program that prints all real solutions to the quadratic equation
ax2+bx+c=0. Read in a, b, c and use the quadratic formula. (use if, else if and else)
Enter a=1
Enter b=5
Enter c=1
Roots are real and unequal.
Root r1=-0.208712115252208009
Root r2=-4.7912878474779195

5. Develop a Java application to generate Electricity bill. Create a class with the
following members: Consumer no., consumer name, previous month reading,
current month reading, type of EB connection (i.e. domestic or commercial).
Commute the bill amount using the following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as
follows:
First 100 units - Rs. 1 per unit;
101-200 units - Rs. 2.50 per unit;
201 -500 units - Rs. 4 per unit;
501 units - Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as
follows:
First 100 units - Rs. 2 per unit;
101-200 units - Rs. 4.50 per unit;
201 -500 units - Rs. 6 per unit;
501 its - Rs. 7 per unit.

You might also like