일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- mac terminal command
- #C++ has~a
- html multimedia
- git flow
- 하이퍼레저패브릭
- relative path
- #C++ 연산자함수오버로딩
- html code
- #성적관리프로그램
- 토큰경제
- html youtube
- border-box
- html5 new tag
- html object
- #다차원포인터
- #2차원배열
- #binary
- #3차원배열
- #1차원배열
- #android activity
- #CallByAddress
- hyperledger transaction
- docker example
- html video
- #자바상속#자바이즈어#is~a
- html plug-in
- #JAVASCRIPT
- html id
- #bubbleSort
- html charset
- Today
- Total
A sentimental robot
Object oriented style exercise 본문
import java.util.Scanner;
public class Hello2 {
int num1, num2;
char a;
public void setNum1(int x) {
num1 = x;
}
public void setOp(char r) {
a = r;
}
public void setNum2(int y) {
num2 = y;
}
public int getNum1() {
return num1;
}
public char getOp() {
return a;
}
public int getNum2() {
return num2;
}
public int getRes() {
int result=0;
switch (a) {
case '+':
result = (num1 + num2);
break;
case '-':
result = (num1 - num2);
break;
case '*':
result = (num1 * num2);
break;
case '/':
result = (num1 / num2);
break;
default:
System.out.print("You put wrong item");
break;
}
return result;
}
public static void main(String[] ar) {
char ans;
do
{
Scanner sc = new Scanner(System.in);
Hello2 ss = new Hello2();
System.out.print("input number : ");
ss.setNum1(sc.nextInt());
System.out.print("+,*,-,/ : ");
ss.setOp(sc.next().charAt(0));
System.out.print("input number : ");
ss.setNum2(sc.nextInt());
// print
System.out.print(ss.getNum1());
System.out.print(ss.getOp());
System.out.print(ss.getNum2()+"=");
System.out.println(ss.getRes());
System.out.print("Continue? If you want, put Y or y:");
ans=sc.next().charAt(0);
}while(ans=='y'||ans=='Y');
}
}
'Java' 카테고리의 다른 글
Has~a (0) | 2017.12.28 |
---|---|
This (0) | 2017.12.28 |
Object-oriented style score management (0) | 2017.12.28 |
The elements of "Class" (0) | 2017.12.28 |
Score Management[Three dimensional] (0) | 2017.12.28 |