MrDoyle

Arrays) Parallel Arrays

Jan 25th, 2021
548
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Main
  6. {
  7.     public static void main( String[] args ) {
  8.         String[] surnames = { "Mitchell", "Ortiz", "Luu", "Zimmerman", "Brooks" };
  9.  
  10.         Double[] grades = new Double [5];
  11.         Random rand = new Random();
  12.  
  13.         for (int i = 0; i < grades.length; i++) {
  14.             Double min = 0.0;
  15.             Double max = 100.0;
  16.             double x = (Math.random() * ((max - min) + 1)) + min;
  17.             double xrounded = Math.round(x * 100.0) / 100.0;
  18.             grades[i] = xrounded;
  19.         }
  20.  
  21.         Integer[] studentID = { 12345, 23456, 34567, 45678, 56789 };
  22.  
  23.         System.out.print("Values:\n\t");
  24.  
  25.         for (int i = 0; i < grades.length; i++) {
  26.             System.out.print(surnames[i] + " " + grades[i] + " " + studentID[i] + "\n\t");
  27.         }
  28.  
  29.  
  30.  
  31.         int found = 0;
  32.         while (found == 0) {
  33.             System.out.println();
  34.             Scanner keyboard = new Scanner(System.in);
  35.             System.out.print("ID number to find: ");
  36.             int idFind = keyboard.nextInt();
  37.  
  38.             for (int i = 0; i < studentID.length; i++) {
  39.                 if (studentID[i] == idFind) {
  40.                     System.out.println("\nFound in slot " + i);
  41.                     System.out.println("\tName : " + surnames[i]);
  42.                     System.out.println("\tAverage: " + grades[i]);
  43.                     System.out.println("\tID: " + studentID[i]);
  44.                     found = found + 1;
  45.                 }
  46.             }
  47.  
  48.             System.out.println();
  49.  
  50.             if (found == 0) {
  51.                 System.out.println("Student ID number not found.");
  52.  
  53.             }
  54.         }
  55.     }
  56. }
RAW Paste Data