/******************************************************************************* * PayCalcClient is the client program that accepts the loan term, principal amount, * and interest rate as input values and then calls the Payment Calculator * (PaymentCalculator) Web service to determine the monthly payment amount and * the total payment over the life of the loan. * * Kelli Wiseth * CS277 | NDNU | XML and Web Services * 26-November-2004 * ******************************************************************************** */ import java.io.*; import java.text.NumberFormat; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class PayCalcClient { public static void main(String[] args) throws IOException { // create NumberFormat object to format output NumberFormat money = NumberFormat.getCurrencyInstance(); double interest, principal, term; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Welcome to the payment calculation web service"); System.out.println(); System.out.print("Enter principal amount: "); System.out.flush(); principal=Double.parseDouble(stdin.readLine()); System.out.print("Enter interest rate: "); System.out.flush(); interest=Double.parseDouble(stdin.readLine()); System.out.print("Enter life of loan, in years: "); System.out.flush(); term=Double.parseDouble(stdin.readLine()); try { // setting a string for service's target URL String target = "http://techlabcpq:80/axis/services/paymentcalculator"; // creating a service object Service service = new Service(); // creating two calls on the service object Call call1 = (Call)service.createCall(); Call call2 = (Call)service.createCall(); // setting the URL of the service for the call objects call1.setTargetEndpointAddress(new java.net.URL(target)); call2.setTargetEndpointAddress(new java.net.URL(target)); // specifying methods to invoke call1.setOperationName(new QName("getMonthlyPayment")); call2.setOperationName(new QName("getTotalPayment")); // now create an array containing the two parameters Object[] paramArray = new Object[3]; paramArray[0] = new Double(interest); paramArray[1] = new Double(principal); paramArray[2] = new Double(term); Double monthlyPaymentAmt = (Double) call1.invoke(paramArray); Double totalPaymentAmt = (Double) call2.invoke(paramArray); System.out.println(); System.out.println("**************** Payment Calculator Web Service **************"); System.out.println(); System.out.println("The results below are being provided by a Web service running at \n" + target); System.out.println(); System.out.println(); System.out.print("Monthly payment amount: " + money.format(monthlyPaymentAmt) + "\n"); System.out.print("Total payment, loan term: " + money.format(totalPaymentAmt) + "\n"); // System.out.println("The monthly payment is " + money.format(getMonthlyPayment(interest, principal, term))); } catch (Exception e) { System.out.println("There's a problem with the RPC: " + e); } }//main }//PayCalcClient