Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import java.io.*;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Program_5_2
  7. {
  8.     //ITP_120 - 002N; LEE Program_5_2
  9.     public static void main (String[] args)
  10.             throws IOException
  11.     {
  12.        
  13.         String fileName;
  14.         int sum = 0;
  15.         int upperRangeLimit = 100;
  16.         int userRandomNumber;
  17.         Random randomNumbers = new Random(100);
  18.         boolean done = false;
  19.         int x = 1;
  20.         int q;
  21.         while (!done)
  22.         {
  23.             fileName = JOptionPane.showInputDialog("Enter a file name or done to exit: ");
  24.            
  25.             if (!(fileName.equals("done")))
  26.             {
  27.                 fileName = "fileName" + "_" + x++;
  28.                
  29.                 Scanner keyboard = new Scanner(System.in);
  30.                
  31.                 upperRangeLimit = Integer.parseInt(JOptionPane.showInputDialog("Enter the upper range limit:\\nMaximum range is 100"));
  32.                 //upperRangeLimit = keyboard.nextInt();
  33.                 userRandomNumber = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of random numbers you want to generate: "));
  34.                 //userRandomNumber = keyboard.nextInt();
  35.                 q = randomNumbers.nextInt(upperRangeLimit);
  36.                 //Random randomNumbers = new Random(upperRangeLimit);
  37.                 //upperRangeLimit = JOptionPane.showInputDialog("Enter the upper range limit:\n Maximum range is 100");
  38.                 //userRandomNumber = JOptionPane.showInputDialog("Enter the number of random numbers you want to generate: ");
  39.            
  40.                   //creating the file
  41.                 File file = new File(fileName);
  42.            
  43.                   //writing the random number to the new file
  44.                 PrintWriter outputFile = new PrintWriter(fileName);
  45.                     for (int n = 1; n < upperRangeLimit; n++)
  46.                     {
  47.                         sum = sum + q;
  48.                         outputFile.println(sum);
  49.                     }
  50.                
  51.                 outputFile.close();
  52.    
  53.                 Scanner inputFile = new Scanner(file);
  54.                     //while (inputFile.hasNext())
  55.                     //{
  56.                     //  sum = inputFile + inputFile.nextInt();
  57.                     //}
  58.                 System.out.println(sum);
  59.                 inputFile.close();
  60.             }
  61.             else
  62.                 done = true;
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement