-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Addition { | ||
/* | ||
new file --> any name | ||
new class --> Addition (accept 2 parameters, returns sum of 2 nums | ||
1) test class (first) | ||
2) write test cases for addition class | ||
3) run test case (fails) | ||
4) write code to make it pass | ||
5) naming convention | ||
6) statuc funcn --> print num of objects | ||
7) create default constructor (print statement whenever called) | ||
8) default destructor???? (print statement whenever called) | ||
*/ | ||
int num1,num2,ans; | ||
static int count=0; | ||
public int sum(){ | ||
ans=num1+num2; | ||
return ans; | ||
} | ||
public Addition() { | ||
this.num1=0; | ||
this.num2=0; | ||
count+=1; | ||
System.out.println(count+"object(s) created"); | ||
} | ||
public Addition(int num1, int num2) { | ||
this.num1 = num1; | ||
this.num2 = num2; | ||
count+=1; | ||
System.out.println(count+" object(s) created"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestAddition { | ||
@Test | ||
public static void main(String[] args) { | ||
Addition x = new Addition(1,2); | ||
assertEquals(x.sum(),3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters