==================================
創(chuàng)新互聯(lián)建站是專業(yè)的天橋網(wǎng)站建設(shè)公司,天橋接單;提供成都網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行天橋網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class PhoneBook {
// 代表有多少條記錄
private int size = 0;
// 用來記錄信息的數(shù)組
private Phone[] phones = new Phone[100];
private String filename = "phonebook.txt";
public PhoneBook() {
try {
read();
} catch (IOException e) {
}
}
private void read() throws IOException {
File f = new File(filename);
if (!f.exists()) {
return;
}
BufferedReader br = new BufferedReader(new FileReader(filename));
String line = null;
while ((line = br.readLine()) != null) {
if (line.trim().length() 0) {
Phone phone = new Phone(line);
addPhone(phone);
}
}
br.close();
}
public void store() throws IOException {
File f = new File(filename);
BufferedWriter bw = new BufferedWriter(new FileWriter(filename));
for (Phone phone : phones) {
if (phone == null) {
continue;
}
String str = phone.name + "::" + phone.number + "::" + phone.notes;
bw.write(str + "\r\n");
}
bw.close();
}
public void addPhone(Phone phone) {
phones[size++] = phone;
}
public Phone getPhone(String name) {
for (Phone phone : phones) {
if (phone == null) {
continue;
}
if (phone.name.equalsIgnoreCase(name)) {
return phone;
}
}
return null;
}
public Phone[] getPhones() {
return phones;
}
}
class Phone {
String name, number, notes;
public Phone() {
}
public Phone(String line) {
String[] strs = line.split("::");
name = strs[0];
number = strs[1];
notes = strs[2];
}
public String toString() {
return String.format("-- %s\r\n-- %s\r\n-- %s", name, number, notes);
}
}
=================================================
import java.io.IOException;
import java.util.Scanner;
public class MainClass {
private static PhoneBook book = new PhoneBook();
public static void main(String[] args) {
getCommand();
}
public static void getCommand() {
String cmd = getString("Command: ");
if (cmd.startsWith("e ")) {
add(cmd.substring(cmd.indexOf(' ') + 1));
try {
book.store();// 添加一個(gè)就記錄一次文件
} catch (IOException e) {
e.printStackTrace();
}
} else if (cmd.startsWith("f ")) {
find(cmd.substring(cmd.indexOf(' ') + 1));
} else if (cmd.equals("l")) {
list();
} else if (cmd.startsWith("q")) {
quit();
} else {
System.out.println("unknown command!");
}
getCommand();
}
public static void add(String name) {
Phone phone = new Phone();
phone.name = convert(name);// 名字轉(zhuǎn)換
phone.number = getString("Enter number: ");
phone.notes = getString("Enter notes: ");
book.addPhone(phone);
}
public static void find(String name) {
Phone phone = book.getPhone(name);
if (phone != null) {
System.out.println(phone);
} else {
System.out.println("** No entry with code " + name);
}
}
public static void list() {
for (Phone phone : book.getPhones()) {
if (phone != null) {
System.out.println(phone);
}
}
}
public static void quit() {
try {
book.store();
} catch (IOException e) {
}
System.exit(0);
}
public static String getString(String tip) {
System.out.print(tip);
Scanner sc = new Scanner(System.in);
return sc.nextLine();
}
private static String convert(String name) {
if (name != null name.length() 0) {
return name.substring(0, 1).toUpperCase()
+ name.substring(1).toLowerCase();
}
return null;
}
}
package src;
public class TelBook {
// 姓名
String name;
// 家庭電話
Integer homePhone;
// 個(gè)人移動(dòng)電話
Integer personalMobilePhone;
// 辦公電話
Integer officePhone;
// 家庭地址
String homeAddress;
// 辦公地址
String officeAddress;
// QQ號碼
Integer qqNumber;
// MSN號碼
String msn;
// 郵件
String email;
// 備注
String notes;
String getEmail() {
return email;
}
void setEmail(String email) {
this.email = email;
}
String getHomeAddress() {
return homeAddress;
}
void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}
Integer getHomePhone() {
return homePhone;
}
void setHomePhone(Integer homePhone) {
this.homePhone = homePhone;
}
String getMsn() {
return msn;
}
void setMsn(String msn) {
this.msn = msn;
}
String getName() {
return name;
}
void setName(String name) {
this.name = name;
}
String getNotes() {
return notes;
}
void setNotes(String notes) {
this.notes = notes;
}
String getOfficeAddress() {
return officeAddress;
}
void setOfficeAddress(String officeAddress) {
this.officeAddress = officeAddress;
}
Integer getOfficePhone() {
return officePhone;
}
void setOfficePhone(Integer officePhone) {
this.officePhone = officePhone;
}
Integer getPersonalMobilePhone() {
return personalMobilePhone;
}
void setPersonalMobilePhone(Integer personalMobilePhone) {
this.personalMobilePhone = personalMobilePhone;
}
Integer getQqNumber() {
return qqNumber;
}
void setQqNumber(Integer qqNumber) {
this.qqNumber = qqNumber;
}
public TelBook() {
}
public TelBook(String name, Integer personalMobilePhone) {
this.setName(name);
this.setPersonalMobilePhone(personalMobilePhone);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TelBook myfriend = new TelBook("張三", new Integer("13800138000"));
}
}
采用C/S的架構(gòu)方式。
首先用swing 畫幾個(gè)條條框框出來。做出顯示 和 添加 修改的界面。
添加的時(shí)候。吧輸入的信息存入數(shù)據(jù)庫
修改的時(shí)候 修改數(shù)據(jù)庫里面的內(nèi)容
查詢的時(shí)候 顯示數(shù)據(jù)庫里面的內(nèi)容。
不想用數(shù)據(jù)庫 也可以吧文件寫在磁盤上。不過這樣,還不如用個(gè)excel當(dāng)通訊錄用來的省事。
這就是high level。detail么 自己研究吧