| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2537 人关注过本帖, 1 人收藏
标题:写了个代码请大家帮忙看看,指正一下(小白)
只看楼主 加入收藏
诺亚1998
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2020-6-22
收藏(1)
 问题点数:0 回复次数:4 
写了个代码请大家帮忙看看,指正一下(小白)
package practice;
public class Four_Fortyfive_Array_User {
        //数组空间
        static Four_Fortyfive_Object_User[] Array=new Four_Fortyfive_Object_User[0];
        //有效数据个数
        static int num=0;
        
        
        public Four_Fortyfive_Array_User(){
            insert(new Four_Fortyfive_Object_User("张三","123456","17788888888"));
             insert(new Four_Fortyfive_Object_User("李四","123456","17788888888"));
             Array[1].saveManey(1000.0);
             for(int i=0;i<num;i++){
                          Array[i].print();
                      }
        }
        //对数组加长5
        static void expand(){
            Array=java.util.Arrays.copyOf(Array,Array.length+5);
        }
        //移除指定位置的元素
        public void remove(int postion){
            if(postion>num-1||postion<0){
                System.out.println("位置不合法不予执行。");
                return;
            }
            for(int i=postion;i<num-1;i++){
                Array[i]=Array[i+1];
            }
            num--;
        }
        //添加一个数在指定位置
        static void insert(Four_Fortyfive_Object_User value){
            if(Array.length==num){
                expand();
            }
            Array[num]=value;
            num++;
        }
        static void allPrint(){
            for(int i=0;i<num;i++){
                     Array[i].print();
                 }
        }
}
package practice;
import java.util.Scanner;
public class Four_Fortyfive_Object_Bank {
    private Scanner Input=new Scanner(System.in);
    private String Name;
    private Four_Fortyfive_Array_User Depot=new Four_Fortyfive_Array_User() ;
    //构造函数
    public Four_Fortyfive_Object_Bank(){};
    public Four_Fortyfive_Object_Bank(String Name){
        this.Name=Name;
    };
    //调出主菜单
    public void showMenu(){
        do{
            System.out.println("-----------------------------------"+Name+"欢迎您------------------------------------");
            System.out.println("1、开户  2、存款  3、取款  4、转账  5、查询余额  6、修改密码  7、修改预留手机号码  8、注销账户  0、退出");
            System.out.println("-----------------------------------------------------------------------------------");
            System.out.print("请输入操作代码:");
            int step=Input.nextInt();
            switch(step){
            case 1:setUser();break;
            case 2:saveMoney();break;
            case 3:getMoney();break;
            case 4:transferMoney();break;
            case 5:showSurplus();break;
            case 6:changePassWord();break;
            case 7:changePhoneNum();break;
            case 8:logout();break;
            case 0:System.out.println("谢谢您的使用,欢迎下次光临。");Depot.allPrint();return;
            default:break;
            }
        }while(true);
    }
    //开户
    public void setUser(){
        String[] a=new String[4];
        System.out.println("---开户程序---");
        System.out.println("请输入您的姓名:");
        a[0]=this.Input.next();
        do{
            System.out.println("请输入您的密码:");
            a[1]=Input.next();
            System.out.println("请再次输入以确认您的密码:");
            a[2]=Input.next();
        }while(!a[2].equals(a[1]));
        System.out.println("请输入您的电话:");
        a[3]=Input.next();
        Four_Fortyfive_Object_User b=new Four_Fortyfive_Object_User(a[0],a[1],a[3]);
        Depot.insert(b);
        System.out.println("您的卡号是:"+b.showCardId());
        System.out.println("---开户完成---");
    }
    //存钱
    public void saveMoney(){
        boolean a;
        String cardId;
        double money;
        Four_Fortyfive_Object_User to;
        System.out.println("---存款程序---");
        do{
            do{
                System.out.println("请输入您希望存款的卡号是:");
                cardId=Input.next();
                to=find(cardId);
            }while(to==null);
            do{
                System.out.println("请输入您希望存款的金额是:");
                money=Input.nextDouble();
            }while(money<0.0);
            System.out.println("您确定是向卡号为"+cardId+"的用户存上"+money+"元吗?(确认请输入true,重输请输入false)");
            a=Input.nextBoolean();
        }while(!a);
        to.saveManey(money);
        System.out.println("已经向卡号为"+cardId+"的用户存上"+money+"元");
        System.out.println("---存款完成---");
    }
    //寻人
    public Four_Fortyfive_Object_User find(String CardId){
        for(int i=0;i<Depot.num;i++){
            if(CardId.equals(Depot.Array[i].showCardId())){return Depot.Array[i];}
        }
        return null;
    }
    //登录
    public Four_Fortyfive_Object_User signIn(){
        int a=0;
        do{
            String CardId;
            String PassWord;
            Four_Fortyfive_Object_User User;
            System.out.println("请输入您的卡号:");
            CardId=Input.next();
            User=find(CardId);
            System.out.println("请输入您的密码:");
            PassWord=Input.next();
            if(PassWord.equals(User.showPassWord())){
                return User;
            }
            a++;
        }while(a<2);
        System.out.println("*******吞卡*******");
        System.exit(0);
        return null;
    }
    //取款
    public void getMoney(){
        double money;
        Four_Fortyfive_Object_User from;
        System.out.println("---取款程序---");
        from=signIn();
        do{
            System.out.println("您要取得金额为:");
            money=Input.nextDouble();
        }while(money>from.showSurplus()||money<0.0);
        from.giveMoney(money);
        System.out.println("---出款---");
        System.out.println("---取款完成---");   
    }
    //转账
    public void transferMoney(){
        double money;
        Four_Fortyfive_Object_User from;
        Four_Fortyfive_Object_User to;
        System.out.println("---转账程序---");
        from=signIn();
        do{
            System.out.println("您要转账的金额为:");
            money=Input.nextDouble();
        }while(money>from.showSurplus()||money<0.0);
        do{
            System.out.println("请输入您要转入的卡号是:");
            to=find(Input.next());
        }while(to==null);
        from.giveMoney(money);
        to.saveManey(money);
        System.out.println("已经从卡"+from.showCardId()+"向卡"+to.showCardId()+"转入"+money+"元");
        System.out.println("---转账结束---");
    }
    //查询余额
    public void showSurplus(){
        Four_Fortyfive_Object_User from;
        System.out.println("---查询余额---");
        from=signIn();
        System.out.println("您的余额是:"+from.showSurplus());
        System.out.println("---查询结束---");
    }
    //改变密码
    public void changePassWord(){
        Four_Fortyfive_Object_User to;
        String NewPassWord;
        System.out.println("---修改密码---");
        to=signIn();
        do{
            System.out.println("您的新密码是:");
            NewPassWord=Input.next();
            System.out.println("确认您的新密码是:");
        }while(!NewPassWord.equals(Input.next()));
        to.changePassWord(NewPassWord);
        System.out.println("---修改成功---");
        System.out.println("---修改结束---");   
    }
    //改变手机号
        public void changePhoneNum(){
            Four_Fortyfive_Object_User to;
            String NewPhoneNum;
            System.out.println("---修改手机号---");
            to=signIn();
            System.out.println("您的新手机号是:");
            NewPhoneNum=Input.next();
            to.changePhoneNum(NewPhoneNum);
            System.out.println("修改成功,您的新手机号是:"+NewPhoneNum);
            System.out.println("---修改结束---");   
        }
        //注销
        public void logout(){
            Four_Fortyfive_Object_User to;
            System.out.println("---注销程序---");
            to=signIn();
            int num=0;
            if(to.showSurplus()!=0){
                System.out.println("请取完所有余款。");
                System.out.println("---注销失败---");
                return;
            }
            for(int i=0;i<Depot.num;i++){
                if(to.equals(Depot.Array[i])){
                    num=i;
                }
            }
            Depot.remove(num);
            System.out.println("---注销结束---");
        }   
}
package practice;
public class Four_Fortyfive_Object_User {
    private String CardId;
    private String Name;
    private String PassWord;
    private String PhoneNum;
    private double Surplus=0.0;
    //public Four_Fortyfive_Object_User(){};
    public Four_Fortyfive_Object_User(String Name,String PassWord,String PhoneNum){
        this.Name=Name;
        this.PassWord=PassWord;
        this.PhoneNum=PhoneNum;
        int a=(int)(Math.random()*10000);
        if(a<1000){
            if(a<100){
                if(a<10){
                    this.CardId="61000001000"+a;
                }else{
                    this.CardId="6100000100"+a;
                }
            }else{
                this.CardId="610000010"+a;
            }   
        }else{
            this.CardId="61000001"+a;
        }        
    }
    public void print(){
        System.out.println("卡号:"+this.CardId);
        System.out.println("姓名:"+this.Name);
        System.out.println("密码:"+this.PassWord);
        System.out.println("手机:"+this.PhoneNum);
        System.out.println("余额:"+this.Surplus);
    }
    public String showCardId(){
        return this.CardId;
    }
    public void saveManey(double money){
        this.Surplus+=money;
    }
    public String showPassWord(){
        return this.PassWord;
    }
    public double showSurplus(){
        return this.Surplus;
    }
    public void giveMoney(double money){
        this.Surplus-=money;
    }
    public void changePassWord(String newpassword){
        this.PassWord=newpassword;
    }
    public void changePhoneNum(String newPhoneNum){
        this.PhoneNum=newPhoneNum;
    }   
}
package practice;
public class QF_Four_Section_Fortyfive {
    public static void main(String[] arg){
        Four_Fortyfive_Object_Bank zhong=new Four_Fortyfive_Object_Bank("中国银行");
        zhong.showMenu();
    }
}
搜索更多相关主题的帖子: System public String println out 
2020-06-23 11:48
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
有什么问题?

剑栈风樯各苦辛,别时冰雪到时春
2020-06-24 23:17
诺亚1998
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2020-6-22
收藏
得分:0 
回复 2楼 林月儿
主要是在自学,没个老师什么的,发到这想让各位朋友看看,尤其是格式,基础用法,和一些线程安全之类的问题
2020-06-25 20:59
sdozhangland
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-9-15
收藏
得分:0 
命名不规范
2020-09-15 14:14
rh2020
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-10-27
收藏
得分:0 
可以去问一下专业的人员

2020-10-29 11:49
快速回复:写了个代码请大家帮忙看看,指正一下(小白)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033862 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved