携号转网雏形

编程入门 行业动态 更新时间:2024-10-07 00:15:17

携号转网<a href=https://www.elefans.com/category/jswz/34/1726631.html style=雏形"/>

携号转网雏形

User:

private String name;// 姓名private String id;// 身份证号private String money;// 资费金额private String phone;// 手机号public UserY() {super();}public UserY(String name, String id, String money, String phone) {super();this.name = name;this.id = id;this.money = money;this.phone = phone;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((id == null) ? 0 : id.hashCode());result = prime * result + ((money == null) ? 0 : money.hashCode());result = prime * result + ((name == null) ? 0 : name.hashCode());result = prime * result + ((phone == null) ? 0 : phone.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;UserY other = (UserY) obj;if (id == null) {if (other.id != null)return false;} else if (!id.equals(other.id))return false;if (money == null) {if (other.money != null)return false;} else if (!money.equals(other.money))return false;if (name == null) {if (other.name != null)return false;} else if (!name.equals(other.name))return false;if (phone == null) {if (other.phone != null)return false;} else if (!phone.equals(other.phone))return false;return true;}@Overridepublic String toString() {return name + "*" + id + "*" + money + "*" + phone;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getMoney() {return money;}public void setMoney(String money) {this.money = money;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}

移动:

```java
//检索自己的数据库文件(cm.txt)public static List<UserY> findUsers() throws IOException{List<UserY> list=new ArrayList<UserY>();File file=new File("F:\\ceshi\\移动\\cm.txt");RandomAccessFile raf=new RandomAccessFile(file, "rw");//循环读取while (raf.read()!=-1) {//防止指针多跑raf.seek(raf.getFilePointer()-1);//读取属性----循环一次为一行byte[] b1=new byte[12];//名字String name=findDate(raf, b1);//就得到了名字了byte[] b2=new byte[11];//手机号String ph=findDate(raf, b2);//就得到了手机号了byte[] b3=new byte[18];//身份证号String id=findDate(raf, b3);//就得到了身份证了byte[] b4=new byte[12];//资费String money=findDate(raf, b4);//就得到了资费了//写完一行,需要换行raf.skipBytes(2);//写完了,存到集合UserY uy=new UserY(name, id, money, ph);list.add(uy);}return list;}//封装public static String findDate(RandomAccessFile raf,byte[] bts) throws IOException{raf.read(bts);return new String(bts);}//判断手机号是不是存在public UserY phone(String phone) throws IOException{//先遍历list集合中是不是有输入的手机号phonefor(UserY uy:findUsers()){//判定当前用户的电话是不是存在if(uy.getPhone().equalsIgnoreCase(phone)){System.out.println(uy.getName()+"用户存在");return uy;}}return null;//多次循环都查找不到,就返回null}//判断指定用户是不是欠费public boolean money(UserY uy){String mo=uy.getMoney();double d=Double.parseDouble(mo);
//		true表示欠费return d<0;//d小于零返回true,大于o返回flase}//序列化将这个人的信息写到一个txt文件中public File writerUserY(UserY uy) throws IOException{//想保证单据的唯一性:时间毫秒数File file =new File("F:\\ceshi\\移动\\date.txt");FileOutputStream fos=new FileOutputStream(file);ObjectOutputStream oos=new ObjectOutputStream(fos);//写入到文件夹oos.writeObject(uy);return file;}//转网业务public File YL() throws IOException{System.out.println("------------现在在移动转网服务------------");//接收输入的手机号Scanner key=new Scanner(System.in);System.out.println("请输入手机号:");String phone=key.next();//将输入的手机号获取用户UserY uy1=phone(phone);//这是上面的判断手机号是不是存在的方法(如果存在,把手机号返回过来存起来)if(uy1==null){System.out.println("没有此用户");return null;}//判断是不是欠费boolean bln=money(uy1);//调用的判断欠费的方法if(bln){//如果为true则是欠费System.out.println("欠费不能使用转网功能");return null;}//如果用户存钱且不欠费,可以转网return writerUserY(uy1);//要是上面写入的方法,就是上面都符合,那就把用户存入到date.txt里面去}

联通

/** 联通公司业务类型*    移动将用户信息存到了date.txt(通过序列化)*/
public class LianTong {//通过传过来的序列化对象,实行反序列化读取用户信息//public UserY readuy(File file) throws IOException, ClassNotFoundException{//反序列化FileInputStream fis=new FileInputStream(file);ObjectInputStream ois=new ObjectInputStream(fis);UserY uy=(UserY)ois.readObject();return uy;}//反序列化后,将用户信息写入到联通的数据库F:\ceshi\联通\cn.txtpublic void writer(UserY uy) throws IOException{//构建rafFile file=new File("F:\\ceshi\\联通\\cu.txt");RandomAccessFile raf=new RandomAccessFile(file, "rw");//按位写入raf.seek(file.length());//1-12用户名raf.write(uy.getName().getBytes());//手机号raf.write(uy.getPhone().getBytes());//身份证号raf.write(uy.getId().getBytes());//资费信息raf.write(uy.getMoney().getBytes());//写完一行要换行raf.write('\r');raf.write('\n');}/*入网:*    封装一个转网转入的业务(在YiDong移动转出的时候,返回值是File类型,所以这里接收也是File类型)*/public void zhuanru(File file) throws ClassNotFoundException, IOException{System.out.println("-----入网联通业务办理中-------");UserY uy=readuy(file);//调用反序列化的方法//写到联通数据库中writer(uy);//写入到数据库的方法System.out.println("移动转联通业务办理成功");}

``
测试类:

public static void main(String[] args) throws IOException, ClassNotFoundException{//构建移动YiDong yd=new YiDong();//构建联通LianTong lt=new LianTong();//在移动里办转网业务移动里:   public File YLFile file=yd.YL();// if(file==null){System.out.println("转网失败");//可能是欠费或者用户不存在}else {lt.zhuanru(file);//把file传进去}

更多推荐

携号转网雏形

本文发布于:2024-03-23 19:59:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1742214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:雏形   携号转网

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!