السلام عليكم ورحمة الله وبركاته
كيف حالكم اخواني, انا طالب بجامعة أمريكية وتخصصي نظم ادارة المعلومات.
أخذت مادة الجافا وانا مبتدئ فيها والدكتور امرنا انو نسوي ساعة تطبع الساعات والدقايق . أنا صراحة محتار معاه ما ادري كيف ابدء. حاولت اني اعمله بس صعب علي. لوتكرمتو احد يساعدني فيه.
النتيجة النهائية يطبع
run:
The current time is: 12:00 pm
The current time is: 1200 hours
The current time is: 1:00 pm
The current time is: 1300 hours
The current time is: 1:47 pm
The current time is: 1347 hours
The current time is: 4:17 pm
The current time is: 1617 hours
The current time is: 12:32 am
The current time is: 0032 hours
BUILD SUCCESSFUL (total time: 0 seconds
)
الكود الي انا شغال عليه الآن
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clockdriver;
*/
public class ClockDriver {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Clock MyClock = new Clock(1200); // Instantiate a clock object and initialize to 12 hours, 0 minutes
MyClock.displayAMPM(); // display time in AM or PM format
MyClock.displayMilitary(); // display time in military (HHMM) format
System.out.println(); // print blank line
MyClock.setHours(13); // change hours attribute to 13
MyClock.displayAMPM();
MyClock.displayMilitary();
System.out.println();
MyClock.setMinutes(47); // change minutes attribute to 47
MyClock.displayAMPM();
MyClock.displayMilitary();
System.out.println();
MyClock.advance(150); // advance time by 150 minutes (2 hours, 30 minutes)
MyClock.displayAMPM();
MyClock.displayMilitary();
System.out.println();
MyClock.advance(495); // advance time by 495 minutes (8 hours, 15 minutes)
MyClock.displayAMPM();
MyClock.displayMilitary();
}
}
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 hours; // valid range of values 0 thru' 23
private int minutes; // valid range of values 0 thru' 59
public Clock (int h, int m)
{
/*************************************************************************
** This method (constructor) must initialize hours and minutes **
** using the value of the integer variable h (20 points) **
*************************************************************************/
if(0<= hours && hours<23 )
h=hours;
else hours=0;
if(0<= m && m<59 )
m= minutes;
else m=0;
}
public void setHours(int h){
/*************************************************************************
** This method must set hours to the value of **
** the integer variable h (5 points) *
*************************************************************************/
if(0<= h && h<59 )
h= minutes;
else h=0;
System.out.println("h"+h);
}
public void setMinutes(int m){
/*************************************************************************
** This method must set minutes to the value of **
** the integer variable m (5 points) **
*************************************************************************/
if(0<= m && m<59 )
m= minutes;
else m=0;
System.out.println("m"+m);
}
public void displayAMPM(){
/*************************************************************************
** This method must display hours and minutes using the **
** AM or PM time format i.e., hh:mm AM/PM (20 points) **
*************************************************************************/
}
}
public void displayMilitary(){
/*************************************************************************
** This method must display hours and minutes using the **
** military time format i.e., hhmm hours (10 points) **
*************************************************************************/
}
public void advance(int m){
/*************************************************************************
** This method must modify the values of hours and minutes **
** to reflect advancing time by m minutes (40 points) **
*************************************************************************/
System.out.println(m,h);
}
}