Skip to content

Instantly share code, notes, and snippets.

@chamellion
Created October 23, 2022 20:57
Show Gist options
  • Select an option

  • Save chamellion/df976ffc0fefc6eabfb40b522dcc2126 to your computer and use it in GitHub Desktop.

Select an option

Save chamellion/df976ffc0fefc6eabfb40b522dcc2126 to your computer and use it in GitHub Desktop.

Revisions

  1. chamellion created this gist Oct 23, 2022.
    64 changes: 64 additions & 0 deletions LabThreeQ3.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    import java.util.Locale;
    import java.util.Scanner;

    public class LabThreeQ3 {

    public static void main(String[] args) {
    String countryOne = "Albania";
    String countryTwo = "Moldova";
    String countryThree = "Slovakia";
    String countryFour = " North Macedonia";
    String countryFive = " Liechtenstein";

    String capitalOne = "Tirana";
    String capitalTwo = "Chişinău";
    String capitalThree = "Bratislava";
    String capitalFour = "Skopje";
    String capitalFive = "Vaduz";

    String countryOnePopulation = "2,854,710";
    String countryTwoPopulation = "3,061,506";
    String countryThreePopulation = "5,447,622";
    String countryFourPopulation = "2,103,330";
    String countryFivePopulation = "39,039";

    System.out.println("Welcome to CountryAndCapital: ");
    System.out.println("Countries available are ");
    System.out.println("Albania Moldova Slovakia North Macedonia and Liechtenstein.");
    System.out.println("Please enter one of the five countries to continue....: ");

    Scanner scanner = new Scanner(System.in);
    if (scanner.hasNextLine()){
    String countryChosen = scanner.nextLine().toLowerCase(Locale.ROOT);
    switch (countryChosen){
    case "albania": {
    System.out.printf("The capital of %1s is %2s and it has a population of %3s people", countryOne, capitalOne, countryOnePopulation);
    break;
    }
    case "moldova": {
    System.out.printf("The capital of %1s is %2s and it has a population of %3s people", countryTwo, capitalTwo, countryTwoPopulation);
    break;
    }
    case "slovakia": {
    System.out.printf("The capital of %1s is %2s and it has a population of %3s people", countryThree, capitalThree, countryThreePopulation);
    break;
    }
    case "north macedonia": {
    System.out.printf("The capital of %1s is %2s and it has a population of %3s people", countryFour, capitalFour, countryFourPopulation);
    break;
    }
    case "liechtenstein": {
    System.out.printf("The capital of %1s is %2s and it has a population of %3s people", countryFive, capitalFive, countryFivePopulation);
    break;
    }
    default:{
    System.out.println("You should enter one of the printed five countries above");
    System.out.println("N.B: For North Macedonia, please leave a space between the two words...");
    }
    }
    }else {
    System.out.println("Invalid input. Try again");
    }

    }
    }