Professional Documents
Culture Documents
Buy Now To Create PDF Without Trial Watermark!!: Address Book - V. 3.0
Buy Now To Create PDF Without Trial Watermark!!: Address Book - V. 3.0
Buy Now To Create PDF Without Trial Watermark!!: Address Book - V. 3.0
You have already implemented most of it. The remaining, we try to implement today.
Step 1:
//PersonInfo.java class
import javax.swing.*;
class PersonInfo
{
protected String name;
protected String address;
protected String phoneNum;
protected String status;
{
return name;
}
public String getAddress()
{
return address;
}
public String getPhoneNum()
{
return phoneNum;
}
________________________________________________________________________________
Any other changes, we have made, but are not bold, please specify here: ________________________
________________________________________________________________________________
________________________________________________________________________________
Step2:
We do not need to make any changes in the following two classes:
//Colleague.java class
class Colleague extends PersonInfo
{
private String organization;
private String designation;
}
public void print()
{
super.print();
JOptionPane.showMessageDialog(null,"Organization: " + organization + "\nDesignation: "
+designation);
}
public String getDesignation() {
return designation;
2
}
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
public void setDesignation(String designation){
this.designation = designation;
}
}
Any changes in the above class: _________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
//Favorites.java class
import javax.swing.*;
class Favorites extends PersonInfo
{
private String dateOfBrith;
__________________________________________________________________________________
__________________________________________________________________________________
Step 3:
We also need to make some changes in AddessBook class. Modified class is given below:
//AddressBook.java class
import java.io.*;
import javax.swing.*;
import java.util.*;
class AddressBook {
ArrayList persons;
public AddressBook() {
persons = new ArrayList();
//getting all data from file to arraylist
this.loadPersons();
}
}//end if
}//end for
}//end method
try {
PersonInfo p;
String line;
try {
FileReader fr = new FileReader("persons.txt");
BufferedReader br = new BufferedReader(fr);
tokens = line.split(",");
status = tokens[0];
name = tokens[1];
add = tokens[2];
ph = tokens[3];
if (status.equals("normal")) {
p = new PersonInfo(name, add, ph, status);
} else if (status.equals("favorite")) {
String date = tokens[4];
p = new Favorites(name, add, ph, date, status);
} else if (status.equals("colleague")) {
String org = tokens[4];
String desg = tokens[5];
p = new Colleague(name, add, ph, org, desg, status);
}
//add all types of perosns to list
persons.add(p);
//reading next line
line = br.readLine();
}//end while
________________________________________________________________________________
Any other changes, we have made, but are not bold, please specify here: ________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Step 4:
//Test.java class
import javax.swing.*;
class Test
{
public static void main (String args[])
{
AddressBook ab = new AddressBook();
while (true)
{
input = JOptionPane.showInputDialog("Enter 1 to Add Person \n Enter 2 to
Search Person \n Enter 3 to Delete Person \n Enter 4 to Exit");
ch = Integer.parseInt(input);
switch (ch)
{
case 1:
inputPerson = JOptionPane.showInputDialog("Enter 1 to Add
Normal Person \n Enter 2 to Favorite Person \n Enter 3 to Add Collegue \n Enter 4 to Back");
chPerson = Integer.parseInt(inputPerson);
switch (chPerson)
{
case 1:
ab.addPerson();
break;
case 2:
ab.addFavorites();
break;
case 3:
ab.addColleague();
break;
case 4:
break;
default:
JOptionPane.showMessageDialog(null,"Enter Option 1 to 4");
}
break;
case 2:
s =JOptionPane.showInputDialog("Enter Name to search");
ab.searchPerson(s);
break;
case 3:
s =JOptionPane.showInputDialog("Enter name to delete");
ab.deletePerson(s);
break;
case 4:
ab.savePersons();
System.exit(0);
default:
JOptionPane.showMessageDialog(null,"Enter Option 1 to 4");
}//end switch
}//end while
}//end main
}//end class
Changes in the above class are bold. Reason for doing these changes: __________________________
________________________________________________________________________________
________________________________________________________________________________
Any other changes, we have made, but are not bold, please specify here: ________________________
________________________________________________________________________________
________________________________________________________________________________