# EECS 1022 3.0 Programming for Mobile Computing

## Instructions

• The piece of paper with your name on it can be used as scrap paper.
• A non-electronic dictionary may be used during the test.
• During the test, you have access to
• the slides,
• the sample code,
• the API of the Java standard library, and
• the Android API.
• No other aids may be used during the test.

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 FinalC project. The project contains the package eecs1022.finalc. 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 SINCard. Its API can be found here. The API of the Random class can be found here

## Question 2 (5 marks, partial marks)

The class `Question 2` contains the method

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

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

Input
Argument
Output
Return
1 1
3 4
5 9
7 16
9 25

## 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 H of the given height.  You may assume that the height is at least 3
* and that height is odd.  See test for sample outputs.
*
* @param height the height of the H.
*/
public static void h(int height)
{

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

### Sample input/output

Input
Argument
Output
Return
3
```* *
***
* *```
5
```*   *
*   *
*****
*   *
*   *```
7
```*     *
*     *
*     *
*******
*     *
*     *
*     *```

## Question 5 (2.5 marks, no partial marks)

The class `Question 5` contains the method

``` /**
* Tests whether the given string contains at least five digits.
* You may assume that the string is not null.
*
* @param s a string.
* @return true if the given string contains at least five digits, false otherwise.
*/
public static boolean containsAtLeastFive(String s)
{

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

### Sample input/output

Input
Argument
Output
Return
1234 false
54830 true
a1b2c3d4e5f true
abcdefgh false
8defhg7fhketd4 false

## Question 6 (2.5 marks, no partial marks)

The class `Question 6` contains the method

```/**
* Returns the product of the digits occurring in the given string.  You may assume that
* the string is not null and contains at least one digit.
*
* @param s a string.
* @return the product of the digits occurring in the given string.
*/
public static int product(String s)
{

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

Input
Argument
Output
Return
1234 24
1a5h5x1 25
12h56s9 540
aaaaaa4aaaaa 4
5a 5

## Question 7 (2.5 marks, no partial marks)

The class `Question 7` contains the method

```/**
* Returns the length of a largest gap between two identical characters.
* For example, in the string "adhbfsdgda", the substring "dhbfsdgd"
* forms a gap between the two a's since all characters of the substring
* are different from a.  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 length of a largest gap between two identical characters.
*/
public static int gap(String s)
{

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

### Sample input/output

Input
Argument
Output
Return
adhbfsdgda 8
ababbabbbabbbba 4
a 0
aa 0
abcba 3

## Submit your code

Before 21:15, submit your code as follows.

• Double click on "Home" at the top left of the desktop.
• Double click on "AndroidStudioProjects".
• Double click on "FinalC"
• Double click on "app"
• Right-click on "src" and select "Compress".
• For "Location", select "Desktop"
• Press "Create".
• Press "Close".
• Click here.
• Click on "clicking here" to select Passport York login.
• Select 1022 for Course.
• Select finalC for Assignment.
• Click browse.
• Select "src.tar.gz".
• Click "Open".
• Scroll to the bottom and click "Submit Files".
• Click "OK" to confirm your submission.

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 21:15 but before 21:20, you will get a penalty of 1 mark per minute (the test is worth 30 marks).