Skip to content

Commit 0a78c23

Browse files
java-object-oriented-programming-introduction-lab
0 parents  commit 0a78c23

File tree

7 files changed

+582
-0
lines changed

7 files changed

+582
-0
lines changed

.github/workflows/evaluate.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
test_files:
5+
description: 'Comma separated list of test files to download'
6+
required: true
7+
test_files_storage_location:
8+
description: 'Location to store the test files'
9+
required: true
10+
webhook_token:
11+
description: 'Token to authenticate the webhook'
12+
required: true
13+
callback_url:
14+
description: 'URL to send the results to'
15+
required: true
16+
17+
jobs:
18+
evaluate:
19+
name: Evaluate
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
25+
- name: Set up JDK 18
26+
uses: actions/setup-java@v4
27+
with:
28+
distribution: 'adopt'
29+
java-version: '18'
30+
- name: Install yq
31+
run: sudo snap install yq
32+
- name: Download the additional test files
33+
env:
34+
TEST_FILES: ${{ inputs.test_files }}
35+
TEST_FILES_STORAGE_LOCATION: ${{ inputs.test_files_storage_location }}
36+
run: |
37+
# Split the files by comma
38+
file_list=${TEST_FILES//,/ }
39+
40+
# Download the files
41+
for file in $file_list; do
42+
fn="${file##*/}"
43+
file_name="${fn%\?*}" # Get the file name
44+
echo "Downloading $file_name in $TEST_FILES_STORAGE_LOCATION"
45+
curl --create-dirs --output-dir $TEST_FILES_STORAGE_LOCATION -o $file_name $file
46+
done
47+
- name: Run the tests
48+
run: mvn test
49+
continue-on-error: true
50+
- name: Parse and send the results to the API
51+
env:
52+
WEBHOOK_TOKEN: ${{ inputs.webhook_token }}
53+
CALLBACK_URL: ${{ inputs.callback_url }}
54+
run: |
55+
# Initialize global counters
56+
total_tests=0
57+
passed_tests=0
58+
failed_tests=0
59+
60+
# Loop through all XML files in the directory
61+
for file in target/surefire-reports/*.xml; do
62+
if [ -f "$file" ]; then
63+
# Extract the total number of tests, passed tests, and failed tests using yq
64+
tests=`yq '.testsuite.+@tests' $file`
65+
failed=$((`yq '.testsuite.+@failures' "$file"` + `yq '.testsuite.+@errors' "$file"`))
66+
passed=$((tests - failed))
67+
68+
# Accumulate the results
69+
total_tests=$((total_tests + tests))
70+
passed_tests=$((passed_tests + passed))
71+
failed_tests=$((failed_tests + failed))
72+
fi
73+
done
74+
75+
# Print the results
76+
echo "Total tests: $total_tests"
77+
echo "Total passed: $passed_tests"
78+
echo "Total failed: $failed_tests"
79+
80+
curl \
81+
-X POST \
82+
-H "Content-Type: application/json" \
83+
-H "Authorization: $WEBHOOK_TOKEN" \
84+
-d "{\"passedTests\": $passed_tests, \"failedTests\": $failed_tests, \"totalTests\": $total_tests, \"commitSHA\": \"$GITHUB_SHA\"}" \
85+
$CALLBACK_URL

.gitignore

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

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Object-Oriented Programming Java Lab
2+
### Objectives
3+
1. Understand and create a new class in Java.
4+
2. Creating objects and accessing them in a class.
5+
3. Creating and invoking methods in Java
6+
4. Create constructors.
7+
5. Create instances using argument and no-argument constructors.
8+
6. Create static variables and methods.
9+
7. Invoking static methods.
10+
### Tasks
11+
1. Create a package `com.trainingmug.ecommerce` under `/src/main/java`
12+
2. Create a new Java class named `Employee` in the `com.trainingmug.ecommerce` package with the following properties:
13+
- id : `long`
14+
- name : `String`
15+
- designation : `String`
16+
- grossSalary : `float`
17+
- travellingAllowances : `float`
18+
- federalTax : `float`
19+
- stateTax : `float`
20+
21+
3. Create a no-argument constructor for Employee class to initialize the instance variables to the following.
22+
- id: 111
23+
- name : Andrew Filler
24+
- designation = Senior Software Engineer;
25+
- grossSalary = 5208.33;
26+
- federalTax = 611.86;
27+
- stateTax = 359.24;
28+
29+
30+
31+
3. Create an all-argument constructor for Employee class to initialize the
32+
instance variables.
33+
34+
5. Create a method in `Employee` class to display all the property values as follows:
35+
```java
36+
public void displayProfile() {}
37+
```
38+
39+
4. Create a method in Employee class to increase the `grossSalary` by the given percentage as follows:
40+
```java
41+
public void incrementSalary(float percentage) {}
42+
```
43+
44+
45+
6. Add the following static constant variables in Employee class:
46+
- companyName : `String`
47+
- companyContactNo : `String`
48+
- employeeCount : `long`
49+
50+
51+
52+
7. Each time the `Employee` object is created, the `employeeCount` should be incremented by 1.
53+
54+
8. Create a static method in `Employee` class to display all the static properties and the method signature as follows:
55+
56+
```java
57+
public static void displayCompanyInfo() {}
58+
```

pom.xml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.trainingmug</groupId>
8+
<artifactId>object-oriented-programming-java-lab</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.junit.jupiter</groupId>
19+
<artifactId>junit-jupiter-engine</artifactId>
20+
<version>5.9.1</version>
21+
<scope>test</scope>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-surefire-plugin</artifactId>
30+
<version>3.3.1</version>
31+
<configuration>
32+
<includes>
33+
<include>*Test.java</include>
34+
</includes>
35+
<consoleOutputReporter>
36+
<disable>true</disable>
37+
</consoleOutputReporter>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
</project>

src/main/java/Main.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.trainingmug.ecommerce;
2+
3+
4+
public class Employee {
5+
/*
6+
7+
*/
8+
9+
10+
}

0 commit comments

Comments
 (0)