السلام عليكــم ورحمـة الله وبركاتــه ،،
هذا البرنامج يعمل على تحويل الوقت على حسب اختيار المستخدم.
هذه الاوقات هي
AEST = GMT + 10
ACST = GMT +9 1/2
ASET = GMT + 8
بحيث ان المستخدم يدخل الوقت الحالي, وبعدين يختار يحوله على اي وقت من السابق ذكره
وبعدين بسأله البرنامج اذا يبي يدخل وقت كمان او لا, وهذا مثال للمطلوب
java ZoneTimeDemo
Enter a military time using the ##:## form:
10:47
Current time is 10:47 AM AEDT New time zone (AEST, AEDT, ACST, ACDT, AWST or AWDT):
aest
Converted time is 9:47 AM AEST
Do you want to enter another (Y/N)?
y
Enter a military time using the ##:## form: 10:47
Current time is 10:47 AM AEDT New time zone (AEST, AEDT, ACST, ACDT, AWST or AWDT):
acst
Converted time is 9:17 AM ACST Do you want to enter another (Y/N)?
n
المطلوب عمل كلاسين مشتقين من الكلاس الاب وهو تايم.جافا
عالى الرغم من محاولاتي المضنيه في عمل الكلاس الاب ولكن هناك اخطاء وهو مرفق.
وايضا حاولة عمل الكلاسين ولكن مثل الكلاس الاب. لا نتيجه تذكر
فهل من منقذ ؟
وهذه اكوادي
هذا الكلاس الرئيسي
{
public BetterTime(String militaryTime)
{
public void setZone(String zone)
public void Update(int minutes)
وهذا مشتق من الاول
{
private int;
public ZoneTime(String militaryTime)
public void setZone(String zone)
public String toString()
{
String am_pm;
String zero = "";
if (afternoon)
am_pm = "PM";
else
am_pm = "AM";
if (minutes < 10)
zero = "0";
return hours + ":" + zero + minutes + " " + am_pm;
}
}
وهذا كلاس ثالث
//the customary conventions
public class Time
{
//hours in conventional time
private int hours;
//minutes in conventional time
private int minutes;
//true if afternoon time, false if morning time
private boolean afternoon;
//Constructs a cutomary time (12 hours, am or pm)
//from a military time ##:##
public Time(String militaryTime)
{
//Check to make sure something was entered
if (militaryTime == null)
{
System.out.println(
"You must enter a valid miliary time." );
}
//Check to make sure there are 5 characters
else if (//CONDITION TO CHECK LENGTH OF STRING)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else
{
//Check to make sure the colon is in
//the correct spot
if (//CONDITION TO CHECK COLON POSITION)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
//Check to make sure all other characters are digits
else if (//CONDITION TO CHECK FOR DIGIT)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else if (//CONDITION TO CHECK FOR DIGIT)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else if (//CONDITION TO CHECK FOR DIGIT)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else if (//CONDITION TO CHECK FOR DIGIT)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else
{
//SEPARATE THE STRING INTO THE HOURS
//AND THE MINUTES, CONVERTING THEM TO
//INTEGERS AND STORING INTO THE
//INSTANCE VARIABLES
//validate hours and minutes are valid values
if(hours > 23)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
else if(minutes > 59)
{
System.out.println(militaryTime +
" is not a valid miliary time." );
}
//convert military time to conventional time
//for afternoon times
else if (hours > 12)
{
hours = hours - 12;
afternoon = true;
System.out.println(this.toString());
}
//account for midnight
else if (hours == 0 && minutes == 0)
{
hours = 12;
System.out.println(this.toString());
}
//morning times don't need converting
else
{
System.out.println(this.toString());
}
}
}
}
public void setHours(int hours)
public void setMinutes(int minutes)
public void setAfternoon(boolean afternoon)
public int getHours()
{
return hourse;
}
public int getMinutes()
{
return minutes;
}
public boolean getAfternoon()
{
return afternoon;
}
public String toString()
{
String am_pm;
String zero = "";
if (afternoon)
am_pm = "PM";
else
am_pm = "AM";
if (minutes < 10)
zero = "0";
return hours + ":" + zero + minutes + " " + am_pm;
}
}
وهذا البرنامج
public class TimeDemo
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
char answer = 'Y';
String enteredTime;
String response;
while (//CHECK ANSWER AFTER CONVERTING TO CAPITAL)
{
System.out.print(
"Enter a miitary time using the ##:## form ");
enteredTime = keyboard.nextLine();
Time now = new Time (enteredTime);
System.out.println(
"Do you want to enter another (Y/N)? ");
response = keyboard.nextLine();
answer = response.charAt(0);
}
}
}
