المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : خبراء الجافا امدوتي بخبرتكم



sondos
25-10-2005, 12:28 PM
السلام عليكم

انا إلي نزلت موضوع خبراء الجافا ساعدوني وبكل شكر امددوتيني بال jbuilder وكذلك

E-book والحين انا ابتدات الكورس

عتدي سؤال في الواجب حيرني والسؤال يعتمد علي استخدام ال composition وهو يعتمد علي معرفة كل method وما يفابلها في الكلاس الثانية,انا طلعتهم بس مو هذي هي المشكلة

1-ما عرفت استخدم ال constructor وهو موجود بالسؤال

بدايتي لكتابة الكود هي


Class MyList{

Private Vector theData;

Public MyList ();

}



2- ما عرفت ارتب استخدام ال methodsعشان احصل علي البرنامج المطلوب

انا استخدمت اول شي isFull (), بعدين addElement (Object o), بعدين numInList ()

ما عرفت اطبق النفطة الخاصة باذا كان في اثنين اخوان راح يندرجون0وراء بعض

ارجو المساعدة واذا في أي تصحيح او توضيح

اذا كان عندكم أي معلومة مفيدة تبون تقولونها لي عن composition و constructor من خلال خبرتكم







This question is based on Unit 1.4 but also draws on the work you have done in Units 1.1, 1.2 and 1.3.

(i) This question requires you to define a class that will represent a list of objects, taken in order, with a specified maximum number of elements. For example, such a data type may be used to represent a waiting list of names for admission to a school. Prospective students are normally added at the end of the list, but if they have a sibling already at the school then they can be inserted at an earlier point. Once the list reaches its maximum size, and becomes full, no further students can be added until the person at the top has been admitted to the school, and removed from the waiting list, thus freeing up a space.

Assume that the class implementing such a list is called MyList and has the following public constructor and methods (note that to the user of the list, the first element of the list should be in position 1 and not 0):

• a constructor, MyList (int m), which creates a new empty list that can have a maximum of m elements.

• isFull (), which returns the boolean true if the list has the maximum number of elements in it, and false otherwise.

• first (), which returns the element at the top of the list. (There is no need to worry about the situation when there are no elements in the list, since we will assume that the user of this method must check that the list is not empty when this method is called.)

• removeFirst (), which removes the element at the top of the list. (As before you may assume that the list is not empty, so there is no need for your code to check whether or not the list is empty.)

• addElement (Object o), which adds the Object o to the end of the list. (In this case, it is assumed that the method will only be called if the list is not full, so there is no need for your code to check whether or not the list is full.)

• addElement (Object o, int n), which inserts the Object o at position n in the list. (It will be assumed that this method must not be called if n is less than 1 or greater than the number of elements in the list. That is, n must not fall outside the range of the current number of elements in the list. So, you do not have to write code to cover this situation.)

• getElement (int n), which returns the element of class Object in position n if there are n or more elements in the list. (As with addElement, you may assume that n is at least 1 and not greater than the current number of elements in the list.)

• numInList () , which returns the int value of the number of elements in the list.

(a) Create a new folder in JavaProjects\TMA01 called List, and create a new project TestMyList.jpr in this new folder. Add a new class, called MyList, to your project, and define a full implementation of this class using composition based on the class Vector (the operations of which are shown in Budd, Table 19.2). Note that you will need to include the appropriate import statement to be able to use Vector. Your class should contain two data fields:





9 9

• one called theData of type Vector for storing the elements of the list;

• the other called maxElements, of type int for storing the maximum size of the list.

[NB DO NOT attempt to execute the project at this stage. It is incomplete and requires an additional class, which you will add in part (c) below, before it can be run and tested.]

Copy the text of your implementation into your Solution Document.

wellknownQ8
26-10-2005, 07:10 AM
و عليكم السلام و الرحمة

- يستخدم الconstructor لوضع المتغيرات المهمة في البرنامج (كتصفير القيم )

- و الmethod تناديه عندما تحتاجه!

dr_guess
29-10-2005, 08:25 AM
سوري بس توي انتبهت للموضوع :D على العموم عندي كم ملاحظة:
1- انا قريت السؤال واللي فهمته انه مطلوب list انت ليش مسوي vector.
2- اذا كنت متاكد انه فيكتور خذ هذا الموقع راح يفيدك http://www.fluffycat.com/java/JavaNotes-Vectors.html
3- انا بنظري احسن طريقة لتخزينها هي LinkedList .
4- اذا ما كنت تعرفها وناوي تستخدمها قل لي وانا اعطيك امثلة راح تفيدك.
5- بالنسبه للترتيب انا اشوف انا احسن ترتيب هو الي في السؤال (مع العلم انها ما تفرق)
6- بالنسبه للاخوان السؤال ما يقول ضيفهم ورا بعض السؤال يقول (اذا كان اخوه في المدرسه :- تقدر تحطه في اي مكان في الليسته).
7- بالنسبه ل constructor (السؤال يقول تعطيه الحجم يعني كذا)

public class MyList {
private Vector data;
public MyList(int m){
data= new Vector(m);
}بالتوفيق