Uploaded by hudamkhaled2006

Object Oriented Programming Assignment 1

advertisement
Spring 2025
Object Oriented Programming
Assignment 1
Name
Huda Khaled
ID
202409657
Section
55
1.
What is the output of the following statements? Suppose a and b are int variables, c is a double variable, and a =
13, b = 5, and c = 17.5.
a. System.out.println("a + b + c = " + a + b + c);
b. System.out.println(15 / 2 + c);
c. System.out.println(a / (double)(b) + 2 * c);
d. System.out.println(14 % 3 + 6.3 + b / a);
e. System.out.println((int)(c)% 5 + a - b);
f. System.out.println(13.5 / 2 + 4.0 * 3.5 + 18);
2.
A clinic wants to convert measurement of patients’ height from Feet and Inches into centimeters. Write a Java
program to ask the user to enter the patient height in Feet and Inches. The program should output the height in
centimeters.
A sample output is given below:
run:
What is the patient height:
Feet:
5
Inches:
7
The patient height in centimeters is: 170
BUILD SUCCESSFUL (total time: 20 seconds)
1/4
3.
A student will not be allowed to sit in exam if his/her attendence is less than 75%.
Write a Java program that take following input from user
- Number of classes held
- Number of classes attended.
Then ouptut
- percentage of class attended
- Is student allowed to sit in exam or not.
A sample output is given below
run:
Enter number of classes
28
20
Percentage of classes attended: 71%
The student is not allowed to sit in exam
BUILD SUCCESSFUL (total time: 20 seconds)
2/4
4.
Write a program that reads a set of integers, and then finds and prints the sum of the even and odd integers.
3/4
5.
Which of the following method heading are valid? If they are invalid, explain why.
a. public static secret(int a, int b)
b. public static int methodX
c. public static char firstMethod(int a, double x)
d. public static double larger(double a, b)
6.
Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, and
otherwise returns false. Then write a program that prompts the user to input a sequence of characters and outputs
the number of vowels.
4/4
Download