| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 835 人关注过本帖
标题:改错,一个关于模式银行帐户功能的程序
只看楼主 加入收藏
SD7436
Rank: 2
等 级:论坛游民
帖 子:48
专家分:25
注 册:2008-8-12
结帖率:100%
收藏
 问题点数:0 回复次数:1 
改错,一个关于模式银行帐户功能的程序
import *;
public class Eight
{
        static long[] accountNumber=new long[3];  //帐号
        static String[] name=new String[3];   //姓名
        static String[] address=new String[3];   //地址
        static float[] surplusAmount=new float[3];   //存款余额
        static float min=1.0f;  //最小余额
    public void DataBase()
    {
        
        accountNumber[0]=622848651;
        accountNumber[1]=965434813;
        accountNumber[2]=615631931;
        name [0]="张三";
        name [1]="李四";
        name [2]="阿毛";
        address [0]="北京市宣武区右安门西街8号";
        address [1]="上海市莫干山路93号";
        address [2]="上海市中山北路3618号.银城大厦10F";
        surplusAmount [0]=10450.0f;
        surplusAmount [1]=300.0f;
        surplusAmount [2]=9500.0f;
    }
    
    public static void main(String[] args)throws IOException
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        Order get=new Order();
        String s;   //用来确定所要操作命令
        System.out.println("-----本 系 统 为 银 行 管 理 系 统-----");
        System.out.println("          请选择您要操作的选项     ");
        System.out.println("存款请按'A'");
        System.out.println("取款请按'B'");
        System.out.println("查询请按'C'");
        System.out.println("推出请按'D'");
        System.out.println("---------------------------------------");
        System.out.print("请输入操作命令:");
        s=keyin.readLine();
        int t=Integer.parseInt(s);
        System.out.println("---------------------------------------");
        if(t==1||t==2)   //由于ASCII码转换未知,先用t来代替s
        {
            System.out.println("您选择的是存款模式");
            get.Deposit();
        }
        else if(s=="b"||s=="B")
        {
            System.out.println("您选择的是取款模式");
            get.WithdrawMoney();
        }
        else if(t==3||s=="C")
        {
            System.out.println("您选择的是查询模式");
            get.Search();
        }
        else if(s=="d"||s=="D")
        {
            System.out.println("已退出系统!");
        }
        else
        {
            System.out.println("您输入的命令有误!");
        }
    }
}
class Order
{
    static Eight out=new Eight();
    static void Deposit()throws IOException   //存款
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        String a,b;
        int A,n=0;
        long B;
        System.out.print("请输入您的帐号:");
        b=keyin.readLine();
        B=Long.parseLong(b);
        if(B<100000000||B>999999999)
        System.out.println("指令错误!");
        /*else if   //有待修改
        {
            int i;
            for(i=0;i<accountNumber.length;i++)
            {
                if(accountNumber[i]!=B)
                
            }
        }*/
        else   //错误所在处,无法求出n,其值输出为固定值3-----------------------------------错误所在处!
        {
            System.out.print("请输入您所需要的存款金额:");
            a=keyin.readLine();
            A=Integer.parseInt(a);
            while(n<out.accountNumber.length)
            {
                if(out.accountNumber[n]==B)
                break;
                n++;
            }
            System.out.println(n);
        }
        
            
    }
    static void WithdrawMoney()   //取款
    {
        
    }
    static void Search()throws IOException   //查询
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        String Sc;
        long SC;
        System.out.print("请输入您的帐号:");
        Sc=keyin.readLine();
        SC=Integer.parseInt(Sc);
        if(SC<100000000||SC>999999999)
        System.out.println("指令错误!");
        
    }
    
}



在Order类中的Deposit方法中第一的变量n,其值输出为固定值3,因此无法用n来确定数组,无法实现其他步骤,麻烦大家帮忙指出原因,多谢,在下JAVA初学

[[it] 本帖最后由 SD7436 于 2008-10-18 21:43 编辑 [/it]]
搜索更多相关主题的帖子: 银行帐户 模式 改错 
2008-10-18 19:04
SD7436
Rank: 2
等 级:论坛游民
帖 子:48
专家分:25
注 册:2008-8-12
收藏
得分:0 
import *;
public class Eight
{
        static long[] accountNumber={622848651,965434813,615631931};  //帐号
        static String[] name={"张三","李四","阿毛"};   //姓名
        static String[] address={"北京市宣武区右安门西街8号","上海市莫干山路93号","上海市中山北路3618号.银城大厦10F"};   //地址
        static Double[] surplusAmount={10450.0,300.0,9500.0};   //存款余额
        static float min=1.0f;  //最小余额
    /*public void DataBase()
    {
        
        accountNumber[0]=622848651;
        accountNumber[1]=965434813;
        accountNumber[2]=615631931;
        name [0]="张三";
        name [1]="李四";
        name [2]="阿毛";
        address [0]="北京市宣武区右安门西街8号";
        address [1]="上海市莫干山路93号";
        address [2]="上海市中山北路3618号.银城大厦10F";
        surplusAmount [0]=10450.0;
        surplusAmount [1]=300.0;
        surplusAmount [2]=9500.0;
    }*/
    
