자바 기초: 계산기

김영채 (Kevin)·2020년 3월 16일
0

Java

목록 보기
1/6
post-thumbnail

자바프로그래밍 기초 수업을 들은 적이 있다. 그때 배운 내용을 조금이나마 기록하고 싶어서 해당 시리즈를 새로 작성하게 됐다. 코드가 좀 번잡하지만 양해 바란다.


public class CalculatorForFourArithmeticOperators {
	

	class CalculatorForFourArithmeticOperators implements Calculator {

	    int numberOfArithmeticOperatorProcessed = 0;

	    public static void main(String[] args) {

	        // create myCalculator instance from CalculatorForFourArithmeticOperators class! 
	        CalculatorForFourArithmeticOperators myCalculator = new CalculatorForFourArithmeticOperators();

	        System.out.println("SUM: " + myCalculator.sum(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
	        System.out.println("SUBTRACT: " + myCalculator.subtract(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
	       // System.out.println("MULTIPLY: " + myCalculator.multply(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
	        System.out.println("DIVIDE: " + myCalculator.divide(Integer.parseInt(args[0]), Integer.parseInt(args[1])));

	        myCalculator.displayNumberOfArithmeticOperatorProcessed();
	    }

	    public int sum(int firstNumber,int secondNumber) {
	        numberOfArithmeticOperatorProcessed++;
	        return firstNumber+secondNumber;
	    } // sm --> sum

	    public int subtract(int firstNumber,int secondNumber) {
	        numberOfArithmeticOperatorProcessed++;
	        return firstNumber-secondNumber;
	    }// subtrct --> subtract

	    public int divide(int firstNumber,int secondNumber) {
	        numberOfArithmeticOperatorProcessed++;
	        return firstNumber/secondNumber;
	    }

	    public void displayNumberOfArithmeticOperatorProcessed(){
	        System.out.println("The number of arithmetic operators processed!: " + numberOfArithmeticOperatorProcessed);
	    }
	}
}

profile
맛있는 iOS 프로그래밍

0개의 댓글