Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. // the original code for class Thermometer
  2.  
  3.     public int measure() {
  4.         if (onoff == false) {
  5.             try {
  6.                 throw IllegalStateException(" ");
  7.             } catch (Exception ex) {
  8.                 Logger.getLogger(Thermometer.class.getName()).log(Level.SEVERE, null, ex);
  9.             }
  10.         } else {
  11.             Random randoms = new Random();
  12.             random = randoms.nextInt(61) - 30;
  13.  
  14.             return random;
  15.         }
  16.         return random;
  17.     }
  18.  
  19. // my suggestion
  20.  
  21.     public int measure() {
  22.         if (onoff) {
  23.             return (int) (-30 + Math.random() * 60);
  24.         }
  25.         throw new IllegalStateException();
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement