/** * The data class to (de)fuzzyize a number. * This class has to be hard coded, though, which * kinda sucks. Maybe direct manipulation of the pretty * line picture would be cool!!! YEAH!!! **/ import java.awt.*; class FuzzyNumber { int iRealNum; double iFuzzyNum; int iLeftZero; int iRightOne; /** * @param iRN The real number **/ FuzzyNumber(int iRN) { iRealNum = iRN; setRightOne(65); setLeftZero(10); calcFuzNum(); } /** * @param iRN The real number to set this to **/ public void setReal(int iRN) { iRealNum = iRN; calcFuzNum(); } /** * Find out what the fuzzy number should be **/ private void calcFuzNum() { // Calc how much into slant it is int iDistance = iRealNum - iLeftZero; double dFactor = (double) 1 / (double) (iRightOne - iLeftZero); if ( iRealNum <= iLeftZero ) iFuzzyNum = 0; else if ( iRealNum >= iRightOne ) iFuzzyNum = 1; else { iFuzzyNum = (double) iDistance * dFactor; } } /** * Draw the pretty graph thing **/ public void displayGraph( Graphics g ) { g.setColor( Color.white ); g.fillRect( 20, 50, 180, 50 ); g.setColor( Color.black ); g.drawLine( 20, 95, 20 + 2 * iLeftZero, 95 ); g.drawLine( 20 + 2*iLeftZero, 95, 20 + iRightOne * 2, 55 ); g.drawLine( 20 + iRightOne * 2, 55, 200, 55 ); g.setColor( Color.blue ); g.drawLine( 20 + iRealNum * 2, 100, 20 + iRealNum * 2, 50 ); } /** * @return The fuzzy value **/ public double getFuzzyNum() { return iFuzzyNum; } /** * @param left The new value for iLeftZero **/ public void setLeftZero( int left ) { if (left < iRightOne) iLeftZero = left; } /** * @param right The new value for iRightOne **/ public void setRightOne( int right ) { if (right > iLeftZero) iRightOne = right; } }