FINAL EXAM AND COURSE OUTCOMES MATCHING
COURSE OUTCOMES
Upon successful completion of this course, students should be able to
1. analyze and design strategies for solving basic programming problems.
2. use primitive data types, selection statements, loops, methods to write programs.
3. develop programs to solve a variety of problems in math, science, business, and
games.
4. use the step-wise refinement approach.
5. use arrays to store, process, and sort data.
6. use an IDE to develop programs.
Here is a mapping of the final comprehensive exam against the course outcomes:
Question Matches outcomes
Part I(a) 2
Part I(b) 2
Part I(c) 2
Part II(a) 2
Part II(b) 2
Part II(c) 2
Part II(d) 2
Part II(e) 2, 5
Part III(a) 1, 2, 3
Part III(b) 1, 2, 3, 4
Part III(c) 1, 2, 3, 4, 5
Part VI 1, 2, 3, 4, 5
1
, Name:__________________ CSCI 1301 Final
Armstrong Atlantic State University
Covers chs 1-8 Instructor: Dr. Y. Daniel Liang
Please note that the university policy prohibits giving the exam score by email. If you need to know your
final exam score, come to see me during my office hours next semester.
I pledge by honor that I will not discuss the contents of this exam with
anyone.
Signed by ___________________ Date ___________________
Part I. (2 pts each)
a. How many times is the following loop body repeated? What is the
output of the loop?
int i = 0;
while (i < 10) {
if ((i + 1) % 2 == 0)
System.out.println(i);
i++;
}
b. Convert the following for loop into a do-while loop.
int sum = 0;
for (int i = 0; i < 100; i++) {
sum += i;
}
c. Convert the following if statement using a switch statement
// Find interest rate based on year
if (numOfYears == 7)
annualInterestRate = 7.25;
else if (numOfYears == 15)
annualInterestRate = 8.50;
else if (numOfYears == 30)
annualInterestRate = 9.0;
else {
System.out.println("Wrong number of years");
System.exit(0);
}
Part II: Show the output of the following code:
a: (2 pts)
public class Test1 {
public static void main(String[] args) {
int i = 1;
while (i < 10) {
System.out.print(i + " ");
i = i + 3;
2
, }
}
}
b. (3 pts)
Suppose the input is 2 3 4 5 0. What is the output of the
following code?
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number, max;
number = input.nextInt();
max = number;
while (number != 0) {
number = input.nextInt();
if (number > max)
max = number;
}
System.out.println("max is " + max);
System.out.println("number " + number);
}
}
c. (3 pts)
public class Test {
public static void main(String[] args) {
System.out.println(xMethod(5672));
}
public static int xMethod(int number) {
int result = 0;
while (number != 0) {
int remainder = number % 10;
result = result * 10 + remainder;
number = number / 10;
}
return result;
}
}
d. (3 pt)
public class Test {
public static void main(String[] args) {
int number = 0;
int[] numbers = new int[1];
3
, m(number, numbers);
System.out.println("number is " + number
+ " and numbers[0] is " + numbers[0]);
}
public static void m(int x, int[] y) {
x = 3;
y[0] = 3;
}
}
e. (3 pt) Suppose the input is 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4. What is the output of the following code?
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double[][] m = new double[4][4];
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
m[i][j] = input.nextDouble();
System.out.print(ttt(m));
}
public static int ttt(double[][] m) {
int sum = 0;
for (int i = 0; i < m.length; i++)
sum += m[i][i];
return sum;
}
}
4