Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class BabyNames {
  5.  
  6. public static void main(String[] args) throws FileNotFoundException {
  7. System.out.println("** Popularity of a baby name since year 1900 **");
  8. System.out.println();
  9. checkingforname();
  10. }
  11.  
  12.  
  13. public static void checkingforname() throws FileNotFoundException {
  14. String continueplaying= "";
  15. do {
  16. Scanner scanner = new Scanner (System.in);
  17. System.out.print("name? ");
  18. String name = scanner.next();
  19. Scanner input =new Scanner(new File("names.txt"));
  20. String inputtedname =input.next();
  21. while(!(inputtedname.equalsIgnoreCase(name)&&input.hasNext())) {
  22. inputtedname = input.next();
  23. if(!inputtedname.equals(name)) {
  24. System.out.print("name not found");
  25. return;
  26. }
  27.  
  28. }
  29.  
  30.  
  31. PrintStream file = new PrintStream(new File(inputtedname+".txt"));
  32. file.println("name? " + inputtedname);
  33. for (int year = 1900; year <= 2000; year += 10) {
  34. int rank =input.nextInt();
  35. String ranks = (year + ": " + rank);
  36. System.out.println(ranks);
  37. file.println(ranks);
  38. }
  39. System.out.print("Would you like to search another name?");
  40. continueplaying = scanner.next();
  41. //scanner.close();
  42. //input.close();
  43.  
  44. }while((continueplaying.startsWith("y")) || (continueplaying.startsWith("Y")));
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement