1. package ovn;
  2. import java.util.*;
  3.  
  4. import javagently.LasIn;
  5. public class HeikuraM_RO1_3 {
  6.  
  7.     public static void main(String[] args){
  8.        
  9.         title("Guess the Number!");
  10.         Random generator=new Random();
  11.        
  12.         System.out.println("This program lets you guess a number that the computer" +
  13.                 "randomly chose, from an interval that you choose. It also counts " +
  14.                 "your score. :)");
  15.        
  16.         boolean success=false;
  17.         while(success==false){
  18.             int lowerBound=LasIn.läsHeltal("Enter the lower bound. ");
  19.             int upperBound=LasIn.läsHeltal("Now enter the upper bound. ");
  20.             if(lowerBound>upperBound){
  21.                 System.out.println("The lower bound cannot be higher than the upper"+
  22.                         "bound, silly!");
  23.             }
  24.                 else{
  25.                     success=true;
  26.                 }
  27.         }
  28.                
  29.         int compChoise = generator.nextInt(upperBound - lowerBound + 1 ) + lowerBound;
  30.        
  31.         int guess=LasIn.läsHeltal("Do you think you're lucky? Take a guess!");
  32.        
  33.         if(guess==compChoise){
  34.             System.out.println("You are correct! You got it right in ");
  35.             }
  36.             else if(guess<compChoise){
  37.                 System.out.println("Higher...");
  38.             }
  39.                 else if(guess>compChoise){
  40.                     System.out.println("Lower...");
  41.                 }
  42.                     else {
  43.                         System.out.println("");
  44.                     }
  45.         }
  46.        
  47.     }
  48.        
  49.    
  50.     public static void title(String title){
  51.         int i=title.length();
  52.        
  53.         // Prints the title.
  54.         while(i>0){
  55.         System.out.print("*");
  56.         i--;
  57.         }
  58.         System.out.println("\n"+title);
  59.        
  60.         i=title.length();
  61.         while(i>0){
  62.             System.out.print("*");
  63.             i--;
  64.         }
  65.         System.out.println();
  66.     }
  67.    
  68. }