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

王朝java/jsp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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

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

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航