Created
November 14, 2022 14:07
-
-
Save solanoize/2ddc0d4aa8c0af781db793069c1339b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package contoh2; | |
| public class ContohPanggilPublik2 { | |
| public static void main(String[] args) { | |
| Kalkulator kalkulator = new Kalkulator(10, 20); | |
| System.out.println(kalkulator.kali()); | |
| System.out.println(kalkulator.bagi()); | |
| System.out.println(kalkulator.kurang()); | |
| } | |
| } |
This file contains hidden or 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
| package contoh2; | |
| //buatlah calculator menggunakan class Calculator | |
| //10 menit | |
| //- dua field (number1, number2) | |
| //- tambah, kurang, bagi, kali | |
| public class Kalkulator { | |
| private int number1; | |
| private int number2; | |
| Kalkulator(int number1, int number2) { | |
| this.number1 = number1; | |
| this.number2 = number2; | |
| } | |
| public int tambah() { | |
| return this.number1 + this.number2; | |
| } | |
| public int kurang() { | |
| return Math.abs(this.number1 - this.number2); | |
| // return this.number1 >= this.number2 ? this.number1 - this.number2 : this.number2 - this.number1; | |
| } | |
| public double bagi() { | |
| double converter = this.number1; | |
| return converter / this.number2; | |
| } | |
| public int kali() { | |
| return this.number1 * this.number2; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment