java通讯录代码分析,java通信编程
编写一个JAVA程序实现个人通讯录管理
这个太简单了,你问的是程序编制要点,那么我就告诉你:
创新互联于2013年开始,先为海安等服务建站,海安等地企业,进行企业商务咨询服务。为海安企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
1.分析程序
2.制定计划
3.编写代码
4.测试
关于你说的用java编写个人通讯录管理程序,这个程序代码
这本书有原代码,你自己可以看下
java 电子通讯录的载入和保存代码
思路如下:
确定电子通讯录的文字格式,比如纯文本文件,每条通讯记录一行,每项内容之间使用tab键间隔
使用最基础的IO读写,操作此文件。
载入时从文件一行行读入,使用split拆分各项内容,存入一个对应的通讯录对象中,所有的通讯录对象保存在一个List中;
保存时,以覆盖的方式写入文件,以相同的格式写入即可。
java通讯录全部代码!
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class AddList {
private String filePath = "";
private String bakPath = "";
private String content = "";
Scanner sc = new Scanner(System.in);
public String readFile(){
content = "";
if (isNull(filePath)) {
System.out.println("文件存储路径:");
filePath = sc.nextLine();
}
File file = new File(filePath);
FileReader fr = null;
try {
if (file.exists()) {
fr = new FileReader(file);
char[] chars = new char[1024];
int n = 0;
while((n = fr.read(chars)) != -1){
String string = new String(chars, 0, n);
content = content + string;
}
} else {
System.out.println("文件不存在");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return content;
}
public void writeFile(String path){
File file = new File(path);
FileOutputStream fos = null;
mkDirs(path);
try {
fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter pw = new PrintWriter(bos, true);
pw.print(content);
pw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void writeFile(){
if (isNull(filePath)) {
System.out.println("文件存储路径:");
filePath = sc.nextLine();
}
File file = new File(filePath);
FileOutputStream fos = null;
mkDirs(filePath);
try {
fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter pw = new PrintWriter(bos, true);
pw.print(content);
pw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void mkDirs(String filepath){
if (filepath.indexOf("\\") != -1) {
filepath = filepath.replaceAll("\\", "/");
}
int n = filepath.indexOf("//");
String path = filepath.substring(0, n) + "//";
filepath = filepath.substring(filepath.indexOf("//") + 1, filepath.length());
String[] files = filepath.split("/");
for (int i = 0; i files.length - 1; i++) {
path = path + files[i];
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
}
}
public void addImfor(){
System.out.println("--------增加记录---------");
String name = "";
String tel = "";
String email = "";
content = readFile();
while(true){
System.out.println("姓名:");
name = sc.next();
System.out.println("电话:");
tel = sc.next();
System.out.println("Email:");
email = sc.next();
content = content + name + "" + tel + "" + email +"==";
System.out.println("0、Exit 1、继续");
int i = sc.nextInt();
if (i == 0) {
break;
}
}
writeFile();
}
public void deleteImfor(){
System.out.println("---------删除记录---------");
String name = "";
String[] imfors = null;
content = readFile();
while(true){
System.out.println("你要删除的姓名是:");
name = sc.next();
if (content.indexOf(name) != -1) {
imfors = content.split("==");
for (int i = 0; i imfors.length; i++) {
if (imfors[i].indexOf(name) != -1) {
imfors[i] = "";
}
}
实现一个通讯录程序,命令模式下的JAVA程序, 该程序具备添加,删除,合查看通讯录信息的功能~
你就怎么那么小气呢!给个几十分也不亏你!
算了,刚写的就便宜你了!
import java.util.Scanner;
public class Shopping {
System.out.println("\t\t\t\t1.添加联系人信息\n");
System.out.print("\t\t\t\t2删除联系人信息\n");
System.out.println("\t\t\t\t3查看联系人信息\n");
System.out.println("\t\t\t\t4.退出");
System.out.println("请选择,输入数字或按“n”返回上一级菜单:");
System.out.println("请选择,输入数字或按“n”返回上一级菜单:");
num = scanner.nextLine();
if (num.equals("n"))
isR = true;
else if(num.equals("1")){
System.out.println("添加联系人信息");
System.out.println("输入联系人的姓名: ");
num = scanner.nextLine();
String birthDayNum = num;
System.out.println("输入联系人的电话: ");
num = scanner.nextLine();
String birthDayNum = num;
System.out.print("是否继续添加(y/e):");
String numJixu = scanner.nextLine();
if (numJixu.equals("y"))
isEnd2 = true;
else {
isEnd2 = false;
isEnd = true;
}
}
else if(num.equals("3")){
System.out.println("查看联系人");
System.out.print("请输入联系人姓名:");
String snum = scanner.nextLine();
int numberNum = Integer.parseInt(snum);
}
}
就给你发这么多吧!还有一点点自己琢磨吧!我也没时间整理了!!
Java问题,求解答,我太菜了,不会做
题目完整代码如下:
People类:
public class People {
// 姓名
private String name;
// 电话号码
private String phoneNumber;
// 地址
private String address;
// 邮箱
private String mailBox;
public People(String name, String phoneNumber, String address, String mailBox) {
super();
this.name = name;
this.phoneNumber = phoneNumber;
this.address = address;
this.mailBox = mailBox;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getMailBox() {
return mailBox;
}
public void setMailBox(String mailBox) {
this.mailBox = mailBox;
}
@Override
public String toString() {
return "People [name=" + name + ", phoneNumber=" + phoneNumber + ", address=" + address + ", mailBox=" + mailBox
+ "]";
}
}
通讯录类:
/**
* 通讯录
*
* @author qd
*
*/
public class AddressBooks {
// People类型数组,长度为10(可以自己定义长度)
People[] peoples = new People[2];
// 添加联系人
public void addPeople() {
peoples[0] = new People("张三", "1234567", "地址1", "1234567@qq.com");
peoples[1] = new People("lisi", "12345", "地址2", "12345@qq.com");
}
// 查找联系人
public void findPeople() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查找的联系人");
String name = scanner.nextLine();
for (int i = 0; i peoples.length; i++) {
if (name.equals(peoples[i].getName())) {
if (name.equals(peoples[i].getName())) {
System.out.println(peoples[i].toString());
return;
}
} else {
continue;
}
}
System.out.println("不好意思,没有该联系人");
}
public static void main(String[] args) {
AddressBooks addressBooks = new AddressBooks();
addressBooks.addPeople();
addressBooks.findPeople();
}
}
运行结果演示:
本文题目:java通讯录代码分析,java通信编程
本文路径:http://ybzwz.com/article/hchded.html