Applying the techniques of decomposition (refer to pp 425-426), how would you br
ID: 3825757 • Letter: A
Question
Applying the techniques of decomposition (refer to pp 425-426), how would you break this program/problem into smaller pieces. Design an address book program to keep track of the names, addresses, phone numbers, and birthdays of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries. This program should include the ability to load address book data from a file, sort by last name, search by last name, print all information for a given person, print the name of people whose birthdays are in a given month, and print the names of all people between two last names.Explanation / Answer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Addressbook;
import java.io.BufferedReader;
import java.io.FileReader;
import net.sf.json.JSONObject;
/**
*
* @author sravani.k
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Address add = new Address();
// TODO code application logic here
add.readFile("E:/exp/chegg/Practice/Address.txt");
add.search("sravani");
}
static class Address {
JSONObject records = new JSONObject();
void search(String name) {
if (records.containsKey(name)) {
System.out.println(records.get(name));
} else {
System.out.println("Record Not found");
}
}
private JSONObject readFile(String filename) {
String data[];
int Cnt =0;
try {
// records = new JSONObject();
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
while ((line = reader.readLine()) != null) {
if(Cnt >500)
{
System.out.println("Unable read More data");
break;
}
if(line != null)
{
Cnt ++;
System.out.println("line is::"+line );
data = line.split(",");
System.out.println("size"+data.length);
records.put(data[0], line);
}
}
reader.close();
System.out.println("all records" + records);
return records;
} catch (Exception e) {
System.err.format("Exception occurred trying to read '%s'.", filename);
e.printStackTrace();
return null;
}
}
}
}
Example file
-----------------------------------
sravani,H.no 2134:BHEL,99999999,13081992
sreelatha,H.no 2124:BHEL,1111111,13081992
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.