Browse Source

test: adding subject and main

pull/2648/head
amin 4 months ago committed by zanninso
parent
commit
f3ba14efb0
  1. 17
      subjects/java/checkpoints/perfect-number/ExerciseRunner.java
  2. 50
      subjects/java/checkpoints/perfect-number/README.md

17
subjects/java/checkpoints/perfect-number/ExerciseRunner.java

@ -0,0 +1,17 @@
public class ExerciseRunner {
public static void main(String[] args) {
PerfectNumber perfectNumber = new PerfectNumber();
// Test case 1
int number1 = 6;
System.out.println("Is " + number1 + " a perfect number? " + perfectNumber.isPerfectNumber(number1));
// Test case 2
int number2 = 28;
System.out.println("Is " + number2 + " a perfect number? " + perfectNumber.isPerfectNumber(number2));
// Test case 3
int number3 = 12;
System.out.println("Is " + number3 + " a perfect number? " + perfectNumber.isPerfectNumber(number3));
}
}

50
subjects/java/checkpoints/perfect-number/README.md

@ -0,0 +1,50 @@
## Perfect Number
### Instructions
Write a program to check if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper positive divisors, excluding itself.
### Expected Class
```java
public class PerfectNumber {
public boolean isPerfectNumber(int number) {
// Implementation to check if the given number is a perfect number
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
PerfectNumber perfectNumber = new PerfectNumber();
// Test case 1
int number1 = 6;
System.out.println("Is " + number1 + " a perfect number? " + perfectNumber.isPerfectNumber(number1));
// Test case 2
int number2 = 28;
System.out.println("Is " + number2 + " a perfect number? " + perfectNumber.isPerfectNumber(number2));
// Test case 3
int number3 = 12;
System.out.println("Is " + number3 + " a perfect number? " + perfectNumber.isPerfectNumber(number3));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Is 6 a perfect number? true
Is 28 a perfect number? true
Is 12 a perfect number? false
$
```
Loading…
Cancel
Save