This repository was archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobilePhone.java
More file actions
37 lines (29 loc) · 1.3 KB
/
MobilePhone.java
File metadata and controls
37 lines (29 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.ArrayList;
public class MobilePhone{
private String myNumber;
private ArrayList<Contact> myContacts;
//public Constructor
public MobilePhone(String myNumber){ //just intialiszing the number and ArrayList
this.myNumber = myNumber;
this.myContacts = new ArrayList<Contact>();
}
public boolean addNewContact(Contact Contact){
if(findContact(contact.getName()) >= 0){ //here 0 or greater than means already h //coz string returns -1 if not found
System.out.println("Contact is already on file"); //Usually we dont write sop here we only status ie true or false
return false;
}
myContacts.add(contact); //no need of else by default it is else
return true;
}
public boolean updateContact(Contact oldcontact,Contact newContact){
int foundPosition = findContact(oldcontact); //first check oldcontact eg Jatin is der or not
if(foundPosition < 0){ //ie -1 means not found
System.out.println(oldcontact.getName()+"was not found");
return false;
}
this.myContacts.set(foundPosition,newContact); //set Method replaces the element at the specified position in the list with specified element
System.out.println(oldContact.getName()+",was replaced with"+newContact.getName());
return true;
}
public boolean removeContact()
}