Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestContacts {
- public static void main(String [] args) {
- Contact c = new Contact("Akter",
- "428",
- 19,
- "01600000000",
- 'F');
- c.detectMobileOperator();
- }
- }
- class Contact {
- private String personName;
- private String personId;
- private int age;
- private String mobileNumber;
- private char gender; // M or F;
- public Contact() {
- }
- public Contact(String personName,
- String personId,
- int age,
- String mobileNumber,
- char gender) {
- this.personName = personName;
- this.personId = personId;
- this.age = age;
- this.mobileNumber = mobileNumber;
- this.gender = gender;
- }
- public void showPersonInfo() {
- System.out.println("Name: " + personName);
- System.out.println("ID: " + personId);
- System.out.println("Age: " + age);
- System.out.println("Mobile: "+ mobileNumber);
- System.out.println("Gender: "+ gender);
- }
- void detectMobileOperator() {
- char prefix = mobileNumber.charAt(2);
- switch(prefix) {
- case '5':
- System.out.println("Teletalk");
- break;
- case '6':
- System.out.println("Airtel");
- break;
- case '7':
- System.out.println("Grameenphone");
- break;
- case '8':
- System.out.println("Robi");
- break;
- case '9':
- System.out.println("Banglalink");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement