자바 커스텀클래스를 이용한 취업률 계산

문제

해결방안

Main2.java

package pack_CustomClassBasic;

public class Main2 {

	public static void main(String[] args) {
		
		int employedNum = 160;
		int graduatedNum = 245;
		EmployRate employRate = new EmployRate(employedNum, graduatedNum);
		double res = employRate.mtdCalc();
		System.out.printf("취업률 : %.1f%%", res);
	}

}

EmployRate.java

package pack_CustomClassBasic;

public class EmployRate {
	
	int employedNum; // 취업자 수
	int graduatedNum; // 졸업자 수
	
	public EmployRate(int employedNum, int graduatedNum) {
		this.employedNum = employedNum;
		this.graduatedNum = graduatedNum;
		
	}
	
	public double mtdCalc() {
		double res = ((double)employedNum/graduatedNum) * 100;
		
		return res;
	}

}

결과

좋은 웹페이지 즐겨찾기