JAva結婚アルゴリズム

5629 ワード

package test.ibridge.hnwis.sys;

import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Calendar;  
import test.ibridge.hnwis.sys.BaZi;  
import test.ibridge.hnwis.sys.LuozhuangshenshaHehun;  
import test.ibridge.hnwis.sys.luozhuanglvhehun; 

public class test {
	
	LuozhuangshenshaHehun myLuozhuangshenshaHehun = new LuozhuangshenshaHehun();  
    luozhuanglvhehun myluozhuanglvhehun = new luozhuanglvhehun();  
  
    /** 
     * 
     * @param man    yyyy-MM-dd HH 
     * @return      
     * @throws ParseException 
     */  
    public String paipan(String man, luozhuanglvhehun.sex isman) throws ParseException {  
  
        Calendar mancal;  
  
        try {  
            mancal = myLuozhuangshenshaHehun.getCalendarfromString(man, "yyyy-MM-dd HH");  
            //   private        
        } catch (ParseException ex) {  
            return "     " + ex.getMessage();  
        }  
  
        return paipan(mancal, isman);  
  
    }  
  
  
    /**           
     * 
     * @param jiazhi 
     * @param yuezhu 
     * @return 
     */  
    public int getyuezhuStart(String[] jiazhi, String yuezhu) {  
  
        int start = -1;  
        for (int i = 0; i < jiazhi.length; i++) {  
            if (yuezhu.equals(jiazhi[i])) {  
                start = i;  
                break;  
            }  
  
        }  
  
        return start;  
    }  
//       
  
    private String[] shundayun(String yuezhu) {  
  
        String[] DayunStringArray = new String[8];//     
  
        String[] jiazhi = myluozhuanglvhehun.jiazhi;  
        int start = getyuezhuStart(jiazhi, yuezhu);  
        if (start == -1) {  
            return null;  
        }  
        else  
        {  
        start++;  
        }  
        for (int i = 0; i < 8; i++) {  
            DayunStringArray[i] = jiazhi[(start + i) % jiazhi.length];  
        }  
  
        return DayunStringArray;  
  
    }  
//       
  
    private String[] nidayun(String yuezhu) {  
        String[] DayunStringArray = new String[8];//     
  
        String[] jiazhi = myluozhuanglvhehun.jiazhi;  
        int start = getyuezhuStart(jiazhi, yuezhu);  
        if (start == -1) {  
            return null;  
        }  
         else  
        {  
               start--;  
        }  
        for (int i = 0; i < 8; i++) {  
            DayunStringArray[i] = jiazhi[(start - i) % jiazhi.length];  
        }  
  
        return DayunStringArray;  
  
    }  
    //        
  
    public String[] Dayun(String nianzhu,String yuezhu, luozhuanglvhehun.sex isman) {  
        String[] DayunStringArray = null;  
        if (yuezhu == null || yuezhu.length() != 2) {  
            return null;  
        }  
  
  
        // 、 、 、 、     , 、 、 、 、       
        //     (      ),          
        if (nianzhu.startsWith(" ") || nianzhu.startsWith(" ") || nianzhu.startsWith(" ") || nianzhu.startsWith(" ") || nianzhu.startsWith(" ") || nianzhu.startsWith(" ")) {  
            if (isman == luozhuanglvhehun.sex.man) {//    
               DayunStringArray= shundayun(yuezhu);  
            } else {  
                DayunStringArray=nidayun(yuezhu);  
            }  
  
        } else {  
            if (isman == luozhuanglvhehun.sex.man) {  
               DayunStringArray= nidayun(yuezhu);  
            } else {  
                DayunStringArray=shundayun(yuezhu);  
            }  
  
        }  
        return DayunStringArray;  
    }  
  
    private String paipan(Calendar cal, luozhuanglvhehun.sex isman) throws ParseException {  
  
        BaZi lunar = new BaZi(cal);  
        System.out.println("       【" + lunar.toString() + "】");  
        /** 
         *         23:00-1:00        。 
         *   24.00-2.00,  2.00-4.00,  4.00-6.00,  6.00-8.00, 
         *   8.00-10.00,  10.00-12.00,  12.00-14.00,  14.00-16.00 
         *   16.00-18.00,  18.00-20.00,  20.00-22.00,  22.00-24.00 
         * 
         */  
        int time = cal.get(Calendar.HOUR_OF_DAY) / 2;  
        System.out.println("    【" + lunar.getYearGanZhi(time) + "】");  
        //      
        System.out.println("       【" + lunar.animalsYear() + "】");  
  
  
  
        String GanZhi = lunar.getYearGanZhi(time);//     
        String[] tempchar = GanZhi.split(",");  
        //      , ,    
        String ganziyear = tempchar[0];//    
        String ganzimonth = tempchar[1];//    
        String ganziday = tempchar[2];//    
        String ganzitime = tempchar[3];//    
  
        //      
  
        String soundyear = myLuozhuangshenshaHehun.getnumsix(ganziyear);  
        String soundmonth = myLuozhuangshenshaHehun.getnumsix(ganzimonth);  
        String soundday = myLuozhuangshenshaHehun.getnumsix(ganziday);  
        String soundtime = myLuozhuangshenshaHehun.getnumsix(ganzitime);  
  
        String[] DayunArray = Dayun(ganziyear,ganzimonth, isman);  
        pringst(DayunArray);  
        return null;  
    }  
  
    public static void pringst(String[] res) {  
        for (int i = 0; i < res.length; i++) {  
            System.out.print(res[i]);  
            System.out.print("   ");  
        }  
        System.out.println("");  
    }  
          
    /** 
     * @param args the command line arguments 
     */  
    public static void main(String[] args) throws ParseException {    
    	
    	test my = new test();  
     
    	my.paipan("2000-3-13 11", luozhuanglvhehun.sex.man);   
    }  
    
}