CS-212 OOP Practice Questions: Question#1
CS-212 OOP Practice Questions: Question#1
Practice Questions
Question#1:
Write a program that asks the user to enter a three-digit number, then prints the product of its
digits. A session with the program should have the following appearance:
Enter a three-digit number: 126
The product is: 12
Get the numerical input & then break it into three digits.
Hint: If n is a two-digit integer, then n%10 is the last digit in n and n/10 is n with the last digit
removed.
Question#2
Take four numbers as input from the user and determine the smallest and the largest number.
Print the results as well as the original numbers.
Sample output
Enter number: 12
Enter number: 72
Enter number: 32
Enter number: 2
Smallest Number is 2
Largest Number is 72
Question# 3
Write a program AgeIn5.java that asks the user for their name. Then display their name to prove
that your program can recall it. Ask them for their age. Then display what their age would be five
years from now. Also, display what their age was five years ago (use compound assignment)
Sample Output
Hi, Hamza! How old are you? 20
Make a simple Java calculator using switch case structure. Your program should take three
inputs from the user: operator(+ , - , / , *) and 2 numbers. It should then perform calculation
based on the numbers and operator entered by user. Display the result on the screen.
Question#5
Calculate Electricity Bill by taking units from user and calculate the total bill according to the
following criteria.
Add fuel surcharge 20% and Govt. tax 10% on bill to calculate the total bill and display it.
Question# 6
Suppose there are 4 factories and each of these factories produce items of 3 different types i.e.
bio-degradable, non-biodegradable and recyclable. We have to calculate the total products
(category wise) being produced by all factories i.e. sum of the items of each type that all 4
factories produce. Use a method based approach to implement your solution.
Bio-degradable
Non-biodegradable
Recyclable
Instructions:
The attempted solution of the practice exercises shall be compiled into a
single MS word document and submitted onto the appropriate slot on LMS.
Submit your own work. Avoid plagiarism as zero marks will be given in case
of plagiarized work.
Submission Deadline: 11th April 2021