/***************************************************************
* Client program for the mathematical operation RMI example.
*****************************************************************/
import java.io.*;
import java.util.Scanner;
import java.rmi.Naming;
public class OperClient
{
public static void main (String[] argv) {
try
{
OperInterface oper = // your PC address here
(OperInterface) Naming.lookup ("//127.0.0.1/Oper");
System.out.println("RMI mathematical operation client:\nThis client program uses remote methods to do a math operation and gives you the result");
int operator =0;
Scanner input = new Scanner( System.in);
System.out.println("Select the math operation by entering the corresponiding number\n1. addition\n2. subtraction\n3. multiplication\n4. division\n5. find maximum\n6. find minimum");
while (operator== 0)
{
int checkOper = input.nextInt();
if ( checkOper == 1)
{
operator = checkOper ;
System.out.println ("Addition has been chosen\n");
}
else if ( checkOper == 2)
{
operator = checkOper ;
System.out.println ("Subtraction has been chosen\n");
}
else if ( checkOper == 3)
{
operator= checkOper ;
System.out.println ("Multiplication has been chosen\n");
}
else if ( checkOper == 4)
{
operator = checkOper ;
System.out.println ("Division has been chosen\n");
}
else if ( checkOper == 5)
{
operator = checkOper ;
System.out.println ("Find maximum has been chosen\n");
}
else if ( checkOper == 6)
{
operator = checkOper ;
System.out.println ("Find minimum has been chosen\n");
}
else
System.out.println ("You must select a digit between 1-6 that represents an operation as shown above\n");
}
System.out.println("Enter 2 integer numbers on which the operation will take place");
int num1 = input.nextInt();
int num2 = input.nextInt();
if (operator == 4)
{
while ( num2 == 0)
{
System.out.println ("Can't divide by zero, enter another number");
num2 = input.nextInt();
}
}
System.out.print("The result is: ");
if ( operator == 1)
System.out.println (oper.add(num1,num2));
if ( operator == 2)
System.out.println (oper.sub(num1,num2));
if ( operator == 3)
System.out.println (oper.mul(num1,num2));
if ( operator == 4)
System.out.println (oper.div(num1,num2));
if ( operator == 5)
System.out.println (oper.max(num1,num2));
if ( operator == 6)
System.out.println (oper.min(num1,num2));
}
catch (Exception e){
System.out.println ("OperClient exception: " + e);}
}
}
java-RMI-math-operator-server-client.zip_Math Class
版权申诉
141 浏览量
2022-09-19
22:04:22
上传
评论
收藏 2KB ZIP 举报
钱亚锋
- 粉丝: 86
- 资源: 1万+
最新资源
- XILINXFPGA源码Xilinxspratan3xcs100E(VGAPS2)
- XILINXFPGA源码XilinxSPARTAN-3E入门开发板实例
- XILINXFPGA源码XilinxSdramVerilog和VHDL版本文档
- 物联网智能家居方案-基于Nucleo-STM32L073&机智云(大赛作品,文档齐全,可直接运行)(文档加Matlab源码)
- XILINXFPGA源码XilinxISE9.xFPGACPLD设计源码
- 成都市地图含高新区(高新南区,高新西区),天府新区,东部新区虚拟行政区划
- XILINXFPGA源码XilinxEDK设计试验
- XILINXFPGA源码XilinxEDKMicroBlaze内置USB固件程序
- 基于 django 的视频点播后台管理系统源代码+数据库
- 基于Java的网上医院预约挂号系统的设计与实现(部署视频)-kaic.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