1 16 package org.getahead.dwrdemo.gidemo; 17 18 import java.math.BigDecimal ; 19 import java.text.SimpleDateFormat ; 20 import java.util.Date ; 21 import java.util.Random ; 22 23 27 public class Corporation 28 { 29 35 public Corporation(String jsxid, String name) 36 { 37 this.jsxid = jsxid; 38 this.name = name; 39 40 float temp = random.nextFloat() * 100.0F; 41 last = new BigDecimal (Math.round(temp * 100.0F) / 100.0F); 42 last = last.setScale(2, BigDecimal.ROUND_UP); 43 time = new Date (); 44 change = new BigDecimal (0.0F); 45 change = change.setScale(2, BigDecimal.ROUND_UP); 46 max = last; 47 min = last; 48 } 49 50 private String jsxid; 51 52 private String name; 53 54 private BigDecimal last; 55 56 private Date time; 57 58 private BigDecimal change; 59 60 private BigDecimal max; 61 62 private BigDecimal min; 63 64 private Random random = new Random (); 65 66 69 public String getJsxid() 70 { 71 return jsxid; 72 } 73 74 77 public String getName() 78 { 79 return name; 80 } 81 82 85 public BigDecimal getLast() 86 { 87 return last; 88 } 89 90 93 public String getTime() 94 { 95 return FORMAT.format(time); 96 } 97 98 101 public BigDecimal getChange() 102 { 103 return change; 104 } 105 106 109 public BigDecimal getMax() 110 { 111 return max; 112 } 113 114 117 public BigDecimal getMin() 118 { 119 return min; 120 } 121 122 125 public void change() 126 { 127 float newChange = (random.nextFloat() * 4) - 2; 128 newChange = Math.round(newChange * 100.0F) / 100.0F; 129 130 if (last.floatValue() + newChange < 9) 131 { 132 newChange = -newChange; 133 } 134 135 change = new BigDecimal (newChange); 136 change = change.setScale(2, BigDecimal.ROUND_UP); 137 138 last = last.add(change); 139 140 if (last.compareTo(max) > 0) 141 { 142 max = last; 143 } 144 145 if (last.compareTo(min) < 0) 146 { 147 min = last; 148 } 149 150 time = new Date (); 151 } 152 153 private static final SimpleDateFormat FORMAT = new SimpleDateFormat ("hh:MM:ss"); 154 } 155
| Popular Tags
|