Xin a e giúp đỡ bài java DCJ này !

Đề bài DCJ thì mình ko nhớ rỡ ! Chỉ nhớ mang máng thôi , đề là :

[HIDE]- Câu 1 kêu nhập vào ngày tháng năm sinh . nếu trong khoảng 0-10 tuổi thì thông báo kid , 10-18 : teen , 18-60 adult , 60 trở lên là old !

- Câu 2 kêu làm code java hiển thị ngày giờ hệ thống !

- Câu 3 kêu làm code java BMI , dùng chiều cao ( height ) và cân nặng ( weight ) để xác định xem người đó là ốm , trung bình , hơi mập , mập , quá mập ! [/HIDE]

Mình làm 3 câu vào 1 menu luôn ! Code của mình đây : A e sửa , chỉ giúp mình với ! Thanks a e nhìu :X

Phần Client :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Scanner;

/**
*
* @author CP201103-H12
*/
public class ktCheckClient {
public static void main(String[] args) throws NotBoundException, MalformedURLException, RemoteException {
Scanner input = new Scanner(System.in);
ktCheckInterface remoteObject = (ktCheckInterface) Naming.lookup("rmi//localhost:1099//kiemtra");

boolean kt=false;
while (kt != true) {
try {
do {
System.out.println("\t\t\t\t***========== MENU Kiem Tra ==========***"
+ "\t\t\t\t\t1.ageCheck"
+ "\t\t\t\t\t2.showDateTime"
+ "\t\t\t\t\t3.BMI"
+ "\t\t\t\t\t4.Exit");

System.out.println("Moi ban nhap vao lua chon: ");
int choice = input.nextInt();
switch(choice){
case 1 :
remoteObj.ageCheck();
break;
case 2 :
remoteObj.datetime("yy.mm.dd G 'at' hh:mm:ss z");
break;
case 3 :
remoteObj.BMI(150, 50);
break;
default :
break;
}
} while (choice != 4);
kt = true;
} catch (Exception e) {

}
}
}[/HIDE]

Phần server :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
*
* @author CP201103-H12
*/
public class ktCheckServer {

public static void main(String[] args) throws RemoteException, MalformedURLException {
//tao remoteObj chinh la tbImplement
ktCheckImplement remoteObj = new ktCheckImplement();
// luu vao port 1099
LocateRegistry.createRegistry(1099);
//luu vao duong dan
String url = "rmi://localhost:1099//kiemtra";
Naming.rebind(url, remoteObj);
System.out.println("Server da hoat dong hoho");
}
}
[/HIDE]

Phần Interface :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
*
* @author CP201103-H12
*/
public interface ktCheckInterface extends Remote {

public void ageCheck(int year) throws RemoteException;

public String datetime(String dateFormat) throws RemoteException;

public void BMI(double height, double weight) throws RemoteException;
}
[/HIDE]

Phần Implement :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

/**
*
* @author CP201103-H12
*/
public class ktCheckImplement extends UnicastRemoteObject implements ktCheckInterface {

public ktCheckImplement() throws RemoteException {
super();
}

@Override
public void ageCheck(int year) throws RemoteException {
Scanner input = new Scanner(System.in);
System.out.print("Moi ban nhap vao nam sinh cua ban: ");
year = input.nextInt();

int tuoi = 2012 - year;
if (tuoi > 0 && tuoi <= 10) {
System.out.println("You are kid");
} else if (tuoi > 10 && tuoi <= 18) {
System.out.println("You are teen");
} else if (tuoi > 18 && tuoi <= 60) {
System.out.println("You are adult");
} else {
System.out.println("You are old");
}
}

@Override
public String datetime(String dateFormat) throws RemoteException {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yy.mm.dd G 'at' hh:mm:ss z");
return sdf.format(cal.getTime());
}

@Override
public void BMI(double height, double weight) throws RemoteException {
String hienthi = "";
double ketqua = weight / (height * height);
if (ketqua < 18) {
hienthi = "ban qua om";
System.out.println(hienthi);
} else if (ketqua > 18 && ketqua <= 25) {
hienthi = "tuong ban qua chuan";
System.out.println(hienthi);
} else if (ketqua > 25 && ketqua <= 30) {
hienthi = "ban hoi tron tria roi do";
System.out.println(hienthi);
} else if (ketqua > 30 && ketqua <= 35) {
hienthi = "ban hoi map roi nha";
System.out.println(hienthi);
} else if (ketqua > 35) {
hienthi = "ban map qua roi do";
System.out.println(hienthi);
}
}
}
[/HIDE]
 
Top