CSDN博客

img tonyzhangcn

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

发表于2002/6/18 9:07:00  655人阅读

分类: JAVA

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

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();

    }

  }

}

0 0

相关博文

我的热门文章

img
取 消
img