Professional Documents
Culture Documents
Final Examination in CPE402 Computer Programming 2: Batangas State University
Final Examination in CPE402 Computer Programming 2: Batangas State University
FINAL EXAMINATION
in CPE402 Computer Programming 2
First Semester, AY 2020-2021
INSTRUCTIONS:
1. Read, analyze and write a java code that best describes the given situation.
2. Files must be uploaded in Google Classroom, make sure to attach your file before clicking
the Submit/Turn-in button.
3.This will take 30% of your final grade and will be graded based on the identified criteria,
see attached file.
GOOD LUCK!
1. By using do while loop, write Java program to prompt the user to choose the correct answer
from a list of answer choices of a question (minimum 10 sets of questions).
The user can choose to continue answering the question or stop answering it. See the examplebelow:
What is the command keyword to exit a loop in Java?
a. int
b. continue
c. break
d. exit
Enter your choice: b
Incorrect!
Again? press y to continue:
PROGRAM / NETBEANS
String q3 = "3. How many packages can be contained in a java program? ";
String q4 = "4. In java, an array starts counting from what number? ";
String q5 = "5. It is a name of reserved area allocated in memory. ";
String q6 = "6. Which of the following is NOT the key rule to be followed by
everu identifier? ";
String q7 = "7. It is a machine that performs a variety of tasks according to
specific instruction ";
String q8 = "8. It is the intangible part of a computer and consists of data and
the computer programs. ";
String q9 = "9. What are the programs that people use to get their work done?
";
String q10 = "10. He initiated Java language project in June 1991 for use in one
of his many set-top box projects. ";
a = "a";
b = "b";
c = "c";
d = "d";
y = "y";
//Per number
{
do
{
{
System.out.println(q1);
System.out.println("a. C" + "\nb. A" + "\nc. B" + "\nd. 1");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(c)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(c));
{
// number 2
do
{
{
System.out.println("\n" + q2);
System.out.println("a. only one" + "\nb. only two" + "\nc. multiple" + "\nd.
none");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(a)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(a));
}
{
// number 3
do
{
{
System.out.println("\n" + q3);
System.out.println("a. one" + "\nb. two" + "\nc. as many as you need" + "\nd.
none");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(c)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(c));
}
{
// number 4
do
{
{
System.out.println("\n" + q4);
System.out.println("a. 0" + "\nb. 1" + "\nc. 2" + "\nd. 3");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(a)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(a));
}
{
// number 5
do
{
{
System.out.println("\n" + q5);
System.out.println("a. Constant" + "\nb. Package" + "\nc. Variable" + "\nd.
Method");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(c)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(c));
{
// number 6
do
{
{
System.out.println("\n" + q6);
System.out.println("a. The name must not contain any white spaces. " +
"\nb. The name should not start with special characters." + "\nc. All of the
above" + "\nd. None of the above");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(d)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(d));
}
{
// number 7
do
{
{
System.out.println("\n" + q7);
System.out.println("a. Projector" + "\nb. Software" + "\nc. Computer" +
"\nd. Keyboard");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(c)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(c));
CPE402: COMPUTER PROGRAMMING2|FINALEXAM
}
Republic of the Philippines
BATANGAS STATE UNIVERSITY
Pablo Borbon Main II, Batangas City
COLLEGE OF ENGINEERING, ARCHITECTURE & FINE ARTS
www.batstate-u.edu.ph Tel. No. (043) 425-0139 loc. 118
{
// number 8
do
{
{
System.out.println("\n" + q8);
System.out.println("a. Software" + "\nb. Hardware" + "\nc. CPU" + "\nd.
Memory");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(a)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(a));
}
{
// number 9
do
{
{
System.out.println("\n" + q9);
System.out.println("a. Compilers" + "\nb. Appliction Program" + "\nc.
System Program" + "\nd. All of the above");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(b)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct.");
}
while (!ans.equals(b));
} CPE402: COMPUTER PROGRAMMING2|FINALEXAM
Republic of the Philippines
BATANGAS STATE UNIVERSITY
Pablo Borbon Main II, Batangas City
COLLEGE OF ENGINEERING, ARCHITECTURE & FINE ARTS
www.batstate-u.edu.ph Tel. No. (043) 425-0139 loc. 118
{
// number 10
do
{
{
System.out.println("\n" + q10);
System.out.println("a. James Gasling" + "\nb. James Gosling" + "\nc.
Jaymes Golsing" + "\nd. James GLosing");
System.out.print("\nEnter your choice: ");
ans = scanner.next();
}
if (!ans.equals(b)) {
System.out.println("Incorrect"+ "\nAgain? Press 'y' to retake, press 'n' to
exit");
res = scanner.next();
if (!res.equals(y)) {
System.out.println("Thank you!");
System.exit(0);
}
}
else
System.out.println("Correct. \nCONGRATULATIONS!!!");
}
while (!ans.equals(b));
}
scanner.close();
}
}
OUTPUT:
2. Write a Java program to display the speed, in meters per second, kilometers per hour andmilesper hour.
User Input : Distance (in meters) and the time was taken (as three numbers: hours, minutes, seconds).
Note : 1 mile = 1609 meters
Test Data:
Input distance in meters : 2500
Input hour : 5
Input minutes : 56
Input seconds : 23
PROGRAM / NETBEANS
float timeSeconds;
float mps,kph, mph;
scanner.close();
}
} CPE402: COMPUTER PROGRAMMING2|FINALEXAM
Republic of the Philippines
BATANGAS STATE UNIVERSITY
Pablo Borbon Main II, Batangas City
COLLEGE OF ENGINEERING, ARCHITECTURE & FINE ARTS
www.batstate-u.edu.ph Tel. No. (043) 425-0139 loc. 118
OUTPUT
3. Write a JAVA program which asks the user for his login and password. Both must be strings. After 5 wrong
attempts, the user will be rejected.
PROGRAM / NETBEANS
user = scanner.next();
System.out.println("Enter a password: ");
pass = scanner.next();
if (!user.equals("cpegroup3")
|| !pass.equals("password"))
{
System.out.println("Incorrect User/Password!!!\nTry
again...\n");
}
attempts++;
}
while ((!user.equals("cpegroup3")
|| !pass.equals("password")) && attempts != 5);
if (attempts==5)
System.out.println("Login incorrect.");
else
System.out.println("Login correct.");
scanner.close();
}
}
OUTPUT/S
GRADING CRITERIA
Prepared by: