fork download
  1.  
  2. public class Country {
  3. private String name;
  4. private String countryCode;
  5. private String isdCode;
  6. public Country(){}
  7. public Country(String name,String countryCode,String isdCode){
  8. this.name=name;
  9. this.countryCode=countryCode;
  10. this.isdCode=isdCode;
  11. }
  12. public String getName(){
  13. return this.name;
  14. }
  15. public String getCountryCode(){
  16. return this.countryCode;
  17. }
  18. public String getIsdCode(){
  19. return this.isdCode;
  20. }
  21. public void setName(String name){
  22. this.name=name;
  23. }
  24. public void setCountryCode(String countryCode){
  25. this.countryCode=countryCode;
  26. }
  27. public void setIsdCode(String isdCode){
  28. this.isdCode=isdCode;
  29. }
  30. public String toString(){
  31. return this.getClass().getName()+"{name="+this.name+", countryCode="+this.countryCode+", isdCode="+this.isdCode+"}";
  32. }
  33. }
  34.  
  35. //
  36. //
  37. //
  38. //
  39. public class CountryBO {
  40. Country createCountry(String data){
  41. String[] data1=data.split(",");
  42. Country country=new Country();
  43. country.setName(data1[0]);
  44. country.setCountryCode(data1[1]);
  45. country.setIsdCode(data1[2]);
  46. return country;
  47. }
  48. void displaySpecificCountryDetails(Country[] countryList, String countryName, int countryCount){
  49. int i=0,set=0;
  50. for(i=0;i<countryCount;i++){
  51. if(countryName.equals(countryList[i].getName())){
  52. set=1;
  53. System.out.println(countryList[i].toString());
  54. break;
  55. }
  56. }
  57. if(set!=1){
  58. System.out.println("Country by name "+countryName+" is not found");
  59. }
  60. }
  61. void displayAllCountryDetails(Country[] countryList, int countryCount){
  62. int i;
  63. for(i=0;i<countryCount;i++){
  64. System.out.println(countryList[i].toString());
  65. }
  66. }
  67. void displayAllCountryNameAndIsdCode(Country[] countryList, int countryCount){
  68. for(int i=0;i<countryCount;i++){
  69. System.out.println("{name="+countryList[i].getName()+", isdCode="+countryList[i].getCountryCode()+"}");
  70. }
  71. }
  72. void updateIsdCodeOfSpecificCountry(Country[] countryList, String countryName, String isdCode, int countryCount){
  73. int i,set=0;
  74. for(i=0;i<countryCount;i++){
  75. if(countryName.equals(countryList[i].getName())){
  76. countryList[i].setIsdCode(isdCode);
  77. break;
  78. }
  79. }
  80. for(i=0;i<countryCount;i++){
  81. System.out.println(countryList[i].toString());
  82. }
  83. }
  84. }
  85. //
  86. //
  87. //
  88. //
  89. import java.util.Scanner;
  90.  
  91. public class Main {
  92.  
  93. public static void main(String[] args) {
  94. // TODO Auto-generated method stub
  95. Scanner s=new Scanner(System.in);
  96. int ch;
  97. String str;
  98. String countryName;
  99. String isdCode;
  100. String reply;
  101. Country country[]=new Country[10];
  102. CountryBO countryBo=new CountryBO();
  103. int i=0;
  104. System.out.println("Menu:\nType any number between 1 and 6");
  105. System.out.println("1)Create a new country\n2)Display details of a specific country\n3)Display the details of all countries\n4)Display the ISD codes of all countries");
  106. System.out.println("5)Update ISD code of a specific country\n6)Exit");
  107. do{
  108. System.out.println("Enter your choice");
  109. ch=s.nextInt();
  110. s.nextLine();
  111. switch(ch){
  112. case 1: System.out.println("Enter Country Details");
  113. str=s.nextLine();
  114. country[i]=countryBo.createCountry(str);
  115. i++;
  116. break;
  117. case 2: System.out.println("Enter the name of the country to be searched");
  118. countryName=s.nextLine();
  119. countryBo.displaySpecificCountryDetails(country, countryName, i);
  120. break;
  121. case 3: System.out.println("Details of all countries");
  122. countryBo.displayAllCountryDetails(country, i);
  123. break;
  124. case 4: System.out.println("ISD codes of all countries");
  125. countryBo.displayAllCountryNameAndIsdCode(country, i);
  126. break;
  127. case 5: System.out.println("Enter the name of the country for which the isd code needs to be updated");
  128. countryName=s.nextLine();
  129. System.out.println("Enter the new ISD code");
  130. isdCode=s.nextLine();
  131. countryBo.updateIsdCodeOfSpecificCountry(country, countryName, isdCode, i);
  132. break;
  133. default: break;
  134. }
  135. System.out.println("Do you want to continue? Type Yes / No");
  136. reply=s.nextLine();
  137. }while(reply.equals("Yes"));
  138. }
  139.  
  140. }
  141. //
  142. //
  143. //
  144. //
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:89: error: class, interface, or enum expected
import java.util.Scanner;
^
1 error
stdout
Standard output is empty