Ask Question
8 April, 01:00

Create an application (that uses the SortedABList) that allows a user to enter a list of countries that he or she has visited and then displays the list in alphabetical order, plus a count of how many countries are on the list. If the user mistakenly enters the same country more than once, the program should inform the user of their error and refrain from inserting the country into the list a second time.

+3
Answers (1)
  1. 8 April, 01:38
    0
    import java. util.*;

    public class Country

    {

    public static void main (String args[])

    {

    char ch, temp;

    int flag = 0;

    String country;

    ArrayList countries = new ArrayList ();

    Scanner sc = new Scanner (System. in);

    do

    {

    System. out. println ("enter the country you have visited:/t");

    country = sc. next ();

    for (int i=0; i
    {

    if (countries. get (i). equals (country))

    {

    System. out. println ("you have already entered the country");

    flag = 1;

    break;

    }

    }

    if (flag = = 0)

    {

    countries. add (country);

    flag = 0;

    }

    System. out. println ("want to add another country (y/n) : /t");

    ch = sc. next (). charAt (0);

    }while (ch!='n');

    Collections. sort (countries);

    System. out. println ("Countries you have visited:/t"+countries);

    System. out. println ("Total number of contries visited:"+countries. size ());

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create an application (that uses the SortedABList) that allows a user to enter a list of countries that he or she has visited and then ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers