Advertisement
binibiningtinamoran

TestCountry.java

May 6th, 2020
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Objects;
  3. import java.util.Scanner;
  4.  
  5. public class TestCountry {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         ArrayList <Country> lineArrayList = new ArrayList <>();
  10.         Scanner scan = new Scanner(System.in);
  11.  
  12.         String controlString;
  13.         do {
  14.             System.out.println("Enter a control String: ");
  15.             controlString = scan.nextLine();
  16.  
  17.             if (controlString.equals("party")) {
  18.                 System.exit(0);
  19.             } else if (controlString.equals("lake")) {
  20.                 lineArrayList.stream().filter(Objects::nonNull).forEach(System.out::println);
  21.             } else if (controlString.equals("raspy")) {
  22.                 System.out.println("Enter country name: ");
  23.                 String countryName = scan.nextLine();
  24.  
  25.                 System.out.println("Enter an int number: ");
  26.                 int intNumber = Integer.parseInt(scan.nextLine());
  27.  
  28.                 System.out.println("Enter a double number: ");
  29.                 double doubleNumber = Double.parseDouble(scan.nextLine());
  30.  
  31.                 // Create a Country object snd store it in the ArrayList
  32.                 lineArrayList.add(new Country(countryName, intNumber, doubleNumber));
  33.  
  34.             } else if (controlString.equals("sky")) {
  35.  
  36.                 System.out.println("Enter another control String: ");
  37.                 String searchString = scan.nextLine();
  38.  
  39.                 lineArrayList.stream()
  40.                         .filter(country -> country != null && country.getAnger().endsWith(searchString))
  41.                         .forEach(System.out::println);
  42.             } else {
  43.                 System.out.println("Goodbye.");
  44.             }
  45.         } while (controlString.equals("lake")
  46.                 || controlString.equals("raspy")
  47.                 || controlString.equals("sky"));
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement