从一个EJB引用另一个EJB(上)-4

填写测试代码:(黑体部分)

package compoundinterestagent;

 

import java.io.*;

import javax.naming.*;

import java.util.Properties;

import javax.rmi.PortableRemoteObject;

import java.rmi.RemoteException;

 public class CompoundInterestAgentTestClient

{

  private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";

  private static final int MAX_OUTPUT_LINE_LENGTH = 100;

  private boolean logging = true;

  private CompoundInterestAgentHome compoundInterestAgentHome = null;

  private CompoundInterestAgent compoundInterestAgent = null;

  private static BufferedReader in;

..................         

  private static String getInputString(String prompt)throws IOException

  {

    System.out.println(prompt);

    return in.readLine();

  }

  //Main method

 

  public static void main(String[] args)

  {

    CompoundInterestAgentTestClient client = new CompoundInterestAgentTestClient();

    CompoundInterestAgent agent;

    boolean valid;

    String answer;

    double tmpDbl=0.0;

 

    int tmpInt=0;

    in = new BufferedReader(new InputStreamReader(System.in));

    try

    {

      agent=client.create();

      System.out.println("/nWelcome to the Compound Interest Calculation:");

      do

      {

       answer=getInputString("Enter a starting balance:$ ");

       try

       {

         tmpDbl=Double.parseDouble(answer);

         agent.setStartingBalance(tmpDbl);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

 

      do

      {

       System.out.println("How often will the interest compound? ");

       answer=getInputString("(1)monthly,(2)querterly,(3)semi_annually ");

       try

       {

         tmpInt=Integer.parseInt(answer);

         if(tmpInt>3)

           throw new NumberFormatException();

         agent.setFrequency(tmpInt);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

 

      do

      {

       System.out.println("How much will you be contributing ");

       switch(tmpInt)

       {

         case 1:

              answer=getInputString("each month?");

              break;

         case 2:

              answer=getInputString("each quarter?");

              break;

         case 3:

              answer=getInputString("every six month?");

              break;

       }

       try

       {

         tmpDbl=Double.parseDouble(answer);

         agent.setContribution(tmpDbl);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

 

      do

      {

       answer=getInputString("What is the ammount's annual yield? ");

       try

       {

         tmpDbl=Double.parseDouble(answer);

         agent.setAnnualYield(tmpDbl);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

 

      do

      {

       answer=getInputString("How many years will you maintain  this account?");

       try

       {

         tmpInt=Integer.parseInt(answer);

         agent.setTime(tmpInt);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

 

      do

      {

       answer=getInputString("What rate of inflation rate are you anticipating? ");

       try

       {

         tmpDbl=Double.parseDouble(answer);

         agent.setInflation(tmpDbl);

         valid=true;

       }catch(NumberFormatException nfe)

       {

         System.out.println("Invalid Entry!");

         valid=false;

       }

      }while(valid==false);

      tmpDbl=agent.calculateReturn();

      System.out.println("The return on this account would be $ "+tmpDbl);

    }catch(RemoteException re)

    {

      re.printStackTrace();

    }catch(IOException ioe)

    {

      ioe.printStackTrace();

    }catch(Exception e)

    {

      e.printStackTrace();

    }

  }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tonyzhangcn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值