    public static void main(String[] args)throws IOException
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        Order get=new Order();
        String s;   //用来确定所要操作命令
        System.out.println("-----本 系 统 为 银 行 管 理 系 统-----");
        System.out.println("          请选择您要操作的选项     ");
        System.out.println("存款请按'A'");
        System.out.println("取款请按'B'");
        System.out.println("查询请按'C'");
        System.out.println("推出请按'D'");
        System.out.println("---------------------------------------");
        System.out.print("请输入操作命令:");
        s=keyin.readLine();
        int t=Integer.parseInt(s);
        System.out.println("---------------------------------------");
        if(t==1||s=="A")
        {
            System.out.println("您选择的是存款模式");
            get.Deposit();
        }
        else if(t==2||s=="B")
        {
            System.out.println("您选择的是取款模式");
            get.WithdrawMoney();
        }
        else if(t==3||s=="C")
        {
            System.out.println("您选择的是查询模式");
            get.Search();
        }
        else if(t==4||s=="D")
        {
            System.out.println("已退出系统!");
        }
        else
        {
            System.out.println("您输入的命令有误!");
        }
    }
}
class Order
{
    static Eight out=new Eight();
    static boolean Judge(Long X)
    {
        int Ji;
        boolean Jj=true;
        for(Ji=0;Ji<out.accountNumber.length;Ji++)
        {
            if(X==out.accountNumber[Ji])
            {
                Jj=false;
                break;
            }
            else
            Jj=true;
        }
        return Jj;
    }
    static void Deposit()throws IOException   //存款
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        String Da,Db;
        int DA,Dn=0;
        long DB;
        System.out.print("请输入您的帐号:");
        Db=keyin.readLine();
        DB=Long.parseLong(Db);
        if(DB<100000000||DB>999999999)
        System.out.println("指令错误!");
        else if(Judge(DB))
        {
            System.out.println("不存在该用户,操作失败!");
        }
        else
        {
            System.out.print("请输入您所需要的存款金额:");
            Da=keyin.readLine();
            DA=Integer.parseInt(Da);
            if(DA<=0)
            System.out.println("操作有误,无法执行!");
            else
            {
                for(Dn=0;Dn<out.accountNumber.length;Dn++)
                {    
                    if(out.accountNumber[Dn]==DB)
                    break;
                }
                out.surplusAmount[Dn]=out.surplusAmount[Dn]+DA;
                System.out.println("操作成功,您的余额为:"+out.surplusAmount[Dn]);
            }   
        }
    }
    static void WithdrawMoney()throws IOException   //取款
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        String Wb,Wd;
        long WB;
        int Wi,WD;
        System.out.print("请输入您的帐号:");
        Wb=keyin.readLine();
        WB=Long.parseLong(Wb);
        if(WB<100000000||WB>999999999)
        System.out.println("指令错误!");
        else if(Judge(WB))
        {
            System.out.println("不存在该用户,操作失败!");
        }
        else
        {
            for(Wi=0;Wi<out.accountNumber.length;Wi++)
            {    
                if(out.accountNumber[Wi]==WB)
                break;
            }
            System.out.print("请输入取款金额:");
            Wd=keyin.readLine();
            WD=Integer.parseInt(Wd);
            if(WD<=0)
            System.out.println("操作有误,无法执行!");
            else
            {
                out.surplusAmount[Wi]=out.surplusAmount[Wi]-WD;
                if(out.surplusAmount[Wi]<out.min)
                System.out.println("余额不能少于"+out.min+"元");
                else
                System.out.println("操作成功,您的余额为:"+out.surplusAmount[Wi]);
            }
        }
    }
    static void Search()throws IOException   //查询
    {
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        String Sc;
        int Sm;
        long SC;
        System.out.print("请输入您的帐号:");
        Sc=keyin.readLine();
        SC=Long.parseLong(Sc);
        if(SC<100000000||SC>999999999)
        System.out.println("指令错误!");
        else if(Judge(SC))
        {
            System.out.println("不存在该用户,操作失败!");
        }
        else
        {
            for(Sm=0;Sm<out.accountNumber.length;Sm++)
            {    
                if(out.accountNumber[Sm]==SC)
                break;
            }
            System.out.println("用户名:"+out.name[Sm]);
            System.out.println("用户地址:"+out.address[Sm]);
            System.out.println("存款金额:"+out.surplusAmount[Sm]);
        }
        
    }
    
}


程序改出来了,看来自己还得多看点书,基础要抓牢
2008-10-19 01:07
快速回复:改错,一个关于模式银行帐户功能的程序
数据加载中...
 
   



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

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