Traditional Culture Encyclopedia - Traditional virtues - I. Write a Java program to simulate a simple calculator.
I. Write a Java program to simulate a simple calculator.
private Integer n1;
private Integer n2;
/** Constructor methods */
public Number(Integer n1, Integer n2) {
super();
this.n1 = n1;
this.n2 = n2;
}
/** addition */
public Integer addition() {
System.out.println(this. n1 + this.n2);
return this.n1 + this.n2;
}
}
/** Subtraction */
public Integer subtration() {
System.out.println(this.n1 - this.n2);
return this.n1 - this.n2;
}
/** Multiplication */
public Integer multiplication() {
System.out.println(this.n1 * this.n2);
return this.n1 * this.n2;
}
/** divide */
public Integer division() {
System.out.println(this.n1 / this. n2);
return this.n1 / this.n2;
}
public Integer getN1() {
return n1;
}
public void setN1(Integer n1) {
this.n1 = n1;
}
public Integer getN2() {
return n2;
}
public void setN2(Integer n2) {
this.n2 = n2;
}
}
public static void main(String[] args) {
Number number = new Number(1, 2);
number.addition();
number. subtration();
number.multiplication();
number.division();
}
- Previous article:Is there a logistics freight company in Linfen, Shanxi?
- Next article:What glue is used for erhu skin?
- Related articles
- Top Ten Restaurants in Tianjin (Famous Restaurants in Tianjin)
- With braces will become tender cow five square braces face? I'm not sure if I'm going to be able to do this, but I'm sure I'm going to be able to.
- What are the hopes of teacher-assisted teaching equipment in multimedia classrooms?
- Pay attention to the button of the suit! ! !
- What is the difference between integrated home improvement and ordinary home improvement?
- What documents are needed to open an education and training center?
- Traditional Taiji Linglong Sword
- What problems should I pay attention to when I go to see the firefly exhibition?
- Manufacturing technology of resin ornaments
- The origin and customs of New Year's Eve are very simple. The origin and customs of New Year's Eve are very simple. Grade?One