Skip to content

Commit e730177

Browse files
committed
feat: add exercise boilerplate and tests
1 parent 914afac commit e730177

File tree

11 files changed

+924
-27
lines changed

11 files changed

+924
-27
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/
8+
*.iws
9+
*.iml
10+
*.ipr
11+
12+
### Eclipse ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
!**/src/main/**/build/
29+
!**/src/test/**/build/
30+
31+
### VS Code ###
32+
.vscode/
33+
34+
### Mac OS ###
35+
.DS_Store

.mvn/wrapper/maven-wrapper.jar

61.1 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

README.md

Lines changed: 143 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,143 @@
1-
# Java Exercise Template
2-
This template repository is used to create autograded Java exercise repositories for CBF Academy bootcamps. It includes a GitHub Classroom autograding workflow that scores student submissions on functionality and code quality by executing unit tests and submitting the code changes for review by an automated agent.
3-
4-
## Usage
5-
6-
1. Create a new repository for the exercise, with the following settings:
7-
- Template: Select this repository
8-
- Name: Use the `java-exercises-[exercise name]` naming convention, e.g. `java-exercises-spring-boot`
9-
- Visibility: Private
10-
2. After initialising, navigate to the repo settings and set as a template, so it can be used for assignments
11-
3. Commit README, Maven assets, starter code and unit tests to the main branch
12-
4. Create a solutions branch and commit any reference solutions code to it
13-
5. Modify the `MAX_TESTS` environment variable to reflect the total number of tests available
14-
6. Push all changes
15-
16-
## Testing
17-
18-
1. Create a new Classroom assignment using the exercise repo as the starter template, with the following settings
19-
- Repository visibility: Private
20-
- Grant students admin access to their repository: Disabled
21-
- Copy the default branch only: Enabled
22-
- Supported editor: Don't use an online IDE
23-
- Protected file paths: `.github/**/*`, `**/test/**/*`
24-
- Enable feedback pull requests: Enabled
25-
2. Accept the assignment from a test account.
26-
3. Commit and push
27-
4. Review the Actions output and Feedback PR comment to ensure everything operates as expected
1+
# Exception Handling
2+
3+
[![Java Language](https://img.shields.io/badge/PLATFORM-OpenJDK-3A75B0.svg?style=for-the-badge)][1]
4+
[![JUnit5 Testing Framework](https://img.shields.io/badge/testing%20framework-JUnit5-26A162.svg?style=for-the-badge)][2]
5+
[![Maven Dependency Manager](https://img.shields.io/badge/dependency%20manager-Maven-AA215A.svg?style=for-the-badge)][3]
6+
7+
The goal of this exercise is to practise:
8+
- Creating custom exceptions
9+
- Handling exceptions
10+
11+
For the exercises below, we've provided the starter project above.
12+
13+
## :pushpin: Exceptions
14+
15+
### Question 1
16+
17+
Is the following code legal?
18+
19+
```java
20+
try {
21+
22+
} finally {
23+
24+
}
25+
```
26+
27+
### Question 2
28+
29+
What exception types can be caught by the following handler?
30+
```java
31+
catch (Exception e) {
32+
33+
}
34+
```
35+
36+
What is wrong with using this type of exception handler?
37+
38+
### Question 3
39+
40+
Is there anything wrong with the following exception handler as written? Will this code compile?
41+
42+
```java
43+
try {
44+
45+
} catch (Exception e) {
46+
47+
} catch (ArithmeticException a) {
48+
49+
}
50+
```
51+
52+
### Question 4
53+
54+
```java
55+
int[] A;
56+
A[0] = 0;
57+
```
58+
59+
The above code produces (choose 1):
60+
61+
- [ ] an error
62+
- [ ] a checked exception
63+
- [ ] an unchecked exception
64+
- [ ] a compile error
65+
- [ ] no exception
66+
67+
### Question 5
68+
69+
The JVM starts running your program, but the JVM can't find the Java platform classes.
70+
(The Java platform classes reside in classes.zip or rt.jar.)
71+
72+
What happens (choose 1):
73+
74+
- [ ] an error
75+
- [ ] a checked exception
76+
- [ ] an unchecked exception
77+
- [ ] a compile error
78+
- [ ] no exception
79+
80+
## :pushpin: Custom Exceptions
81+
82+
Create a custom (checked) exception class called `FilenameException`.
83+
84+
Create a class called `FileExtension` with the following methods:
85+
86+
- `boolean check(String filename)`
87+
- `Map<String, int> map(List<String> filenames)`
88+
89+
The `check` method should:
90+
- return `true` when the file extension is `.java`
91+
- return `false` when the file extension is not `.java`
92+
- throw a `FilenameException` when the file name is `null` or an empty string.
93+
94+
The `map` method should:
95+
- check each provided file's extension and map the returned value as 1 if true or 0 if false
96+
- map `-1` when an exception occurs
97+
98+
**Example**
99+
100+
For the following list of file names: `Arrays.asList("App.java", "App.txt", null, "App.md")`, the `map` method should return a map with the following entries:
101+
102+
```txt
103+
{"App.java", 1},
104+
{"App.txt", 0},
105+
{null, -1},
106+
{"App.md", 0}
107+
```
108+
109+
#### :white_check_mark: Verify Your Implementation
110+
111+
To verify that your code works as expected, run the provided unit tests.
112+
113+
In your terminal, ensure that you are in the `java-exceptions` folder, then run the following command:
114+
115+
```shell
116+
./mvnw clean test
117+
```
118+
119+
If you are on Windows, run this command instead:
120+
121+
```bat
122+
mvnw clean test
123+
```
124+
125+
Your implementation is correct when all tests pass.
126+
127+
#### :information_source: Notes
128+
If you want to experiment with the provided application in the App.java file, you can run the following command from the terminal:
129+
130+
```shell
131+
./mvnw -q clean compile exec:java
132+
```
133+
```
134+
135+
Or on Windows:
136+
137+
```bat
138+
mvnw -q clean compile exec:java
139+
```
140+
141+
[1]: https://docs.oracle.com/javase/21/docs/api/index.html
142+
[2]: https://junit.org/junit5/
143+
[3]: https://maven.apache.org/

0 commit comments

Comments
 (0)