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

مساعدة اضافة الأيام كود الساعة

بدأه Abodia في 11 نوفمبر 2010 · 33 رد · 1,064 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

مساعدة الكود الي عندي بيطبع ارقام الأيام وانا ابغى اطبع اليوم نفسه وبس ماضبط معاي

الكود المفروض يطبع :

Modify the Clock class from your previous assignment to include the following functionality:

It should store, manipulate and display the day of the week

It should be able to reverse the clock in addition to advancing it.

You are provided with a ClockDriver class to test the functionality of the Clock class. Do not change anything in the ClockDriver class. If your Clock class works correctly you should see the following output:

compile:

run:

Thursday, 12:00 pm

Thursday, 2:30 pm

Friday, 12:15 am

Friday, 12:15 am

Thursday, 2:30 pm

Saturday, 2:30 pm

BUILD SUCCESSFUL (total time: 0 seconds)

This assignment is due on 11/16/2010 (11:59 pm)

الكود الموجود عندي :

package clockdriver;

public class ClockDriver {

public static void main(String[] args) {

Clock MyClock = new Clock("Thursday", 12,0); // Instantiate a clock object

System.out.println(MyClock); // Should display: Thursday, 12:00 p.m.

System.out.println(); // print blank line

MyClock.advance(150); // advance time 150 minutes (2 hours 30 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.advance(585); // advance time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.advance(10080); // advance time by 10080 minutes (7 days)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.reverse(585); // reverse time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.reverse(17280); // reverse time by 17280 minutes (12 days)

System.out.println(MyClock); // Should display: Saturday, 2:30 p.m.

System.out.println();

} // end of main

} // end of class ClockDriver

class Clock{

/***************************************************************

* Objects of this class represent time (in hours and minutes) *

* The time data is stored in 24 hour (HHMM military format) *

***************************************************************/

private int day_of_week; // valid range of values is 1 thru' 7

private int hours; // range of values is 0 thru' 23

private int minutes; // range of values is 0 thru' 59

public Clock(String s, int h, int m){

day_of_week=5;

hours=0;

minutes=0;

}

public void advance(int m){

int totalminutes = (hours*60)+(minutes+m);

day_of_week=totalminutes%8;

hours = (totalminutes/60)%24;

minutes=totalminutes%60;

}

public void reverse(int m){

int totalminutes = (hours*60)-(minutes-m);

day_of_week=totalminutes%8;

hours = (totalminutes%24)/60;

minutes=totalminutes%60;

}

@Override

public String toString(){

String S = + day_of_week + ", " +

(hours>12? hours-12 : hours<1? 12 : hours) +

":" + (minutes<10? ("0"+minutes) : minutes) +

(hours>=12? " pm" : " am");

return (S);

}

}

الكود بيطبع

run:

5, 12:00 am

6, 2:30 am

7, 12:15 pm

7, 12:15 pm

2, 12:30 am

2, 12:30 am

BUILD SUCCESSFUL (total time: 0 seconds)

#2

االمفروض ان يكون حضرتك تعلمت من المره اللى فاتت ازاى تعمل الموضوع دا

لكن بالنسبه للرقم اللى بيظهر قبل الساعه

فحضرتك قبل الطباعه بتشوف الرقم دا بيناسب اى يوم وتطبع اليوم بدلا من الرقم

حضرتك كدا بتسال فى كل حاجه واعتقد ان دا مش كويس علشانك

حاول فيها واعملها وانا اعطيتك نبذه عن ماذا ستفعل

ارنا كيف تقوم بعملها

بالتوفيق

Software Developer
Mahmoudkelany.com


 

#3
Mahmoud Kelany كتب:

االمفروض ان يكون حضرتك تعلمت من المره اللى فاتت ازاى تعمل الموضوع دا

لكن بالنسبه للرقم اللى بيظهر قبل الساعه

فحضرتك قبل الطباعه بتشوف الرقم دا بيناسب اى يوم وتطبع اليوم بدلا من الرقم

حضرتك كدا بتسال فى كل حاجه واعتقد ان دا مش كويس علشانك

حاول فيها واعملها وانا اعطيتك نبذه عن ماذا ستفعل

ارنا كيف تقوم بعملها

بالتوفيق

انا حولة الرقم الى نص وجربت اول يوم بس بيعطيني ايررر بس ماضبطة معايا

private int day_of_week; // valid range of values is 1 thru' 7

private int hours; // range of values is 0 thru' 23

