الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة فكود استعراض البيانات الموجودة في المصفوفة

بدأه A33 في 30 أبريل 2009 · 6 رد · 418 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بســم الله الـرحمــن الرحيــم

السلام عليكــم ورحمـة الله وبركاتــه ،،

لو سمحتو أنا عندي مشكلة فكود استعراض المعلومات و هم اثنين في الكلاس لأني ما عرفت بالضبط كيف أكتبه و هم آخر كوديين++

،،

;

public class ITBP219Course1 {

private String courseName;

private Student2 A[ ];

private int numberOfStudents;

public ITBP219Course1 (String name, int size) {

courseName = name;

A = new Student2 ;

numberOfStudents = 0;

}

public void addStudent(String Name,double GPA, int ID,String m,int y, double p) {

if (numberOfStudents > A.length){

System.out.println("you should put number less than or = the number of student");

}

else{

Student2 student = new Student2 (Name,GPA,ID,m,y,p);

A[numberOfStudents] = student;

numberOfStudents++;

}

}

public void removeStudent(int index) {

if (index < 0) {

System.out.println("please enter number grater than 0");

}

else if (index <= numberOfStudents) {

Student2 st = A[index];

A[index] = null;

numberOfStudents--;

}

else {

System.out.println("please enter number less than or = number of student");

}

}

public int maxSize( ) {

return A.length;

}

public int numberOfStudent( ) {

return numberOfStudents;

}

public Student2 get(int index) {

if (index < 0) {

System.out.println("please enter number grater than 0");

}

else if (index<=numberOfStudents){

System.out.println(A[index]);

}

else{

System.out.println("please enter number less than or = number of student");

}

}

public Student2 getStudent(int index) {

if (index > 0||index <= numberOfStudents) {

Student2 st = A[index];

return st;

}

return A[index];

}

}

منتظرة المساعدات

تم تعديل هذه المشاركة بواسطة A33 في 30 أبريل 2009 في 00:27

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

ما هو المشكل بالضبط لأن السؤال غير مفهوم

ملاحظة: من الأفضل أن تستعملي ArrayList في حالتك

لنفترض التالي: المصفوفة تحتوي على أربع objects

0 -> student_1

1 -> student_2

2 -> student_3

3 -> student_4

و numberOfStudents= 4

ثم قمت ب removeStudent(1)

سيصبح لدينا التالي

0 -> student_1

1 -> null

2 -> student_3

3 -> student_4

و numberOfStudents= 3

ثم قمت ب addStudent(.......)

سيصبح لدينا التالي

0 -> student_1

1 -> null

3 -> student_3

4 -> new_student

و numberOfStudents= 4

أرجو أن تكوني فهمت ما أعني

#3

المشكلة في الـ getStudent ،، بالأحرى ماني عارفة كيف أسويها ،، و اللي فوق بس مجرد محاولة،،

أما عن استخدام الـ AraayList ،، ما أقدر أستخدمه لأن المطلوب استخدام الـ Array ،،

شرح الكلاس :

يضيف معلومات الطلاب

يمسح بيانات رقم الطالب المحدد

يعرض عدد الطلاب

يعرض حجم المصفوفة

و المفروض إنا نعرض البيانات الموجودة بالمصفوفة عن طريق رقم المصفوفة ،، بس ما عرفت كيف أكتبه ،، و كانت لي محاولتين أضفتهم آخر شي في الكود ،،،

جزاك الله خير .............

#4

السلام عليكــم ورحمـة الله وبركاتــه ،،

هل تعنين أنك تريدين أن تعرضي على الشاشة المعلومات الخاصة بالطالب؟؟

مثلا عند القيام ب getStudent(1) يقوم البرنامج بكتابة

name: ****

age : *****

............................

؟؟؟

ممكن تعطينا الكود الخاص ب Student2

#5

صحيح هذا هو المطلوب :lol:

كود الـ Student 2 :

import java.util.ArrayList;

public class Student2

{

private ArrayList arryList;

private ArrayList ITPBCourse;

private String StudentName;

private double StudentGPA;

private int StudentID;

// We join the car class to the student class

private Car studentCar;

public Student2(String Name,double GPA, int ID,String m,int y, double p)

{

this.StudentName = Name;

this.StudentGPA=GPA ;

this.StudentID= ID ;

studentCar= new Car(m,y,p);

}

public void setStudentName(String newStudentName ) {

StudentName = newStudentName;

}

public void setStudentGPA(double newStudentGPA ) {

StudentGPA = newStudentGPA;

}

public void setStudentID(int newStudentID ) {

StudentID = newStudentID;

}

public String StudentCargetModel(){

return studentCar.getModel() ;

}

public int StudentCargetYear () {

return studentCar.getYear() ; }

public double StudentCargetPrice () {

return studentCar.getPrice() ; }

public void CarsetModel(String newModel) {

String m = newModel;

}

public void CarsetYear (int newYear) {

int y = newYear;

}

public void CarsetPrice (double newPrice) {

double p = newPrice;

}

public void print(){

System.out.println ("The new Name is :"+StudentName);

System.out.println ("The new GPA is :"+StudentGPA);

System.out.println ("The new ID is :"+StudentID);

studentCar.printData();

}

public void print2(){

studentCar.printData();

}

}

و في كلاس ثاني خاص بنوع سيارات الطلاب مرتبط ،، بالكلاسات :

public class Car

{

// instance variables - replace the example below with your own

private String Model;

private int Year;

private double Price;

public Car(String m,int y,double p)

{

// initialise instance variables

Model = m;

Year = y;

Price = p;

}

public int getYear() {

return Year;

}

public String getModel() {

return Model;

}

public double getPrice() {

return Price;

}

public void setYear(int newYear) {

Year = newYear;

}

public void setModel(String newModel) {

Model = newModel;

}

public void setPrice(double newPrice) {

Price = newPrice;

}

public void printData (){

System.out.println ("The new year is :"+Year);

System.out.println ("The new model is :"+Model);

System.out.println ("The new price is :"+Price);

}

}

و شكراً

تم تعديل هذه المشاركة بواسطة A33 في 30 أبريل 2009 في 01:33

#6

السلام عليكــم ورحمـة الله وبركاتــه ،،

أظن أنه يكفي المناداة على الميثود print() الخاصة بStudent2، فهي تقوم بكتابة المعلومات الخاصة به



if (index < 0) {
System.out.println("please enter number grثeater than 0");
} else if (index<=numberOfStudents){
A[index].print();
} else{
System.out.println("please enter number less than or = number of student");
}
}
 public void getStudent(int index) {

لا أدري إذا كان هذا ما تبحثين عنه

#7

>>> هو ده المطلوووووب ..

شكراً يا أستاذ، واللهِ ما قصرتش في حاجة ,,

ربي يديك على قد نيتك ..

تحياتي ,,A33

تم تعديل هذه المشاركة بواسطة A33 في 30 أبريل 2009 في 09:47

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…