EECS 1022 3.0 Programming for Mobile Computing

Final Exam - Version A
15:30-16:45 on July 27, 2017

Instructions

You are strongly encouraged to submit your work regularly (how to submit your work can be found at the bottom of this page).

Before you start

Start Android Studio. Open the FinalA project. The project contains the package eecs1022.finala. The package contains the classes Question1, Question2, ..., Question7. If you cannot find these classes, please let the teaching assistant know.

Question Marks Partial marks?
1 10 yes
2 5 yes
3 5 yes
4 2.5 no
5 2.5 no
6 2.5 no
7 2.5 no

Question 1 (10 marks, partial marks)

Implement the class Interval. Its API can be found here.

Question 2 (5 marks, partial marks)

The class Question 2 contains the method

/**
 * Returns the value of 1 + 2 + ... + n.  You have to use a loop to solve this question.
 * You may assume that n is greater than 0.
 *
 * @param n a positive integer.
 * @return the value of 1 + 2 + ... + n
 */
public static int sum(int n)
{

}
Implement this method using a loop. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
1 1
2 3
3 6
4 10
5 15

Question 3 (5 marks, partial marks)

The class Question 3 contains the method

/**
 * Print the following pattern of the given length.  You may assume that the given length
 * is greater than or equal to 0.
 * The pattern is: *+*+*+*+*+*+*+*+*+*+*+*...
 *
 * @param length the length of string to be printed.
 */
public static void pattern(int length)
{

}
Implement this method. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
1 *
4 *+*+
9 *+*+*+*+*
11 *+*+*+*+*+*
34 *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+

Question 4 (2.5 marks, no partial marks)

The class Question 4 contains the method

/**
 * Prints Z of the given height.  You may assume that the height is at least 3.
 * See test for sample outputs.
 *
 * @param height the height of the Z.
 */
public static void z(int height)
{

}
Implement this method. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
3
***
 * 
***
4
****
  * 
 *  
****
5
*****
   * 
  *  
 *   
*****
6
******
    * 
   *  
  *   
 *    
******
7
*******
     * 
    *  
   *   
  *    
 *     
*******

Question 5 (2.5 marks, no partial marks)

The class Question 5 contains the method

 /**
  * Tests whether the digits occurring in the given string are in strictly increasing order.
  * You may assume that the string is not null.
  *
  * @param s a string.
  * @return true if the digits occurring in the given string are in strictly increasing order,
  * false otherwise.
  */
public static boolean isIncreasing(String s)
{

}
Implement this method. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
a1a2a3a true
a1a1a2a false
1b2c3d true
aaaa1aa2aa3aaaa true
910 false

Question 6 (2.5 marks, no partial marks)

The class Question 6 contains the method

/**
 * Returns the sum of the digits occurring in the given string.  You may assume that
 * the string is not null and not empty.
 *
 * @param s a string.
 * @return the sum of the digits occurring in the given string.
 */
public static int sum(String s)
{

}
Implement this method. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
1234 10
1a5h5x1 12
12h56s9 23
aaaaaa4aaaaa 4
5a 5

Question 7 (2.5 marks, no partial marks)

The class Question 7 contains the method

/**
 * Returns the number of occurrences of a most occurring character in the given string.
 * You may assume that the string is not null and not empty.  You may may also assume
 * that all characters are lower case letters.
 *
 * @param s a string.
 * @return the number of occurrences of a most occurring character in the given string.
 */
public static int mostOccurrences(String s)
{

}
Implement this method. Below you find some sample inputs and outputs.

Sample input/output

Input
Argument
Output
Return
a 1
ab 1
abc 1
abca 2
aaa 3

Submit your code

Before 16:45, submit your code as follows.

You can repeat the above steps as many times as you like throughout the test. Every submission overwrites the previous one. Submission of a file does not imply that you cannot continue to work on the file and resubmit it.

If you submit after 16:45 but before 16:50, you will get a penalty of 1 mark per minute (the test is worth 30 marks).