private int minutes; // range of values is 0 thru' 59

public Clock(String S, int h, int m){

day_of_week=5;

day_of_week=Integer.parseInt(S); //I change number to string but still has proble

day_of_week="thirsday";

hours=0;

minutes=0;

#4

ايه الخطا اللى ظهر معاك ؟؟

ولو تكرمت عند وضع كود كبير كمثل هذا

من الافضل وضع المشروع الذى تعمل عليه

لان هذا بيتعبنا كثير فى اخذ الكود نسخ ولصق وفتح مشروع جديد

وشكرا

Software Developer
Mahmoudkelany.com


 

#5
Mahmoud Kelany كتب:

ايه الخطا اللى ظهر معاك ؟؟

ولو تكرمت عند وضع كود كبير كمثل هذا

من الافضل وضع المشروع الذى تعمل عليه

لان هذا بيتعبنا كثير فى اخذ الكود نسخ ولصق وفتح مشروع جديد

وشكرا

مشكور على ردك السريع معذرة على اللخبطة

هذا الكود

package clockdriver;

/**

*

* @author

*/

public class ClockDriver {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Clock MyClock = new Clock("Thursday", 12,0); // Instantiate a clock object

System.out.println(MyClock); // Should display: Thursday, 12:00 p.m.

System.out.println(); // print blank line

MyClock.advance(150); // advance time 150 minutes (2 hours 30 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.advance(585); // advance time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.advance(10080); // advance time by 10080 minutes (7 days)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.reverse(585); // reverse time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.reverse(17280); // reverse time by 17280 minutes (12 days)

System.out.println(MyClock); // Should display: Saturday, 2:30 p.m.

System.out.println();

} // end of main

} // end of class ClockDriver

class Clock{

/***************************************************************

* Objects of this class represent time (in hours and minutes) *

* The time data is stored in 24 hour (HHMM military format) *

***************************************************************/

private int day_of_week; // valid range of values is 1 thru' 7

private int hours; // range of values is 0 thru' 23

private int minutes; // range of values is 0 thru' 59

public Clock(String S, int h, int m){

day_of_week=5;

day_of_week=Integer.parseInt(); //I change number to string but still has proble

day_of_week="thirsday";

hours=0;

minutes=0;

}

public void advance(int m){

int totalminutes = (hours*60)+(minutes+m);

day_of_week=totalminutes%8;

hours = (totalminutes/60)%24;

minutes=totalminutes%60;

}

public void reverse(int m){

int totalminutes = (hours*60)-(minutes-m);

day_of_week=totalminutes%8;

hours = (totalminutes%24)/60;

minutes=totalminutes%60;

}

@Override

public String toString(){

String S = + day_of_week

+ ", " +

(hours>12? hours-12 : hours<1? 12 : hours) +

":" + (minutes<10? ("0"+minutes) : minutes) +

(hours>=12? " pm" : " am");

return (S);

}

}

output

run:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code

at clockdriver.Clock.<init>(ClockDriver.java:52)

at clockdriver.ClockDriver.main(ClockDriver.java:13)

Java Result: 1

BUILD SUCCESSFUL (total time: 2 seconds)

Mahmoud Kelany كتب:

ايه الخطا اللى ظهر معاك ؟؟

ولو تكرمت عند وضع كود كبير كمثل هذا

من الافضل وضع المشروع الذى تعمل عليه

لان هذا بيتعبنا كثير فى اخذ الكود نسخ ولصق وفتح مشروع جديد

وشكرا

احمل الملف كامل

Abodia كتب:

مشكور على ردك السريع معذرة على اللخبطة

هذا الكود

package clockdriver;

/**

*

* @author

*/

public class ClockDriver {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Clock MyClock = new Clock("Thursday", 12,0); // Instantiate a clock object

System.out.println(MyClock); // Should display: Thursday, 12:00 p.m.

System.out.println(); // print blank line

MyClock.advance(150); // advance time 150 minutes (2 hours 30 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.advance(585); // advance time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.advance(10080); // advance time by 10080 minutes (7 days)

System.out.println(MyClock); // Should display: Friday, 12:15 a.m.

System.out.println();

MyClock.reverse(585); // reverse time by 585 minutes (9 hours 45 minutes)

System.out.println(MyClock); // Should display: Thursday, 2:30 p.m.

System.out.println();

MyClock.reverse(17280); // reverse time by 17280 minutes (12 days)

System.out.println(MyClock); // Should display: Saturday, 2:30 p.m.

System.out.println();

} // end of main

} // end of class ClockDriver

class Clock{

/***************************************************************

* Objects of this class represent time (in hours and minutes) *

* The time data is stored in 24 hour (HHMM military format) *

***************************************************************/

private int day_of_week; // valid range of values is 1 thru' 7

private int hours; // range of values is 0 thru' 23

private int minutes; // range of values is 0 thru' 59

public Clock(String S, int h, int m){

day_of_week=5;

day_of_week=Integer.parseInt(); //I change number to string but still has proble

day_of_week="thirsday";

hours=0;

minutes=0;

}

public void advance(int m){

int totalminutes = (hours*60)+(minutes+m);

day_of_week=totalminutes%8;

hours = (totalminutes/60)%24;

minutes=totalminutes%60;

}

public void reverse(int m){

int totalminutes = (hours*60)-(minutes-m);

day_of_week=totalminutes%8;

hours = (totalminutes%24)/60;

minutes=totalminutes%60;

}

@Override

public String toString(){

String S = + day_of_week

+ ", " +

(hours>12? hours-12 : hours<1? 12 : hours) +

":" + (minutes<10? ("0"+minutes) : minutes) +

(hours>=12? " pm" : " am");

return (S);

}

}

output

run:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code

at clockdriver.Clock.<init>(ClockDriver.java:52)

at clockdriver.ClockDriver.main(ClockDriver.java:13)

Java Result: 1

BUILD SUCCESSFUL (total time: 2 seconds)

احمل الملف كامل

هذا المشروع

ClockDriver.java

#6

طبعا عندك اخطاء

ازاى تضع String فى int

 day_of_week = Integer.parseInt();
day_of_week = "thirsday";

وكمان الداله

parseInt(string);

بتاخد String

Software Developer
Mahmoudkelany.com


 

#7
Mahmoud Kelany كتب:

طبعا عندك اخطاء

ازاى تضع String فى int

 day_of_week = Integer.parseInt();
day_of_week = "thirsday";

وكمان الداله

parseInt(string);

بتاخد String

علشان احول رقم اليوم الى اسم اليوم لأنو ما يقبل اني اكتب نص لأنو integer

علشان كذا حاولت اني احول من من integer to String

#8

هو فين التحويل انت مش حولت حاجه

وبعدين انت بتحول من int لـ string وليس العكس

Software Developer
Mahmoudkelany.com


 

#9
Mahmoud Kelany كتب:

هو فين التحويل انت مش حولت حاجه

وبعدين انت بتحول من int لـ string وليس العكس

كذا مضبوط

public Clock(String S, int h, int m){
      day_of_week=5;
       day_of_week=String.parseInt(day_of_week); //I change number to string but still has proble
      day_of_week="thirsday";
#10

انت بتستخدم IDE ايه ؟؟

netbeans , Eclipse ؟

Software Developer
Mahmoudkelany.com


 

#11
Abodia كتب:

كذا مضبوط

public Clock(String S, int h, int m){
      day_of_week=5;
       day_of_week=String.parseInt(day_of_week); //I change number to string but still has proble
      day_of_week="thirsday";

Netbeans
#12

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

ولا حضرتك بتجرب؟؟؟

يعنى المفروض ان حضرتك عارف انه خطأ

ليه بقا تقول ان كدا مظبوط ؟؟؟؟

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 12 نوفمبر 2010 في 08:26

Software Developer
Mahmoudkelany.com


 

#13
Mahmoud Kelany كتب:

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

ولا حضرتك بتجرب؟؟؟

يعنى المفروض ان حضرتك عارف انه خطأ

ليه بقا تقول ان كدا مظبوط ؟؟؟؟

انا اقصد اني عدلة الطريقة الي قلتلي عليها ما اقصد انو صح بس اتبعت الي قلت

#14

طبعا بردوا غلط

لان انا قولت لك

parseInt(string);

ان الداله دى بتاخد string مش int

هل

day_of_week=String.parseInt(day_of_week);

هى كدا بتاخد String?

وكمان قولت لك ان المتغير دا day_of_week

نوعه int

تضع فيه String

ازاى؟؟؟

 day_of_week="thirsday";

وبدال الخط الاحمر تحت الكلام اعرف ان فيه حاجه انت عاملها غلط

وشوفها وراجع عليها تانى

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 12 نوفمبر 2010 في 08:34

Software Developer
Mahmoudkelany.com


 

#15
Abodia كتب:

Netbeans

والله يا اخ محمد احس انو الجافا صعب عقدني يا اخي

#16

هو ليه انت بتعمل اقتباسات كتير من كلامك

مع ان الاقتباس لا يفيد ؟؟؟

وبعدين الجافا سهله جدا ف تعلمها

وانا مش بعقد حد

لكن انت قدامك انه خطأ وتيجى تقولى انه كدا مظبوط

وتقولى ان انت متبع اللى قولته

شوف ردى السابق وقارن شغلك باللى انا قولته

شوف هل انت متبع فعلا ام لا ؟؟

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 12 نوفمبر 2010 في 08:37

Software Developer
Mahmoudkelany.com


 

#17
Mahmoud Kelany كتب:

هو ليه انت بتعمل اقتباسات كتير من كلامك

مع ان الاقتباس لا يفيد ؟؟؟

وبعدين الجافا سهله جدا ف تعلمها

وانا مش بعقد حد

لكن انت قدامك انه خطأ وتيجى تقولى انه كدا مظبوط

وتقولى ان انت متبع اللى قولته

شوف ردى السابق وقارن شغلك باللى انا قولته

شوف هل انت متبع فعلا ام لا ؟؟

اوكى بس حلمك علي والله بفكر وبحاول حتى احصل على النتيجة

بس عندي سوآل هل الطريقة البداية صح انو احول الرقم الى نص ولا الفكرة اساسا غلطا, يعني اغير في مكان ثاني من الكود.

تم تعديل هذه المشاركة بواسطة Abodia في 12 نوفمبر 2010 في 08:50

#18

لالا خليك زى ما انت ماشى

حول النص الى رقم

علشان تقوم عليه بالعمليات بتاعتك

وبعدين بعد ما تقوم بالعمليات

هيطلع لك ان المتغير اللى اسمه day_of_week

هتعمل ليه if , if else

لو كان يساوى 1 اطبع كذا

لو كان بيساوى 2 اطبع كذا

وبعد كدا تبطع الساعه بتاعتك

Software Developer
Mahmoudkelany.com


 

#19
Mahmoud Kelany كتب:

لالا خليك زى ما انت ماشى

حول النص الى رقم

علشان تقوم عليه بالعمليات بتاعتك

وبعدين بعد ما تقوم بالعمليات

هيطلع لك ان المتغير اللى اسمه day_of_week

هتعمل ليه if , if else

لو كان يساوى 1 اطبع كذا

لو كان بيساوى 2 اطبع كذا

وبعد كدا تبطع الساعه بتاعتك

اوكى

#20
Abodia كتب:

اوكى

التحويل كذا غلط ولا صح

 day_of_week = Integer.parseInt(S);
#21

تمام صح

كمل بقا

واعرض كل حاجه على بعضها

Software Developer
Mahmoudkelany.com


 

#22
Abodia كتب:

التحويل كذا غلط ولا صح

 day_of_week = Integer.parseInt(S);

الطريقة هذي بتشتغل بس التيجة الأول 0

public Clock(String S, int h, int m){



      S= Integer.toString(day_of_week);


      if(day_of_week==1){
          System.out.println("Monday");
        }
      else
          if(day_of_week==5){
              System.out.println("tusday");
          }



        hours=0;
        minutes=0;
    }
#23
Abodia كتب:

الطريقة هذي بتشتغل بس التيجة الأول 0

public Clock(String S, int h, int m){



      S= Integer.toString(day_of_week);


      if(day_of_week==1){
          System.out.println("Monday");
        }
      else
          if(day_of_week==5){
              System.out.println("tusday");
          }



        hours=0;
        minutes=0;
    }

الطريقة التانية يعطيني Error

run:

Exception in thread "main" java.lang.NumberFormatException: For input string: "Thursday"

#24

يعنى ايه مش فاهمك؟؟؟

ممكن تحط المشروع كامل بعد التعديل

Software Developer
Mahmoudkelany.com


 

#25
Abodia كتب:

الطريقة هذي بتشتغل بس التيجة الأول 0

public Clock(String S, int h, int m){



      S= Integer.toString(day_of_week);


      if(day_of_week==1){
          System.out.println("Monday");
        }
      else
          if(day_of_week==5){
              System.out.println("tusday");
          }



        hours=0;
        minutes=0;
    }

الطريقة التانية يعطيني Error

run:

Exception in thread "main" java.lang.NumberFormatException: For input string: "Thursday"

ClockDriver.java

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