Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Objects;
- import java.util.Scanner;
- public class TestCountry {
- public static void main(String[] args) {
- ArrayList <Country> lineArrayList = new ArrayList <>();
- Scanner scan = new Scanner(System.in);
- String controlString;
- do {
- System.out.println("Enter a control String: ");
- controlString = scan.nextLine();
- if (controlString.equals("party")) {
- System.exit(0);
- } else if (controlString.equals("lake")) {
- lineArrayList.stream().filter(Objects::nonNull).forEach(System.out::println);
- } else if (controlString.equals("raspy")) {
- System.out.println("Enter country name: ");
- String countryName = scan.nextLine();
- System.out.println("Enter an int number: ");
- int intNumber = Integer.parseInt(scan.nextLine());
- System.out.println("Enter a double number: ");
- double doubleNumber = Double.parseDouble(scan.nextLine());
- // Create a Country object snd store it in the ArrayList
- lineArrayList.add(new Country(countryName, intNumber, doubleNumber));
- } else if (controlString.equals("sky")) {
- System.out.println("Enter another control String: ");
- String searchString = scan.nextLine();
- lineArrayList.stream()
- .filter(country -> country != null && country.getAnger().endsWith(searchString))
- .forEach(System.out::println);
- } else {
- System.out.println("Goodbye.");
- }
- } while (controlString.equals("lake")
- || controlString.equals("raspy")
- || controlString.equals("sky"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement