Advertisement
Kendred

Curve a Quiz

Mar 14th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Scanner;
  3.  
  4. public class Program {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. /*
  9. * Kendred Thompson
  10. * 4th Period
  11. * CS 2
  12. * Curve a Quiz
  13. */
  14.  
  15. //Variables
  16. File f;
  17. Scanner sc;
  18. double [] scores;
  19. int numScores;
  20. double pointsPossible;
  21.  
  22. //Open the scores.txt file
  23. f = new File("scores.txt");
  24. try {
  25. sc = new Scanner(f);
  26. }
  27. catch(Exception e) {
  28. System.out.println("Error opening file.");
  29. System.out.println("Reading from Keyboard");
  30. sc = new Scanner(System.in);
  31. }
  32.  
  33. //Find out how many scores are in the file
  34. numScores = sc.nextInt();
  35.  
  36. //Find out the highest score possible
  37. pointsPossible = sc.nextDouble();
  38.  
  39. //Read the scores into an array adding one point and displays them onto the screen
  40. scores = new double[numScores];
  41. int i = 0;
  42. while(i < numScores) {
  43. scores[i] = sc.nextDouble() + 1;
  44. System.out.println(scores[i]);
  45. i = i + 1;
  46. }
  47.  
  48. sc.close(); //Close the file
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement