Cse 4102 - Object Oriented Programming Supp
Cse 4102 - Object Oriented Programming Supp
SCHOOL OF BUSINESS
DEPARTMENT OF MANAGEMENT SCIENCE
a) What is the difference between a for loop and a while loop? (2 Marks)
c) Write a Java program that accepts a character input from the user and determines
whether it is a digit or a non-digit character using a switch statement. (4 Marks)
d) Write a program in Java to prompt the user to enter the length and radius of an open
cylinder and then calculate and print its surface area and volume. (5 Marks)
e) What will be the output of the following computation based on the following?
(4 Marks)
f) Write a Java program that prompts the user to input 10 integers, stores them in an
array, and then prints the average of the values. (5 Marks)
g) Write a Java program that reads data from an input file called "input.txt" and writes the
data to two output files called "odd.txt" and "even.txt". The input file contains a list of
numbers, one number per line, and the output files should contain the odd and even
numbers, respectively. (5 Marks)
b) Write a Java program that defines a function called "factorial" that takes an integer as an
argument and returns its factorial. (5 Marks)
c) Write a Java program to calculate the sum of odd numbers from 1 to 100 using a while
loop (5 Marks)
a) Write a Java program that prompts the user to enter a number between 1 and 7 and
prints the corresponding day of the week (1 = Monday, 2 = Tuesday, etc.) (5 marks)
b) Distinguish between the operation of a while loop and a do while. Use a flowchart to
explain (4 Marks)
c) Write a program that assigns a grade to a score such that if the score is between 75 and
100 the grade is A, a score between 64 to 75, the grade is B. The score between 50 and 65
d) Explain the use of the following key words using an example (3 Marks)
i. this
ii. final
iii. implements
c) Write a Java program that defines a function called "maxValue" that takes an array of
integers and its length as arguments and returns the maximum value in the array.
(5 Marks)
d) How do you find the length of an array in Java. Use an example? (2 Mark)
c) Write a program that is able to compute the factorial of a number using a method
factorial( int x)
(5 Marks)
a) Write a Java program that defines an enumeration data type called "Month" that
represents the months of the year (January through December), and an array of strings
called "monthNames" that stores the names of the months. The program should then
prompt the user to enter a month number (starting from 1 for January) and display the
corresponding month name. (5 Marks]