第一范文网 - 专业文章范例文档资料分享平台

数据结构课程设计—java通讯录管理系统

来源:用户分享 时间:2025/8/18 11:54:16 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

import java.io.*;

import java.util.*;

public class LittleProgram {

static boolean isDelete = true;

static boolean isFind = true;

public static void main(String [] args)//主方法,程序从这里开始运行 throws IOException,NumberNotFoundException {

int choice=-1;

do{

LittleProgram lp = new LittleProgram();

System.out.println();

System.out.println(\ System.out.println();

System.out.println(\通訊錄管理系统\

System.out.println(\ 请用号码插入,查找,修改,删除数据\ System.out.println();

System.out.println(\ System.out.print(\增加号码:\\n\ \查找号码:\\n\

\删除号码:\\n\

\清除所有号码:\\n\

\把号码全部打印到屏幕\\n\\把通讯录按号码排序\\n\

\修改号码\\n\

\统计通码讯录的总人数\\n\ \关于作者\\n\ \退出程序.\\n\ \输入:\

BufferedReader in = //从终 new BufferedReader( //端接 new InputStreamReader(System.in));//收数 String inputLine = in.readLine(); //字选 choice= Integer.valueOf(inputLine).intValue();//项; switch(choice)

{

case 1: {//1.增加号码 String str = lp.inputData();

lp.addData(str);

System.out.println(\增加号码成功.\ timeOut(1); }break;

case 2: {//2.查找号码

long find = 0;

System.out.print(\请输入你要查找的号码:\ BufferedReader inn = new BufferedReader(

new InputStreamReader(System.in)); String inputLi = inn.readLine();

find = Integer.valueOf(inputLi).longValue(); lp.findData(find);

timeOut(2); }break;

case 3: {//3.删除号码

long deleteNumber = 0;

System.out.print(\请输入你想删除号码:\ BufferedReader bf =

new BufferedReader (

new InputStreamReader(System.in)); String inputL = bf.readLine();

deleteNumber = Integer.valueOf(inputL).longValue(); lp.deleteData(deleteNumber); if(isDelete)

System.out.println(\删除号码成功!\ timeOut(1); }break;

case 4: {

lp.clearData();//4.清除所有号码 timeOut(1);

}break; case 5: {

print();//5.把号码全部打印到屏幕 timeOut(2); }break;

case 6: {

lp.numSort();//6.把号码按号码排序

System.out.println(\按照号码从小到大排序成功!\\n\ \排序后:\\n\ print(); timeOut(2); }break;

case 7: {

lp.rewrite();//7.修改号码 timeOut(2); }break; case 8: {

int count = lp.count();

System.out.println(\共有\个号码记录.\ timeOut(2); }break; case 9: {

System.out.print(\李雪萍\\n\

\安徽理工大學理學院\\n\ \ timeOut(4); }break;

}}while (choice != 0);

System.out.println(\

System.exit(0); }

public String inputData()//从终端接收数据的方法,返回字符串 throws IOException,NumberFormatException

{

System.out.print(\请依次输入 :号码 姓名 地址 生日\\n\ \每项数据请用空格隔开:\ String all = \

try{

BufferedReader in = //从终 new BufferedReader ( //端接 new InputStreamReader(System.in)); //收数 String inputLine = in.readLine(); //据

StringTokenizer str = new StringTokenizer(inputLine,\\接收的数据用空格隔开,这个类用来提取每个字符串

long num = Integer.valueOf(str.nextToken()).longValue();//号码 String name = (String)str.nextToken(); //姓名 String add = (String)str.nextToken(); // 地址 String birth = (String)str.nextToken();//出生年月 all = String.valueOf(num) +\ name +\

add +\

String.valueOf(birth);//把所有的数据用\, \隔开然后在连起来放进字符串all

}catch (IOException e){}

catch (NumberFormatException e){} return all;//返回字符串all

}

public void addData(String str)//增加号码的方法 throws IOException {

String s1 =\

File file = new File(\

if (file.exists())//如果文件data.txt存在 { try{

BufferedReader in = new BufferedReader(

new FileReader(file)); while ((s1=in.readLine())!=null)

s2+=s1+\把文件中的每行数据全部放进一个字符串s2 s2+=str+\ //再把s2于形参str相连放进s2

BufferedReader in2 = //把字符 new BufferedReader( //串s2也 new StringReader(s2)); //就是原

PrintWriter out = //文件+

new PrintWriter( //形参str(新输入的一行数据)

new BufferedWriter( //重新写进data.txt new FileWriter(file))); //覆盖原来的数据 while ((s3=in2.readLine())!= null) {

out.println(s3); }

out.close();

//System.out.println(\ }catch (IOException e){} }else{

System.err.println(\ } }

public void clearData()//清除data.txt的所有数据的方法 throws IOException

{

File file = new File(\ if(file.exists())//如果文件在 { try{

PrintWriter out = new PrintWriter(

new BufferedWriter(

new FileWriter(file)));

out.print(\在文件data.txt里写进一个空字符,所以清除了原来的内容 out.close(); //关闭文件

System.out.println(\

数据结构课程设计—java通讯录管理系统.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9ilfy0q3wr83hrt8bveb_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top