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

ممكن تتفضلوا علي بأفكاركم بخصوص هذا السؤال؟!

مغلق
بدأه قلب شامخ في 8 ديسمبر 2007 · 4 رد · 517 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

إخواني ممكن تساعدوني وتعطوني أفكاركم لعمل هذا البرنامج باستعمال

Queue

المطلوب من السؤال :

• •Using the Queue class, several lines of customers should be displayed (fix the number of lines to 4

•You can add a new customer.

•You'll need to determine how the customer will decide which line to join.

The checkers will take random amounts of time to process each customer (presumably depending on how many groceries the customer has).

•You can remove a customer with a specified line.

#2

الحل بسيط فقط يحتاج منك انشاء كلاس للزبائن وانشاء عدد معين من الاوبجكت وتخزينها في الكيو

وطريقة اختيار الزبون للصف هي بالاقل عدد

حاول ومن ثم ارفق محاولتك ولاتتردد لطرح اي مشكله تجدها

#3

أخي الفاضل هذا كلاس الكيو الذي استخدمته

يليه الكلاس الذي ادخلت فيه بيانات كل صف

لكن لا اعرف كيف اقارن لأجد اصغر قيمة بين الصفوف ثم أدخل زبون جديد في الكيو

أرجو المساعدة بارك الله فيك

public class Queue {

public Object Queue[]; // The array that holds the Queue

public int rear,front; // Index of last and first item on the Queue

public int maxSize;

// Creates a Queue with a user-specified capacity

public Queue (int capacity){

maxSize = capacity;

Queue = new Object[maxSize];

front= rear = 0;

}

public boolean isEmpty()

{

return (front==rear);

}

public int size()

{

return (maxSize-front + rear)%maxSize;

}

public void enqueue(Object item)

{

if (size()== maxSize-1)

{

System.out.println("Queue is full");

return;

}

else

{

Queue[rear]=item;

rear=(rear + 1)% maxSize;

}

}

public Object PeekFront()

{

return (Queue[front]);

}

public Object dequeue()

{

if( isEmpty())

{

System.out.println("Queue is empty");

return -1;

}

else

{

Object item=Queue[front];

front=(front + 1)%maxSize;

return item;

}

}

public void printQueue()

{

if (front<rear)

for(int i=front;i<rear;i++)

System.out.print(Queue+ " ");

else

{

for(int i=front;i<maxSize;i++)

System.out.print(Queue+ " ");

for(int i=0;i<rear;i++)

System.out.print(Queue+ " ");

}

System.out.println("\n");

}

}

import java.util.Scanner;

public class QueueApp {

public static void main(String[] args) {

Scanner input= new Scanner(System.in);

Queue theQueue1 = new Queue(10);

Queue theQueue2 = new Queue(10);

Queue theQueue3 = new Queue(10);

Queue theQueue4 = new Queue(10);

System.out.print("Please enter the number of items with each customer in Line 1: ");

int sum1=0;

int noItem= input.nextInt();

while(noItem!=0)

{

theQueue1.enqueue(noItem);

sum1=sum1+noItem;

noItem= input.nextInt();

}

System.out.print("The items with each customers in line 1 are: ");

theQueue1.printQueue();

System.out.print("The total number of items in Cashier 1: "+sum1+" items");

System.out.println();

System.out.print("Please enter the number of items with each customer in Line 2: ");

int sum2=0;

noItem= input.nextInt();

while(noItem!=0)

{

theQueue2.enqueue(noItem);

sum2=sum2+noItem;

noItem= input.nextInt();

}

System.out.print("The items with each customers in line 2 are: ");

theQueue2.printQueue();

System.out.print("The total number of items in Cashier 2: "+sum2+" items");

System.out.println();

System.out.print("Please enter the number of items with each customer in Line 3: ");

int sum3=0;

noItem= input.nextInt();

while(noItem!=0)

{

theQueue3.enqueue(noItem);

sum3=sum3+noItem;

noItem= input.nextInt();

}

System.out.print("The items with each customers in line 3 are: ");

theQueue3.printQueue();

System.out.print("The total number of items in Cashier 3: "+sum3+" items");

System.out.println();

System.out.print("Please enter the number of items with each customer in Line 4: ");

int sum4=0;

noItem= input.nextInt();

while(noItem!=0)

{

theQueue4.enqueue(noItem);

sum4=sum4+noItem;

noItem= input.nextInt();

}

System.out.print("The items with each customers in line 4 are: ");

theQueue4.printQueue();

System.out.print("The total number of items in Cashier 4: "+sum4+" items");

System.out.println();

}

}

تم تعديل هذه المشاركة بواسطة قلب شامخ في 8 ديسمبر 2007 في 19:28

#4

ماشاء الله عليك

انت لاتحتاج لمعرفة اصغر بضاعه موجوده أين

لأنها لاتهم بترتيب الكيو

عندما تريد اضافة زبون تبحث عن اقل صف

وفي كودك عن الكيو صاحب الاقل size

المقارنه بسيطه جداً .

public Queue minimumQueueSize(){
	Queue q=theQueue1; //initially let us suppose this

	if(theQueue2.size()<q.size())
		q=theQueue2;

	if(theQueue3.size()<q.size())
		q=theQueue3;

	if(theQueue4.size()<q.size())
		q=theQueue4;

	return q;
}

q الآن يؤشر على أقل صف بالتالي فقط اضف الزبون إليه

#5

شكرا جزيلا أخي الفاضل

لقد كنت كتبتها على هذا النحو

int min=sum1;

if(min>sum2)

{

min=sum2;

theQueue2.enqueue(customerItem);

System.out.println("The new customer will join the Second line\n");

}

if(min>sum3)

{

min=sum3;

theQueue3.enqueue(customerItem);

System.out.println("The new customer will join the third line\n");

}

if(min>sum4)

{

min=sum4;

theQueue4.enqueue(customerItem);

System.out.println("The new customer will join the fourth line\n");

}

if(min>=sum1)

{

theQueue1.enqueue(customerItem);

System.out.println("The new customer will join the first line\n");

}

هذا الموضوع مغلق.

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

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

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

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

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