GUI 실습 - Calculator

/src
ㄴ/controller
	ㄴCal_controller.java
ㄴ/model
	ㄴCal_model.java
ㄴ/view
	ㄴCal_view.java

Model

package model;

public class Cal_model {
	private String op;
    private double firstValue;
    private double secondValue;
    private double result;
    private double text;
    
    public void calculate(String op, double first, double second) {
    		switch(op){
	        case "+" :
	            setResult(plus(first,second));
	            break;
	        case "-" :
	        		setResult(minus(first,second));
	            break;
	        case "*" :
        			setResult(multiply(first,second));
        			break;
	        case "/" : 
	        		setResult(divide(first,second));
	            break;
	        default:
	        		break;
	    }
    }
    
    
	public double plus(double first,double second) {

		return first+second;
    }
    public double minus(double first,double second) {
		return first-second;
    }
    public double multiply(double first,double second) {
		return first*second;
    }
    public double divide(double first,double second) {
		return first/second;
    }
	public String getOp() {
		return op;
	}
	public void setOp(String op) {
		this.op = op;
	}
	public double getFirstValue() {
		return firstValue;
	}
	public void setFirstValue(double firstValue) {
		this.firstValue = firstValue;
	}
	public double getSecondValue() {
		return secondValue;
	}
	public void setSecondValue(double secondValue) {
		this.secondValue = secondValue;
	}
	public double getResult() {
		return result;
	}
	public void setResult(double result) {
		this.result = result;
	}
	public double getText() {
		return text;
	}
	public void setText(double text) {
		this.text = text;
	}
}

View

Controller

Last updated

Was this helpful?