Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IntCaculator {
- protected int x;
- protected int y;
- IntCaculator(){
- x = 1;
- y = 1;
- }
- IntCaculator(int x, int y){
- setX(x);
- setY(y);
- }
- public void setX(int x){
- if(x == 0) this.x = 1;
- else this.x = x;
- }
- public void setY(int y){
- if(y == 0) this.y = 1;
- else this.y = y;
- }
- public int getX(){
- return this.x;
- }
- public int getY(){
- return this.y;
- }
- public int add(){
- return x+y;
- }
- public int substract(){
- return x-y;
- }
- public int multiply(){
- return x * y;
- }
- public int divide(){
- return x / y;
- }
- public static void main(String[] args){
- NewIntCaculator n = new NewIntCaculator(2, 4);
- System.out.println("X: "+n.getX());
- System.out.println("Y: "+n.getY());
- System.out.println("Divide: "+ n.divide());
- System.out.println("Mod: "+ n.mod());
- System.out.println("Min: "+ n.min());
- System.out.println("Max: "+ n.max());
- System.out.println("Pow x^y: "+n.pow());
- }
- }
- class NewIntCaculator extends IntCaculator{
- NewIntCaculator(int x, int y){
- super(x, y);
- }
- public int mod(){
- return x % y;
- }
- public int min(){
- return (x < y) ? x : (x > y) ? y : 0;
- }
- public int max(){
- return (x > y) ? x : (x < y) ? y : 0;
- }
- public int pow(){
- int rs = x;
- for(int i=1; i<y; i++)
- rs *= x;
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement