السلام عليكم أرجو المساعدة اخواني في هذا الكود فقد انشأته ولكن بقت اربع دوال لم اتمكن من تعريفها مع العلم ان وصف عمل الدوال موجود في الكود ضمن التعليقات واليكم المرفق
[تنبيه - عنوان غير مناسب : ]جافا
الأخ الكريم/الأخت الكريمة
السلام عليكم ورحمة الله وبركاته
مرحباً بكم في منتدى الفريق العربي للبرمجة
نود تنبيهك أن العنوان غير مناسب.
الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.
وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!
قواعد المشاركة
شاكرين لكم حُسن تعاونكم
الحل مكتوب في التعليقات :blink:
في ()needRecharging تنادي على getBatteryStatus()، إذا كانت القيمة التي تعيدها أصغر أو تساوي 10، تعيد true، غير ذلك تعيد false
في recharge()، تنادي على الطريقة setBatteryStatus وتمرر لها القيمة 100
في printDetails() ما عليك إلا طباعة محتوى المتغيرات التي عندك.
السلام عليكم وشكرا على المساعدة وانا اسفة بخصوص الخطا الذي وقع ولكن انا اول مرة اشارك في المنتدى وما عندي فكرة ياريت يا أحي توضح الجواب اكثر هل ممكن انادي على الدالة بتكوين اوبجكت او من غير اوبجكت
عند المنادة على دالة من نفس الفئة (class)، لا تحتاج لتكوين كائن
اذا تكرمت اخي الكريم ان تعطيني الصورة العامة للمنادة على الدالة
عند المناداة على دالة ما، فقط تكتب إسمها، وإذا كانت تنتظر أي arguments، تمرر لها القيم اللازمة. مثلا في مثالك، داخل الدالة recharge() تتم المناداة على setBatteryStatus، وبما أن هاته الاخيرة تنتظر argument من صنف int، فيجب علينا أن نمرر لها قيمة من صنف int، وفي المثال نمرر 100
public void recharge() {
setBatteryStatus(100);
}الآن اكتب باقي الدوال بنفسك
بارك الله فيك اخي الكريم وجعل الله ذلك في ميزان حسناتك ..هل ممكنبعد ان اكمل بقية الدوال ارسل اليك الكود لتدلني ان كان صحيح ام لا
السلام عليكم ارجو الا اكون قد اطلت عليكم ولكن اريد معرفة اذا كان الكود في صورته النهائية صحيح ام لا اذا تكرمتم
/**
* Write a description of class BasicPhone here.
*
* @author NJailani
* @version 2010.01.27
*/
public class BasicPhone
{
// instance variables - replace the example below with your own
private RadioTuner radio;
private String model ;
private String manufacturer ;
private int batteryStatus;
/**
*Contructor with parameters to set the values as specified by the user
*(Postcondition: manufacturer = ma, model = mo, batteryStatus = bs, radio = ra).
*/
public BasicPhone(String ma,String mo,int bs,RadioTuner ra)
{
// initialise instance variables
manufacturer = ma;
model = mo;
batteryStatus = bs;
radio = ra;
}
/**
* Method to display the current setting of the phone's radio station and its frequency
*/
public void currentRadioSetting()
{
}
/**
* Method to set the manufacturer to the value specified by the user
* (Postcondition: manufacturer = ma
*/
public void setManufacturer (String ma)
{
manufacturer = ma;
}
/**
* Method to set the model of the device to the value specified by the user
* (Postcondition: model = mo
*/
public void setModel(String mo)
{
model = mo;
}
/**
* Method to set the battery status of the device to the value specified by the user
* (Postcondition: batteryStatus = bs
*/
public void setBatteryStatus(int bs)
{
batteryStatus = bs;
}
/**
* Method to get the device manufacturer
* (Postcondition: the value of manufacturer is returned
*/
public String getManufacturer()
{
return manufacturer;
}
/**
* Method to get the device model
* (Postcondition: the value of model is returned
*/
public String getModel()
{
return model;
}
/**
* Method to get the batteryStatus
* (Postcondition: the value of batteryStatus is returned
*/
public int getBatteryStatus()
{
return batteryStatus;
}
/**
*Method to check the status of the device battery
*(using method getBatteryStatus()
*(Postcondition: true is returned if the value is <=10, false is returned if otherwise
*/
public boolean needCharging()
{
getBatteryStatus();
if(batteryStatus<=10)
return true;
else
return false;
}
/**
* Method to recharge the battery (and set the battery status to value 100
* by using method setBatteryStatus() (Postcondition: batteryStatus = 100
*/
public void recharge()
{
setBatteryStatus(100);
}
/**
* Method to display the values of all variables of the device
*/
public void printDetails()
{
System.out.println();
}
}تم تعديل هذه المشاركة بواسطة herch في 30 يناير 2010 في 13:48
//.......
public boolean needCharging() {
if (getBatteryStatus() <= 10) {
return true;
} else {
return false;
}
}
//......
public void printDetails() {
System.out.println("Model: " + model);
System.out.println("Manufacturer: " + manufacturer);
System.out.println("Battery status: " + batteryStatus);
}بارك الله فيك يا أخي على ماتقوم به واسفة على كثرة الاسئلة ولكن هذه اول مرة ادرس فيها لغة الجافا
لكن بقت دالة لم اعرف ماذا اضع بها وهي هذه الدالة
/** * Method to display the current setting of the phone's radio station and its frequency */
public void currentRadioSetting()
}
{
هذه الطريقة تقوم فقط بطباعة قيم المتغيرات، مثل الطريقة printDetails() ، ابحثي في الكود عن متغيرات تمثل ال frequency وال radio station، أظنها موجودة في الفئة RadioTuner