📄 myinteger.java
字号:
//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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -