Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
UMKD SDP2 2016-2017.docx
Скачиваний:
25
Добавлен:
14.10.2016
Размер:
126.72 Кб
Скачать

Variant 2

1) The final exam includes two parts: open test and coding, you need to send 2 files (.doc files) with the answers to the test, and a .zip file with the code.

  • Pay attention to the name of the file.

  • After the coding is done do not send only a .java file, provide the entire folder.

2) All the answers in the final test must be highlighted in red font, the answers should be short, clear, and fully disclose the meaning of the question.

3) During the coding process, the code should be properly commented, should not contain unnecessary actions, and must fulfill all the requirements according to the task.

4) The final exam is 3 hours, all the answers must be sent 5-10 minutes before the test close, in case if the student does not have time to send an answer, the evaluation of the final exam will be 0%.

5) In the file for the test at the top you need to specify which option you choose for the coding (specify either 75 or 100). 75 and 100 suggests the maximum score for the second part - the coding.

  • In the case that a student will perform the test perfectly and perfectly perform coding by 75%, the highest score will be 87.5.

  • In the case that a student will perform the test perfectly and perfectly perform coding by 100%, the highest score will be 100. 

Test (1st part of Exam)

1. Convert the hexadecimal value “ABCD” to octal. Show your work.

2. For each following expressions, specify the Java type and value that would be generated bye the expression:

Assume “a” and “b” are integer variable of the Java type “int” and “c” and “d” are approximations of real values of java type “double” with the following values:

int a = 3;

int b = 6;

double c = 5.5;

double d = -3.5;

Expression

Type

Value

a + b

b - 2.0

a / b

b / a

a % b

b % a

a + b / 4.0

(int) c + d

c + (int) d

c + b / 2 - d


3. In the space provided, show what the output generated by performing the following Java statements would be.

System.out.print("The answer is: ");

int a = 12;

int result = a / 3 + 1;

System.out.println(result);

System.out.println("The end.");

4. What would the following code display?

int sum = 0;

for (int i=0; i < 4; i++){

for (int j=i; j < 4; j++){

sum += j;

System.out.print(sum + " ");

}

System.out.println();

}

Place your output here:

5. What would the following code display? Explain your answer.

String [] data = {"John", "Susan", "Ursula", "James", "Ben", "Sharon"};

String query = "James";

int numberOfTries = 0;

for (int i=0;i<data.length;i++) {

numberOfTries++;

if (query.equals(data[i])) {

System.out.println("Sequential number of tries: "+numberOfTries+" "+data[i]);

break;

}

}

int left = 0;

int right = data.length - 1;

int middle = (left + right) / 2;

numberOfTries = 0;

while (left < right && !query.equalsIgnoreCase(data[middle])) {

if (query.compareToIgnoreCase(data[middle]) > 0) left = middle + 1;

else right = middle - 1;

middle = (left + right)/2;

numberOfTries++;

}

System.out.println("Binary number of tries: "+numberOfTries+" "+data[middle]);

Place your output here:

6. Determine what the printed output of this program will be:

String theLine = "1 two 3 five 7 8 12 13 fifteen";

Scanner theLineReader = new Scanner(theLine);

int cntr = 0;

while (theLineReader.hasNextFloat()) {

float value = theLineReader.nextFloat();

System.out.print(value + " ");

cntr++;

}

System.out.println();

System.out.println("cntr: " + cntr);

Describe program trace below.

7. Write the java code required to solve the following problem. Given the expression below, which properly determines if a specified year is a leap year, write a Java program that reads in a line from the console keyboard. If the line is empty, the program stops. If the line is not empty, the line will contain one valid. (You do not need to check for valid input!) The integer is a year. Print the year and whether it is a leap year or not.

(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)

Place your output here:

8. In the space provided, show variables value after performing the following Java code:

int x = 3, y = 5, z = 2;

if (x <= y) {

x += z;

if (z != x) { y = (x - z) / y;}

z++;

} else if (y == 0) {

y++;

z *= y;

}

--------------------------------------------------------------------------------------------

Coding (2nd part of Exam)

1) С консоли клавиатуры задается размер массива, после задается сам массив из строк (например имена Ainur, Aigerim, Samat, и т.д.), после задается 1 или 2, это будет порядок сортировки, после необходимо отсортировать массив в требуемом порядке. Алгоритм сортировки выбирается и реализуется самостоятельно.

75%

2) Дан массив чисел, например {6, 13, 2, 1, 12, 22, 56, 4, 5, 9, 8, 15, 20}, масив заполняется из консоли клавиатуры, необходимо выписать числа массива в порядке самое маленькое число, самоемаксимальное число, второе по возрастанию число (второй минимум), второе по убыванию число (второе максимальное), и т.д.

100%

Соседние файлы в предмете Программирование на Java