Guest User

Untitled

a guest
Feb 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4. public class LabAssignment4 {
  5.  
  6.  
  7. public static void main(String[] args) throws IOException {
  8. File animalsFile = new File("animals.txt");
  9. Scanner animalsScan = new Scanner(animalsFile);
  10. File soundsFile = new File("sounds.txt");
  11. Scanner soundsScan = new Scanner(soundsFile);
  12.  
  13.  
  14. int animalsSize = animalSize (animalsScan);
  15. String [] animalsArray = new String [animalsSize];
  16.  
  17. int soundsSize = soundSize (soundsScan);
  18. String[] soundsArray = new String [soundsSize];
  19.  
  20. fillAnimalsAndSoundsArray(soundsScan,animalsScan,animalsArray,soundsArray);
  21. printAnimalsAndSoundsArray(animalsArray,soundsArray);
  22.  
  23.  
  24. } // end main
  25.  
  26. public static int animalSize(Scanner animalsScan){
  27. int animals = animalsScan.nextInt();
  28. return animals;
  29. }
  30.  
  31. public static int soundSize(Scanner soundsScan){
  32. int sounds = soundsScan.nextInt();
  33. return sounds;
  34. }
  35.  
  36. public static void fillAnimalsAndSoundsArray(Scanner soundsScan, Scanner animalsScan, String [] animalsArray, String [] soundsArray){
  37. int animalsIndex=0;
  38. int soundsIndex=0;
  39.  
  40. while(animalsScan.hasNext()){
  41. animalsArray[animalsIndex]=animalsScan.nextLine();
  42. animalsIndex++;
  43. }
  44.  
  45.  
  46. while(soundsScan.hasNext()){
  47. soundsArray[soundsIndex]=soundsScan.nextLine();
  48. soundsIndex++;
  49.  
  50. }
  51. }
  52.  
  53. public static void printAnimalsAndSoundsArray(String[] animalsArray, String[] soundsArray){
  54. for(int i =0;i<animalsArray.length;i++){
  55. System.out.println(animalsArray[i]);
  56. }
  57. for(int i = 0;i<soundsArray.length;i++){
  58. System.out.println(soundsArray[i]);
  59. }
  60. }
  61. } // end class
Add Comment
Please, Sign In to add comment