Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package project5;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.Scanner;
  7.  
  8.  
  9.  
  10.  
  11. public class Project5 {
  12.  
  13.  
  14. public static void main(String[] args) throws FileNotFoundException, IOException {
  15.  
  16. int[] list = new int[15];
  17. int[] f = new int[5];
  18. double target;
  19.  
  20. loadGrades(list);
  21. printGrades(list);
  22. }
  23.  
  24.  
  25.  
  26.  
  27. public static void loadGrades(int list[]){
  28.     Scanner text = null;
  29.     int i = 0;
  30.    
  31.  try {
  32.             text = new Scanner(new FileReader("proj5Data.txt"));
  33.         } catch (FileNotFoundException ex) {
  34.             System.out.println("Error: File proj5Data.txt not found");
  35.             System.exit(1);
  36.         }
  37.        
  38.         //reading from the text file to the list[]
  39.         while (text.hasNext()) {
  40.             list[i] = text.nextInt();
  41.             i++;
  42.         }
  43.         text.close();
  44.        
  45. }
  46. public static void printGrades(int list[])  {
  47.    
  48.    
  49.    
  50. System.out.printf("%3s", list[ 0 ] + "  ");
  51. System.out.printf("%3s", list[ 1 ] + "  ");
  52. System.out.printf("%3s", list[ 2 ] + "  ");
  53. System.out.printf("%3s", list[ 3 ] + "  ");
  54. System.out.printf("%3s", list[ 4 ] + "  ");
  55. System.out.println("");
  56. System.out.printf("%3s", list[ 5 ] + "  ");
  57. System.out.printf("%3s", list[ 6 ] + "  ");
  58. System.out.printf("%3s", list[ 7 ] + "  ");
  59. System.out.printf("%3s", list[ 8 ] + "  ");
  60. System.out.printf("%3s", list[ 9 ] + "  ");
  61. System.out.println("");
  62. System.out.printf("%3s", list[ 10 ] + "  ");
  63. System.out.printf("%3s", list[ 11 ] + "  ");
  64. System.out.printf("%3s", list[ 12 ] + "  ");
  65. System.out.printf("%3s", list[ 13 ] + "  ");
  66. System.out.printf("%3s", list[ 14 ] + "  ");
  67.  
  68.    
  69.    
  70.    
  71. }
  72.   public static int calcMax(int list[]){
  73.    int max = 0;
  74.    for(int n:list){
  75.        if(max < n){
  76.           max = n;
  77.        } else if(n > max){
  78.            max = n;
  79.        }
  80.        System.out.println("The maximum grade is" + max);
  81.    
  82.    
  83. }
  84.    
  85.  
  86.      return max;  
  87.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement