myinteger.java
来自「tutorial for java programming」· Java 代码 · 共 54 行
JAVA
54 行
//Exercise 7.5
public class MyInteger {
//instance variable
private int value;
//constructor
public MyInteger(int value){
this.value = value;
}
//getter and setter
public int getValue(){
return value;
}
public void setValue(int value){
this.value = value;
}
//other public methods
public boolean isEven(){//do not need the parameter here
/*if (value %2 == 0 ){
}*/
return (value % 2 == 0);
}
public boolean isOdd(){//do not need the parameter here
return (value % 2 == 0);
}
public boolean equals(int another){
return (value == another);
}
public boolean equals(MyInteger another){//another is an instance in MyInteger
return (this.value == another.value);
}
public String toString(){
return value + "";//convert int(value) to string
}
//return the current instance
//i1.add(i2),update i1 and return i1
public MyInteger add(MyInteger another){
this.value += another.value;
return this;
}
public MyInteger multiply(MyInteger another){
this.value *= another.value;
return this;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?