1 7 8 package calculator.business; 9 10 11 import calculator.spec.State; 12 13 import com.lutris.util.KeywordValueException; 15 import com.lutris.appserver.server.session.*; 16 17 18 public class StateImpl implements State{ 19 public String checkDigits(SessionData sd)throws KeywordValueException 21 { 22 String digits = (String ) sd.get("digits"); 23 24 if (digits == null) 25 digits = "0"; 26 27 if (digits.endsWith(".0")) 29 digits = digits.substring(0, digits.length()-2); 30 31 32 35 if (digits.indexOf(".") != -1) { 36 if (digits.length() > 6) 37 { 38 digits=digits.substring(0,7); 39 40 int dot= digits.indexOf("."); 41 42 if(dot==6) 43 digits = digits.substring(0,6); 44 45 } 46 } else { 47 if (digits.length() > 7) 48 digits = "0"; } 50 51 return digits; 52 } 53 54 55 public String convertDigitsToHTML(String digits) 56 { 57 String digitHtml = ""; 59 for (int i=0; i<digits.length(); i++) { 60 char c = digits.charAt(i); 61 if (c == '0') 62 digitHtml += "<img SRC=media/zero.jpeg>"; 63 else if (c == '1') 64 digitHtml += "<img SRC=media/one.jpeg>"; 65 else if (c == '2') 66 digitHtml += "<img SRC=media/two.jpeg>"; 67 else if (c == '3') 68 digitHtml += "<img SRC=media/three.jpeg>"; 69 else if (c == '4') 70 digitHtml += "<img SRC=media/four.jpeg>"; 71 else if (c == '5') 72 digitHtml += "<img SRC=media/five.jpeg>"; 73 else if (c == '6') 74 digitHtml += "<img SRC=media/six.jpeg>"; 75 else if (c == '7') 76 digitHtml += "<img SRC=media/seven.jpeg>"; 77 else if (c == '8') 78 digitHtml += "<img SRC=media/eight.jpeg>"; 79 else if (c == '9') 80 digitHtml += "<img SRC=media/nine.jpeg>"; 81 else if (c == '-') 82 digitHtml += "<img SRC=media/dash.jpeg>"; 83 else if (c == '.') 84 digitHtml += "<img SRC=media/point.jpeg>"; 85 } 86 if (digitHtml.length() == 0) 87 digitHtml = "<img SRC=media/zero.jpeg>"; 88 89 90 return digitHtml; 91 } 92 93 94 } | Popular Tags |