实现通讯录的添加,查找,修改,排序,
package com.TongXunLu.services; import java.util.Scanner; import com.TongXunLu.Add.AddMenu; import com.TongXunLu.Delete.DeleteMenu; import com.TongXunLu.Select.SelectMenu; import com.TongXunLu.Update.UpdateMenu; public class App { public static void main(String[] args) { //欢迎进入系统 Welcome(); } public static void Welcome(){ System.out.println("*********************"); System.out.println("** 1 添加纪录 **"); System.out.println("** 2 查找记录 **"); System.out.println("** 3 修改记录 **"); System.out.println("** 4 删除记录 **"); System.out.println("** 5 排序记录 **"); System.out.println("** 6 退出系统 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1,最大是:6"); Scanner input=new Scanner(System.in); int sel=input.nextInt(); switch (sel) { case 1: //添加纪录 AddMenu.Add(); break; case 2: //查找记录 SelectMenu.Select(); break; case 3: //修改记录 UpdateMenu.menu (); break; case 4: DeleteMenu.menu(); break; case 5: //排序记录 CompartorMenu.menu(); break; case 6: System.out.println("系统退出!"); System.exit(0); break; } } }
package com.TongXunLu.Add; import java.util.List; import java.util.Scanner; import com.TongXunLu.Select.SelectAll; import com.TongXunLu.services.App; import com.TongXunLu.services.Person; public class AddMenu { //添加纪录菜单 public static void Add(){ System.out.println("*********************"); System.out.println("** 1 添加新纪录 **"); System.out.println("** 2 查看全纪录 **"); System.out.println("** 3 返回上一级 **"); System.out.println("请输入正确的数字,最小是:1,最大是:3"); Scanner input=new Scanner(System.in); int AddSel=input.nextInt(); switch (AddSel) { case 1: //添加新纪录 AddServices addPerson=new AddImplement(); addPerson.AddPerson(); break; case 2: //查看全记录 List<Person> list=SelectAll.SelectAllPerson(); for (Person p : list) { System.out.println(p.toString()); } Add(); break; case 3: //返回上一级 App.Welcome(); break; } } }
package com.TongXunLu.Add; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Scanner; import com.TongXunLu.tools.TelNoteRegex; import com.TongXunLu.tools.Tools; public class AddImplement implements AddServices{ @Override public void AddPerson() { Scanner input=new Scanner(System.in); String name=null; int age=0; String sex=null; String TelNum=null; String address=null; boolean b=false; while(b==false){ System.out.println("输入姓名,1-10位字母"); name=input.next(); b=TelNoteRegex.CheckName(name,b); } b=false; while(b==false){ System.out.println("输入年龄,1-200"); age=input.nextInt(); b=TelNoteRegex.CheckAge(age, b); } b=false; while(b==false){ System.out.println("输入性别,(男 m or M)(女 f or F)"); sex=input.next(); b=TelNoteRegex.CheckSex(sex, b); } b=false; while(b==false){ System.out.println("输入电话号码,6-10位数字"); TelNum=input.next(); b=TelNoteRegex.CheckTel(TelNum, b); } b=false; while(b==false){ System.out.println("输入地址,1-50位字母或数字"); address=input.next(); b=TelNoteRegex.CheckAddress(address, b); } //获取连接 驱动 Connection conn=null; PreparedStatement pstm=null; conn=Tools.getConnection(); try { pstm=conn.prepareStatement("insert into person(id,name,age,sex,telnum,address)values (person_sequence.nextval,?,?,?,?,?)"); pstm.setString(1, name); pstm.setInt(2, age); pstm.setString(3, sex); pstm.setString(4, TelNum); pstm.setString(5, address); if(pstm.executeUpdate()>0){ System.out.println("添加成功!"); } AddMenu.Add(); } catch (SQLException e) { // e.printStackTrace(); System.out.println("输入错误!请重新输入"); AddPerson(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } }
package com.TongXunLu.Add; public interface AddServices { //添加新纪录 public void AddPerson(); }
package com.TongXunLu.Delete; public interface DeleteServices { public abstract void deleteByID(int id); public abstract void deleteAll(); }
package com.TongXunLu.Delete; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.TongXunLu.tools.Tools; public class DeleteImplement implements DeleteServices{ Connection conn=null; PreparedStatement pstm=null; @Override public void deleteByID(int id) { // 删除指定记录 conn=Tools.getConnection(); try { pstm=conn.prepareStatement("delete from person where id=?"); pstm.setInt(1, id); if(pstm.executeUpdate()>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } @Override public void deleteAll() { // 删除所有记录 conn=Tools.getConnection(); try { pstm=conn.prepareStatement("delete from person "); if(pstm.executeUpdate()>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } }
package com.TongXunLu.Delete; import java.util.List; import java.util.Scanner; import com.TongXunLu.Select.SelectAll; import com.TongXunLu.services.App; import com.TongXunLu.services.Person; import com.TongXunLu.tools.Count; public class DeleteMenu { public static void menu(){ DeleteServices del=new DeleteImplement(); System.out.println("*********************"); System.out.println("** 1 查看全记录 **"); System.out.println("** 2 删除指定记录 **"); System.out.println("** 3 删除全部记录 **"); System.out.println("** 4 返回上一级 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1,最大是:4"); Scanner input=new Scanner(System.in); int sel=input.nextInt(); switch (sel) { case 1: List<Person> list=SelectAll.SelectAllPerson(); for (Person p : list) { System.out.println(p.toString()); } DeleteMenu.menu(); break; case 2: int id=Count.InputXuHao(); del.deleteByID(id); DeleteMenu.menu(); break; case 3: del.deleteAll(); DeleteMenu.menu(); break; case 4: App.Welcome(); break; } } }
package com.TongXunLu.Select; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.TongXunLu.services.Person; import com.TongXunLu.tools.Tools; public class SelectAll { /* * 查询所有记录 */ public static List<Person> SelectAllPerson(){ List <Person>list=new ArrayList(); Connection conn=null; PreparedStatement pstm=null; ResultSet rs=null; conn=Tools.getConnection(); try { pstm=conn.prepareStatement("select *from person"); rs=pstm.executeQuery(); while(rs.next()){ Person p=new Person(); p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); // System.out.println(p.toString()); list.add(p); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } return list; } }
package com.TongXunLu.Select; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; import com.TongXunLu.services.Person; import com.TongXunLu.tools.Tools; public class SelectImplement implements SelectServices{ Scanner input=new Scanner(System.in); Connection conn=null; PreparedStatement pstm=null; ResultSet rs=null; Person p=new Person(); @Override public void findByName() { //按姓名查找 System.out.println("输入姓名,1-10为字母"); try { String name=input.next(); conn=Tools.getConnection(); pstm=conn.prepareStatement("select *from person where name=?"); pstm.setString(1, name); rs=pstm.executeQuery(); if(rs.next()){ p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); System.out.println(p.toString()); }else{ System.out.println("无此联系人!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } } @Override public void findByAge() { System.out.println("输入年龄,1-100+"); int age=input.nextInt(); try { conn=Tools.getConnection(); pstm=conn.prepareStatement("select *from person where age=?"); pstm.setInt(1, age); rs=pstm.executeQuery(); while(rs.next()){ p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); System.out.println(p.toString()); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } } @Override public void findBySex() { System.out.println("输入性别,(男 m or M)(女 f or F)"); String sex=input.next(); String sex_Up=sex.toUpperCase(); String sex_Low=sex.toLowerCase(); try { conn=Tools.getConnection(); pstm=conn.prepareStatement("select *from person where sex=? or sex=?"); pstm.setString(1, sex_Up); pstm.setString(2, sex_Low); rs=pstm.executeQuery(); while(rs.next()){ p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); System.out.println(p.toString()); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } } @Override public void findByTel() { System.out.println("输入电话号码,6-10位数字"); String TelNum=input.next(); try { conn=Tools.getConnection(); pstm=conn.prepareStatement("select *from person where TelNum=?"); pstm.setString(1, TelNum); rs=pstm.executeQuery(); while(rs.next()){ p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); System.out.println(p.toString()); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } } @Override public void findByAddress() { System.out.println("输入地址,1-50位字母或数字"); String address=input.next(); try { conn=Tools.getConnection(); pstm=conn.prepareStatement("select *from person where address=?"); pstm.setString(1, address); rs=pstm.executeQuery(); while(rs.next()){ p.setId(rs.getInt(1)); p.setName(rs.getString(2)); p.setAge(rs.getInt(3)); p.setSex(rs.getString(4)); p.setTelNum(rs.getString(5)); p.setAddress(rs.getString(6)); System.out.println(p.toString()); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } } }
package com.TongXunLu.Select; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import com.TongXunLu.services.App; import com.TongXunLu.services.Person; import com.TongXunLu.tools.Tools; public class SelectMenu { //查找记录菜单 public static void Select(){ System.out.println("*********************"); System.out.println("** 1 按姓名查找 **"); System.out.println("** 2 按年龄查找 **"); System.out.println("** 3 按性别查找 **"); System.out.println("** 4 按号码查找 **"); System.out.println("** 5 按住址查找 **"); System.out.println("** 6 查看全记录 **"); System.out.println("** 7 返回上一级 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1 最大是:7"); SelectServices select=new SelectImplement(); Scanner input=new Scanner(System.in); int sel=input.nextInt(); switch (sel) { case 1: //按姓名查找 select.findByName(); SelectMenu.Select(); break; case 2: //按年龄查找 select.findByAge(); SelectMenu.Select(); break; case 3: //按性别查找 select.findBySex(); SelectMenu.Select(); break; case 4: //按号码查找 select.findByTel(); SelectMenu.Select(); break; case 5: //按住址查找 select.findByAddress(); SelectMenu.Select(); break; case 6: //查看全记录 List<Person> list=SelectAll.SelectAllPerson(); for (Person p : list) { System.out.println(p.toString()); } SelectMenu.Select(); break; case 7: App.Welcome(); break; } } }
package com.TongXunLu.Select; public interface SelectServices { public abstract void findByName(); public abstract void findByAge(); public abstract void findBySex(); public abstract void findByTel(); public abstract void findByAddress(); }
package com.TongXunLu.services; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; import com.TongXunLu.Select.SelectAll; import com.TongXunLu.tools.AgeComparator; import com.TongXunLu.tools.NameComparator; import com.TongXunLu.tools.SexComparator; public class CompartorMenu { public static void menu(){ System.out.println("*********************"); System.out.println("** 1 按姓名排序 **"); System.out.println("** 2 按年龄排序 **"); System.out.println("** 3 按性别排序 **"); System.out.println("** 4 查看全部记录 **"); System.out.println("** 5 返回上一级 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1,最大是:4"); Scanner input=new Scanner(System.in); int sel=input.nextInt(); List<Person> list=SelectAll.SelectAllPerson(); switch (sel) { case 1: //按姓名排序 Collections.sort(list, new NameComparator()); for (Person p : list) { System.out.println(p.toString()); } menu(); break; case 2: Collections.sort(list, new AgeComparator()); for (Person p : list) { System.out.println(p.toString()); } menu(); break; case 3: Collections.sort(list, new SexComparator()); for (Person p : list) { System.out.println(p.toString()); } menu(); break; case 4: for (Person p : list) { System.out.println(p.toString()); } menu(); break; case 5: App.Welcome(); break; } } }
package com.TongXunLu.services; public class Person{ private int id; private String name; private int age; private String sex; private String TelNum; private String Address; public Person(){} public Person(int id,String name,int age,String sex,String TelNum,String Address){ this.id=id; this.name=name; this.age=age; this.sex=sex; this.TelNum=TelNum; this.Address=Address; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getTelNum() { return TelNum; } public void setTelNum(String telNum) { TelNum = telNum; } public String getAddress() { return Address; } public void setAddress(String address) { Address = address; } @Override public String toString() { return "序号\t" + id + "\t姓名\t" + name + "\t年龄\t" + age + "\t性别\t" + sex + "\t电话号码\t" + TelNum + "\t住址\t" + Address ; } public int OrderByName(Object o) { //姓名排序 Person input=(Person)o; return name.compareTo(input.name); } }
package com.TongXunLu.tools; import java.util.Comparator; import com.TongXunLu.services.Person; public class AgeComparator implements Comparator{ @Override public int compare(Object o1, Object o2) { // 年龄排序 Person p1=(Person)o1; Person p2=(Person)o2; return p1.getAge()-p2.getAge(); } }
package com.TongXunLu.tools; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; public class Count { public static int InputXuHao(){ Scanner input=new Scanner(System.in); Connection conn=null; PreparedStatement pstm=null; ResultSet rs=null; conn=Tools.getConnection(); int count=0; try { pstm=conn.prepareStatement("select count(*)from person"); rs=pstm.executeQuery(); while(rs.next()){ count=rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(rs); Tools.Close(pstm); Tools.Close(conn); } System.out.println("请输入记录序号"); System.out.println("请输入正确的数字,最小是:1,最大是:"+count); int id=input.nextInt(); return id; } }
package com.TongXunLu.tools; import java.util.Comparator; import com.TongXunLu.services.Person; public class NameComparator implements Comparator { @Override public int compare(Object o1, Object o2) { // 姓名排序 Person p1=(Person)o1; Person p2=(Person)o2; return p1.getName().compareTo(p2.getName()); } }
package com.TongXunLu.tools; import java.util.Comparator; import com.TongXunLu.services.Person; public class SexComparator implements Comparator{ @Override public int compare(Object o1, Object o2) { // 性别排序 Person p1=(Person)o1; Person p2=(Person)o2; return p1.getSex().compareTo(p2.getSex()); } }
package com.TongXunLu.tools; public class TelNoteRegex { public static boolean CheckName(String name,boolean b){ if(name.length()>10){ try { throw new Exception("输入姓名错误,请检查!"); } catch (Exception e) { // e.printStackTrace(); System.out.println(e.getMessage()); } }else{ b=true; } return b; } public static boolean CheckAge(int age,boolean b){ if(age<0||age>200){ try { throw new Exception("输入年龄错误,请检查!"); } catch (Exception e) { // e.printStackTrace(); System.out.println(e.getMessage()); } }else{ b=true; } return b; } public static boolean CheckSex(String sex,boolean b){ if(!(sex.equals("F")||sex.equals("f")||sex.equals("M")||sex.equals("m"))){ try { throw new Exception("输入性别错误,请检查!"); } catch (Exception e) { // e.printStackTrace(); System.out.println(e.getMessage()); } }else{ b=true; } return b; } public static boolean CheckTel(String Tel,boolean b){ if(Tel.length()<6||Tel.length()>10){ try { throw new Exception("电话输入错误,请检查!"); } catch (Exception e) { // e.printStackTrace(); System.out.println(e.getMessage()); } }else{ b=true; } return b; } public static boolean CheckAddress(String Address,boolean b){ if(Address.length()<0||Address.length()>50){ try { throw new Exception("地址输入错误,请检查!"); } catch (Exception e) { // e.printStackTrace(); System.out.println(e.getMessage()); } }else{ b=true; } return b; } }
package com.TongXunLu.tools; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Tools { static{ try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection getConnection(){ Connection conn=null; try { conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl11","scott","0000"); } catch (SQLException e) { e.printStackTrace(); } return conn; } /** * 关闭资源 * @param conn */ public static void Close(Connection conn){ try { if(conn!=null &&!conn.isClosed()){ conn.close(); } } catch (SQLException e) { e.printStackTrace(); } } public static void Close(PreparedStatement pstm){ try { if(pstm!=null &&!pstm.isClosed()){ pstm.close(); } } catch (SQLException e) { e.printStackTrace(); } } public static void Close(ResultSet rs){ try { if(rs!=null &&!rs.isClosed()){ rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } }
package com.TongXunLu.Update; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; import com.TongXunLu.tools.Tools; public class UpdateImplement implements UpdateServices{ Connection conn=null; PreparedStatement pstm=null; @Override public void UpdateName(String name,int id) { // 修改姓名 try { conn=Tools.getConnection(); pstm=conn.prepareStatement("Update person set name=? where id=?"); pstm.setString(1, name); pstm.setInt(2, id); if(pstm.executeUpdate()>0){ System.out.println("修改成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } @Override public void UpdateAge(int age,int id) { try { conn=Tools.getConnection(); pstm=conn.prepareStatement("Update person set age=? where id=?"); pstm.setInt(1, age); pstm.setInt(2, id); if(pstm.executeUpdate()>0){ System.out.println("修改成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } @Override public void UpdateSex(String sex,int id) { try { conn=Tools.getConnection(); pstm=conn.prepareStatement("Update person set sex=? where id=?"); pstm.setString(1, sex); pstm.setInt(2, id); if(pstm.executeUpdate()>0){ System.out.println("修改成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } @Override public void UpdateTel(String TelNum,int id) { try { conn=Tools.getConnection(); pstm=conn.prepareStatement("Update person set TelNum=? where id=?"); pstm.setString(1, TelNum); pstm.setInt(2, id); if(pstm.executeUpdate()>0){ System.out.println("修改成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } @Override public void UpdateAddress(String address,int id) { try { conn=Tools.getConnection(); pstm=conn.prepareStatement("Update person set address=? where id=?"); pstm.setString(1, address); pstm.setInt(2, id); if(pstm.executeUpdate()>0){ System.out.println("修改成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally{ Tools.Close(pstm); Tools.Close(conn); } } }
package com.TongXunLu.Update; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import com.TongXunLu.Select.SelectAll; import com.TongXunLu.services.App; import com.TongXunLu.services.Person; import com.TongXunLu.tools.Tools; public class UpdateMenu { public static void menu(){ System.out.println("*********************"); System.out.println("** 1 查看全记录 **"); System.out.println("** 2 修改指定记录 **"); System.out.println("** 3 返回上一级 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1,最大是:3"); Scanner input=new Scanner(System.in); int sel=input.nextInt(); switch (sel) { case 1: List<Person> list=SelectAll.SelectAllPerson(); for (Person p : list) { System.out.println(p.toString()); } UpdateMenu.menu(); break; case 2: ZhiDingXiuGai.menu(); UpdateMenu.menu(); break; case 3: App.Welcome(); break; } } }
package com.TongXunLu.Update; public interface UpdateServices { //修改姓名 public abstract void UpdateName(String name,int id); //修改年龄 public abstract void UpdateAge(int age,int id); //修改性别 public abstract void UpdateSex(String sex,int id); //修改号码 public abstract void UpdateTel(String TelNum,int id); //修改住址 public abstract void UpdateAddress(String address,int id); }
package com.TongXunLu.Update; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; import com.TongXunLu.tools.Count; import com.TongXunLu.tools.TelNoteRegex; import com.TongXunLu.tools.Tools; public class ZhiDingXiuGai { public static void menu(){ UpdateServices up=new UpdateImplement(); int id=Count.InputXuHao(); System.out.println("*********************"); System.out.println("** 1 修改姓名 **"); System.out.println("** 2 修改年龄 **"); System.out.println("** 3 修改性别 **"); System.out.println("** 4 修改号码 **"); System.out.println("** 5 修改住址 **"); System.out.println("** 6 返回上一级 **"); System.out.println("*********************"); System.out.println("请输入正确的数字,最小是:1,最大是:6"); Scanner input= new Scanner (System.in); int sel=input.nextInt(); switch (sel) { case 1: //修改姓名 String name=null; boolean b=false; while(b==false){ System.out.println("输入姓名,1-10位字母"); name=input.next(); b=TelNoteRegex.CheckName(name,b); } up.UpdateName(name, id); menu(); break; case 2: //2 修改年龄 int age=0; b=false; while(b==false){ System.out.println("输入年龄,1-200"); age=input.nextInt(); b=TelNoteRegex.CheckAge(age, b); } up.UpdateAge(age,id); menu(); break; case 3: // System.out.println("输入性别,(男 m or M)(女 f or F)"); String sex=null; b=false; while(b==false){ System.out.println("输入性别,(男 m or M)(女 f or F)"); sex=input.next(); b=TelNoteRegex.CheckSex(sex, b); } up.UpdateSex(sex,id); menu(); break; case 4: // System.out.println("输入电话号码,6-10位数字"); String TelNum=null; b=false; while(b==false){ System.out.println("输入电话号码,6-10位数字"); TelNum=input.next(); b=TelNoteRegex.CheckTel(TelNum, b); } up.UpdateTel(TelNum, id); menu(); break; case 5: // System.out.println("输入地址,1-50位字母或数字"); String address=null; b=false; while(b==false){ System.out.println("输入地址,1-50位字母或数字"); address=input.next(); b=TelNoteRegex.CheckAddress(address, b); } up.UpdateAddress(address, id); menu(); break; case 6: UpdateMenu.menu(); break; } } }
初学java,程序写的不好
时间: 2024-10-06 09:14:00