مساعدة الكود الي عندي بيطبع ارقام الأيام وانا ابغى اطبع اليوم نفسه وبس ماضبط معاي
الكود المفروض يطبع :
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)