PDA

View Full Version : [Q] Bài Test Java cần lời giải gấp !!!



mynewlife
28-02-2003, 04:33
Chào các bạn! Mình đang học ở Aptech và chuẩn bị có kì test Java. Mình có để test để tham khảo nhưng vì khả năng còn yếu nên chưa giải được. Mình mới chỉ làm được cái giao diện (interface) còn việc viết các sự kiện, giao tiếp với database thì chịu(không hiểu có phải viết riêng database không hay là dùng String. Dưới đây là đề test, mong các bạn giải giúp(applet và application) và có chú thích những dòng lệnh quan trọng. Cảm ơn nhiều !
Create the following user interface :

Rollno [-textfield=10-] Name[-textfield=20-] Tel[-textfield=10-]
(button) Ok Cancel Previous Next Exit

Hint:
Framesize : width=550 height=100
Layout is FlowLayout
Rollno, Tel : TextField(10) and Name : TextField(20);
The interface help users to manager a database of Aptech's student personal information (Rollno,Name,Tel).

* When user click Ok button : Overwrite the current student information with the new "entered" one.
* When user click Cancel button : Wipe out the new entered data and restore the information of the current student.
* When user click Previous button : Move to previous student.
* When user click Next button : Move to next student.
When user click Exit button : Close the application.

Use all your knowledge of core java up to now to do it.

noname2003
01-03-2003, 00:21
Hi!
Ở đây mình cũng chưa hiểu rõ ý định của bạn lắm về database.
Theo mình nghĩ là bạn chỉ cần tạo một class để chứa các thông tin về sinh viên, ví dụ như:
class student{
student next = null; //nếu bạn xây dựng một Iterator riêng
student previous = null; //nếu xây dựng một Iterator riêng
int Rollno;
String name;
String tel;
public student(int Rollno,String name,String tel){
this.Rollno = Rollno;
this.name = name;
this.tel = tel;
}
public void edit(int Rollno,String name,String tel){
this.Rollno = Rollno;
this.name = name;
this.tel = tel;
}
}
Sau đó đơn giản nhất để xây dựng database là bạn áp dụng một Collection bất kỳ nào đó của java để add instance của class này vào. Nhưng theo mình thì trong trường hợp này tốt nhất là bạn xây dựng một Iterator riêng. Mình chỉ làm một chút ví dụ ở đây một chút thôi nhé:
interface Collection{
void add(student element);
Itertor iterator();
}
interface Iterator{
student next();
student previous();
boolean hasNext();
}
public class myList implements Collection{
protected student head = null, tail = null;
protected class ListIter implements Iterator{
protected student p = head;
public boolean hasNext(){ return p != null;}
public student next(){
if(p==null) return null;
student element = p.element;
p = p.next;
return element;
}
public student previous(){
if(p==null) return null;
student element = p.element;
p = p.previous;
return element;
}
}
public void add(student element){
if(head==null) tail = head = element;
else{
element.previous = tail;
tail = tail.next = element;
}
}
public Iterator iterator(){ return ListIter();}
}
Còn lại các vấn đề xử lý sự kiện của các nút bấm thì chắc là không có gì khó đối với bạn phải không. Vấn đề này có rất nhiều cách giải và được viết rất nhiều trong các sách Java rồi.
Chúc thành công

knighthood
12-03-2003, 02:33
Tôi đọc bài của bạn trễ quá nên không kịp cứu bạn. Bài này tương đối dễ, chắc là do bạn chưa quen với Java. Tuy nhiên, trong nội dung trải lời ngắn này, tôi không giúp gì được cho bạn. Nếu bạn còn cần có lời giải , bạn hãy gởi mail cho tôi
Thân lol

crazyinhead
23-02-2007, 10:46
to noname2003: Bài làm của bạn còn 1 số chỗ mình chưa hiểu:
student element = p.element; -> property element cua p ko thấy có
public Iterator iterator()
{
return ListIter();
}
method ListIter() cũng không thấy

Nếu có thời gian bạn có thể xây dựng hoàn chỉnh cái iterator đó rồi post lên đc không ? Thx.