[Java] 바이오리듬 구하는 소스
-----------------------------------
★ 핵심로직 ★
신체 : (int)(Math.sin(2.0 * Math.PI * ((double)days/23.0)) * 100 + 0.5);
감성 : (int)(Math.sin(2.0 * Math.PI * ((double)days/28.0)) * 100 + 0.5);
지성 : (int)(Math.sin(2.0 * Math.PI * ((double)days/33.0)) * 100 + 0.5);
Bean 파일
import java.text.*;
import java.util.*;
public class Bio {
private String birth;
private int body;
private int feel;
private int intel;
private int bState;
private int fState;
private int iState;
private void calBio(long days){
this.body = calBody(days);
this.feel = calFeel(days);
this.intel = calIntel(days);
if(this.body > calBody(days-1)) this.bState = 1; // 상승
else this.bState = -1; // 하강
if(this.feel > calFeel(days-1)) this.fState = 1; // 상승
else this.fState = -1; // 하강
if(this.intel > calIntel(days-1)) this.iState = 1; // 상승
else this.iState = -1; // 하강
}
private int calBody(long days){
return (int)(Math.sin(2.0 * Math.PI * ((double)days/23.0)) * 100 + 0.5);
}
private int calFeel(long days){
return (int)(Math.sin(2.0 * Math.PI * ((double)days/28.0)) * 100 + 0.5);
}
private int calIntel(long days){
return (int)(Math.sin(2.0 * Math.PI * ((double)days/33.0)) * 100 + 0.5);
}
public void setBirth(String birth) throws ParseException {
long days;
this.birth = birth;
Calendar cNow = Calendar.getInstance();
DateFormat form = DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.KOREAN);
Date dNow,dBirth;
dNow = cNow.getTime();
dBirth = form.parse(birth);
days = (long)(dNow.getTime() - dBirth.getTime())/(1000*60*60*24) -1;
calBio(days);
}
public int getBody() {
return (this.body);
}
public int getFeel() {
return (this.feel);
}
public int getIntel() {
return (this.intel);
}
public int getBState() {
return (this.bState);
}
public int getFState() {
return (this.fState);
}
public int getIState() {
return (this.iState);
}
}
JSP 파일
<%@ page contentType="text/html;charset=euc-kr" %>
<%@ page import="Bio" %>
<%!
public String printState(int state){
if(state > 0) return "<font color=red>△</font>";
else return "<font color=blue>▽</font>";
}
%>
<jsp:useBean id="bio" class="Bio" scope="page">
</jsp:useBean>
<html>
<head>
<style type="text/css">
body {font-size:9pt; font-family:굴림;
</style>
<title>바이오리듬</title>
</head>
<body>
<font size=4><u><b>바이오 리듬</b></u></font>
<%
String birth;
birth = request.getParameter("birth");
if(birth == null) birth = "";
%>
<form name=f1 action="bio.jsp">
생일 : <input type=text name=birth value="<%=birth%>">
<input type=submit value="확인"> * 예 : YYYY-MM-DD ( 양력 )
</form>
<% if(!birth.equals("")){
try {
%>
<jsp:setProperty name="bio" property="birth" value="<%=birth%>" />
신체 : <jsp:getProperty name="bio" property="body" /> (<%=printState(bio.getBState())%>)<br>
감성 : <jsp:getProperty name="bio" property="feel" /> (<%=printState(bio.getFState())%>)<br>
지성 : <jsp:getProperty name="bio" property="intel" /> (<%=printState(bio.getIState())%>)<br>
<%
} catch(Exception e){
out.println("<font color=red>날짜를 정확하게 입력하세요.");
}
}
%>
</body>
</html>
'개발 관련 글' 카테고리의 다른 글
2008/12/04 자동 업데이터 (HAU, Http Auto Updater) (0) | 2009.04.15 |
---|---|
Smart Client (Web-embedded) 보안 (0) | 2009.04.15 |
마이크로소프트 개발자 컨퍼런스 비디오 무료로 보기 (0) | 2009.02.21 |
네이버에서 개발자용 폰트를 공개했군요. ;) (0) | 2009.02.21 |
새로운 MS 클라우드 플랫폼, Windows Azure을 배워 보세요! (0) | 2009.02.12 |