Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public class TestContacts {
  2. public static void main(String [] args) {
  3. Contact c = new Contact("Akter",
  4. "428",
  5. 19,
  6. "01600000000",
  7. 'F');
  8. c.detectMobileOperator();
  9. }
  10. }
  11.  
  12. class Contact {
  13. private String personName;
  14. private String personId;
  15. private int age;
  16. private String mobileNumber;
  17. private char gender; // M or F;
  18.  
  19. public Contact() {
  20. }
  21.  
  22. public Contact(String personName,
  23. String personId,
  24. int age,
  25. String mobileNumber,
  26. char gender) {
  27. this.personName = personName;
  28. this.personId = personId;
  29. this.age = age;
  30. this.mobileNumber = mobileNumber;
  31. this.gender = gender;
  32. }
  33.  
  34. public void showPersonInfo() {
  35. System.out.println("Name: " + personName);
  36. System.out.println("ID: " + personId);
  37. System.out.println("Age: " + age);
  38. System.out.println("Mobile: "+ mobileNumber);
  39. System.out.println("Gender: "+ gender);
  40. }
  41.  
  42. void detectMobileOperator() {
  43. char prefix = mobileNumber.charAt(2);
  44.  
  45. switch(prefix) {
  46. case '5':
  47. System.out.println("Teletalk");
  48. break;
  49. case '6':
  50. System.out.println("Airtel");
  51. break;
  52. case '7':
  53. System.out.println("Grameenphone");
  54. break;
  55. case '8':
  56. System.out.println("Robi");
  57. break;
  58. case '9':
  59. System.out.println("Banglalink");
  60. break;
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement