Midterm Partial Solved Questions on Software Development | CSCI 1302, Exams of Software Engineering

Material Type: Exam; Professor: Pike; Class: Software Development; Subject: Computer Science; University: University of Georgia; Term: Fall 2013;

Typology: Exams

2012/2013

Uploaded on 12/07/2013

darthaaron
darthaaron 🇺🇸

5

(1)

2 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 1302 Software Development
Fall, 2013
Thursday, October 3
Midterm Exam
(100 points)
Time: 75 minutes
Please PRINT your name:
Last Name:__________________
First Name:__________________
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Midterm Partial Solved Questions on Software Development | CSCI 1302 and more Exams Software Engineering in PDF only on Docsity!

CSCI 1302 – Software Development

Fall, 2013

Thursday, October 3

Midterm Exam

(100 points)

Time: 75 minutes

Please PRINT your name: Last Name:__________________ First Name:__________________

1. (12 points) True/False Questions:

Circle T for True or F for False, for each of the following questions. T F (1) A string is a sequence of characters. String is one primitive data type in Java language. T F (2) There are times when it is appropriate to return data from a method of a type that is inconsistent with the return type specified in the method header. T F (3) Java supports multiple inheritance. T F (4) If a class implements an interface, it cannot extend another class. T F (5) In a linked implementation of a stack, a pushed element should be added to the end of the list. T F (6) Every line in a catch block is guaranteed to be executed in all situations.

2. ( 1 8 points) Multiple choice questions:

  1. All Java classes are subclasses of the ___________________ class. a) String b) java.lang c) Java d) Class e) Object
  2. Suppose when I type the command pwd on our server nike, it shows my working directory is: /homes/lewis/CSCI1302. If I want to create a new directory called Project3 and then copy all my java source files under my working directory to the sub-directory Project3, I need to use_________________________. a) $rmdir Project $cp ./.java ./Project3/ b) $rmdir Project $scp ./.java ./Project3/ c) $mkdir Project $scp ../.java ./Project3/ d) $mkdir Project $cp ./.java ./Project3/ e) none of the above
  1. (5 points) Please find one compile-error from the following code fragment and give the correct statement. public class MyClass { int num; public MyClass(int x) { num = x; } } public class MySubClass extends MyClass { public MySubClass(int a, int b) { int c = a + b; super(c); } }
  2. (6 points) A programmer tries to create a subclass of String called MyString. When the programmer compiles her new class, the compiler produces the following message: MyString.java:1: cannot inherit from final java.lang.String public class MyString extends String { ^ 1 error Explain the cause of this error.
  1. (6 points) Consider the following code fragment. String s; for (int i = 0; i < s.length(); i++) System.out.println(s.charAt(i)); What exception will be thrown by this code and why? 5 ) (5 points) Determine the order of the following pseudocode fragment, assuming the time complexity of subprogram sub(n) is O(n). j = 1 for i = 1 to 10 j = j * 2 next i for k = 1 to j x = sub(n) + x next k 6 ) (5 points) Can a class be a parent of more than one subclass? Can a class be a child of more than one parent? Explain.
  1. (8 points) Write an enqueue method for a queue implemented as a linked structure. You may assume that the class has references to LinearNode objects called front and rear, which represent the front and rear of the queue respectively. And the class also has a variable called count, which represents the number of elements in the queue. You may also assume that the LinerNode class has a method setNext(LinearNode node), which sets the node that follows this one in the linked list. public void enqueue(T element) { 3 ) (8 points) Write a push method for a stack implemented with an array. You may assume that the stack is referenced by an array named stack, and that there is an integer variable named count that keeps track of the number of elements in the stack. You may not assume that you have access to an expandCapacity method (meaning that your method should include code to expand the capacity of the array if it is full). public void push(T element) {
  1. (10 points) Given a class PostfixEvaluator defined as follows, complete the declaration of this class. import java.util.Stack; import java.util.Scanner; /** Represents an integer evaluator of postfix expressions. Assumes the operands are integers. / public class PostfixEvaluator { private final static char ADD = '+'; private final static char SUBTRACT = '-'; private final static char MULTIPLY = ''; private final static char DIVIDE = '/'; private Stack stack; /
  • Sets up this evalutor by creating a new stack. / public PostfixEvaluator() { stack = new Stack(); } /*
  • Determines if the specified token is an operator.
  • @param token the token to be evaluated
  • @return true if token is operator / private boolean isOperator(String token) { return ( token.equals("+") || token.equals("-") || token.equals("") || token.equals("/") ); }
  • Peforms integer evaluation on a single expression
  • consisting of the specified operator and operands.
  • @param operation operation to be performed
  • @param op1 the first operand
  • @param op2 the second operand
  • @return value of the expression */ private int evaluateSingleOperator(char operation, int op1, int op2) {

5. Bonus Questions:

(5 Bonus Points!!!) Suppose that the integer array firstArray has been declared and initialized as follows: int[] firstArray = {10, 20, 30, 40, 50} Given this array, what is the result of calling the method mystery(firstArray); if mystery is defined as: public static void mystery(int[] array) { int tmp = array[array.length-1]; for (int i=1; i < array.length; i++) array[i] = array[i-1]; array[0] = tmp; } Work through the method carefully and indicate your answer by filling in the boxes below to show the final contents of firstArray :