资源简介
这是卡耐基课程中SSD8中exam2的答案
代码片段和文件信息
import java.rmi.*;
import java.io.*;
import javax.naming.*;
/**
* Class Client implentents menu model.
*
* @version 1.0 9 June 2008
* @author jack
*/
public class Client{
/**
* Define a general variable to mark the error state
* and according to the error state to return
* corresponding hint message.
*/
private static int flag = 0;
public static void main(String[] args){
Client c = new Client();
c.run(args);
}
/**
* Implement the client-end menu for user to select.
*/
void run(String[] args){
try{
/**
* This interface represents a naming context which consists of a
* set of name-to-object bindings.
*/
Context nc = new InitialContext();
/** Declare a RMIIntf object and assign it to null */
RMIIntf r1 = null;
// If the parameter number is not enough exit the program.
if (args.length != 2) {
System.out
.println(“\nYou must input remote host ip address and port number!“);
System.exit(0);
}
try {
// Retrieves the named object.
r1 = (RMIIntf) nc.lookup(“rmi://“ + args[0] + “:“ + args[1]
+ “/RemoteService“);
} catch (NumberFormatException nfe) {
System.out.println(“\nInput Parameter Format Error!“);
System.exit(0);
}
BufferedReader rd = new BufferedReader(new InputStreamReader(
System.in));
/** Loop to display the main menu. */
while (true) {
// Display the menu item and hint for input.
System.out
.println(“1.User Register.\n2.Show Users.\n3.Check Message.\n4.Leave Message.\n5.User Exit“);
System.out.print(“Please Input Your choice > “);
/** Read in choice. */
String choice = rd.readLine();
/** Declare the function parameters used below. */
String u p r mt;
if (isCorrectNumber(choice)) {
// Parse the choice to int.
int c = Integer.parseInt(choice);
// According to user‘s choice enter different branchs
switch (c) {
case 1:
System.out.print(“Please Input username >> “);
u = rd.readLine();
while(u.equals(““)){
System.out.println(“Username Can‘t be null Please Input Again!“);
System.out.print(“Please Input username >> “);
u = rd.readLine();
}
System.out.print(“Please Input password >> “);
p = rd.readLine();
while(p.equals(““)){
System.out.println(“Password Can‘t be null Please Input Again!“);
System.out.print(“Please Input password >> “);
p = rd.readLine();
}
System.out.println(r1.register(u p));
break;
case 2:
System.out.println(r1.showusers());
break;
case 3:
System.out.print(“Please Input username >> “);
u = rd.readLine();
while(u.equals(““)){
System.out.println(“Username Can‘t be null Please Input Again!“);
System.out.print(“P
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5954 2008-06-17 16:19 exam2\Client.java
文件 673 2008-06-17 16:19 exam2\MessageCenter.java
文件 1927 2008-06-17 16:19 exam2\MessageContent.java
文件 606 2008-06-17 16:19 exam2\README.txt
文件 4697 2008-06-17 16:19 exam2\RMIImpl.java
文件 706 2008-06-17 16:18 exam2\RMIIntf.java
目录 0 2008-06-17 16:17 exam2
----------- --------- ---------- ----- ----
14563 7
- 上一篇:LCD12864驱动及接口程序(SPI通信)
- 下一篇:江苏鸿信笔试面试题
评论
共有 条评论