forked from jimthompson5802/gh_copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_java_code.java
44 lines (38 loc) · 1.2 KB
/
sample_java_code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// print hello world
public class hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
// setup connection to database
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres")
Statement stmt = conn.createStatement();
// execute query
ResultSet rs = stmt.executeQuery("SELECT * FROM table");
// print results
while (rs.next()) {
System.out.println(rs.getString("column"));
}
// function to compute value of two numbers based on an operator Commentary: this was typed by hand
public static int compute(int a, int b, String operator) {
if (operator.equals("+")) {
return a + b;
} else if (operator.equals("-")) {
return a - b;
} else if (operator.equals("*")) {
return a * b;
} else if (operator.equals("/")) {
return a / b;
} else {
return 0;
}
}
// junit test case for compute function Commentary: this was typed by hand
@Test
public void testCompute() {
assertEquals(3, compute(1, 2, "+"));
assertEquals(-1, compute(1, 2, "-"));
assertEquals(2, compute(1, 2, "*"));
assertEquals(0, compute(1, 2, "/"));
assertEquals(0, compute(1, 2, "a"));
}