0% found this document useful (0 votes)
102 views2 pages

CS-212 OOP Practice Questions: Question#1

This document contains 6 practice questions for an Object Oriented Programming (OOP) class. Question 1 asks the user to enter a 3-digit number and print the product of its digits. Question 2 takes 4 numbers as input and determines the smallest and largest. Question 3 asks for a name and age and prints what the age will be in 5 years. Question 4 makes a simple calculator using switch case. Question 5 calculates an electricity bill based on usage. Question 6 calculates total production amounts across 4 factories for 3 categories of items. Instructions are given to compile solutions into a Word doc and submit by a deadline, avoiding plagiarism.

Uploaded by

Syeda Fatima
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)
102 views2 pages

CS-212 OOP Practice Questions: Question#1

This document contains 6 practice questions for an Object Oriented Programming (OOP) class. Question 1 asks the user to enter a 3-digit number and print the product of its digits. Question 2 takes 4 numbers as input and determines the smallest and largest. Question 3 asks for a name and age and prints what the age will be in 5 years. Question 4 makes a simple calculator using switch case. Question 5 calculates an electricity bill based on usage. Question 6 calculates total production amounts across 4 factories for 3 categories of items. Instructions are given to compile solutions into a Word doc and submit by a deadline, avoiding plagiarism.

Uploaded by

Syeda Fatima
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/ 2

CS-212 OOP

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

Hamza, in five years you will be 25 years old.


And five years ago you were 15!
Question #4

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.

<=100 units Rs.4/units


> 100 and <=300 units Rs.4.50/units
>300 and <=500 units Rs.4.75/units
>500 units Rs.5/units

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.

Fact[0] Fact[1] Fact[3] Fact[4]

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

You might also like