Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- public class BabyNames {
- public static void main(String[] args) throws FileNotFoundException {
- System.out.println("** Popularity of a baby name since year 1900 **");
- System.out.println();
- checkingforname();
- }
- public static void checkingforname() throws FileNotFoundException {
- String continueplaying= "";
- do {
- Scanner scanner = new Scanner (System.in);
- System.out.print("name? ");
- String name = scanner.next();
- Scanner input =new Scanner(new File("names.txt"));
- String inputtedname =input.next();
- while(!(inputtedname.equalsIgnoreCase(name)&&input.hasNext())) {
- inputtedname = input.next();
- if(!inputtedname.equals(name)) {
- System.out.print("name not found");
- return;
- }
- }
- PrintStream file = new PrintStream(new File(inputtedname+".txt"));
- file.println("name? " + inputtedname);
- for (int year = 1900; year <= 2000; year += 10) {
- int rank =input.nextInt();
- String ranks = (year + ": " + rank);
- System.out.println(ranks);
- file.println(ranks);
- }
- System.out.print("Would you like to search another name?");
- continueplaying = scanner.next();
- //scanner.close();
- //input.close();
- }while((continueplaying.startsWith("y")) || (continueplaying.startsWith("Y")));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement