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

حل سؤال ضروري جدا لل جافا uml

بدأه norhan ahmad في 15 مايو 2011 · 13 رد · 881 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم :

قد كمت بتنفيذ هذا الكود على برنامج الكلبس لكنه لا يتنفذ هل لانه لايوجد كود الطباعة وهل يتنفذ ام لا وان كان بسبب عدم وجود كود الطباعة وماذا ممكن ان نضع في هذا الكود ليظهر out put

بشكل مناسب السؤال مرفق كصوره

وشكرا لكم

public class Time

{

private int minute;

private int second;

private int hour;

public void incrementHour(int x){}

public void incrementMinute(int y){}

public void decrSecond(int z){}

public void incrementSecond(int a){}

public void decrHour(int c){}

public void decrMinute(int f){}

public String displayAmPmTime(){return "";}

public String display42hourTime(){return "";}

public static void main (String [] args)

{}

}

post-237187-091897300 1305416930_thumb.j

المرفقات
Presentation1.jpg
#2

البرنامج لا يتنفذ لانك لم تقومي بوضع شيئ داخل الدالة ,main طبعا التنفيذ ماله اي دخل بكود الطباعه ، هناك الكثير

من البرامج التي تعمل من دون ان تطبع اي شيئ و اكبر مثال الــ daemons

طبعا علشان تطبعي حقك الكلاس اعملي اوبجكت من الكلاس حقك

Time t = new Time();

بس بما انه المتغيرات حقك integers راح تكون قيمتهم 0

ولا اعملي constructor

    public Time(int minute, int second, int hour) {
        this.minute = minute;
        this.second = second;
        this.hour = hour;
    }

وجربي هذا السطر داخل الداله main

Time t = new Time(20,20, 3);
    System.out.println(t.hour+ ":"+t.second + ":" + t.minute );

الكلاس حقك متوافق تمام مع الUML لذا لا توجد ايه مشكله في تمثيل النموذج

تم تعديل هذه المشاركة بواسطة mental-driller في 15 مايو 2011 في 03:08

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#3

شكرا للاهتمام لكني اريد كود للبرنامج الذي في الصورة المرفقة دون اضافة اي شيء اخر وشكرا

#4

اذا مثل ما قلت لك اكتبي هذا السطر داخل الدالة main

Time t = new Time();
    System.out.println(t.hour+ ":"+t.second + ":" + t.minute );

وسيعمل البرنامج

لا تقولي لي انك لا تريدين ان تكتبي اي حاجة داخل main !

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#5

شكرا جزيلا لاهتمامك

والله الدكتور اعطانا السؤال زي ماهو في الصورة وطلب انا ما انعدل عليه بشء بس نستخدم الموجود وما طلب منا نكتب اي شيء داخل main انخليه زي ما هو

شكرا

#6

يعني يشتي بس تكتبوا الكلاس ، طبعا لو طلب منكم انكم تكتبوا الدوال

public class Time {

    private int minute;
    private int second;
    private int hour;

    public void incrementHour(int x) {
    }

    public void incrementMinute(int y) {
        minute += y;
    }

    public void decrSecond(int z) {
        second -= z;
    }

    public void incrementSecond(int a) {
        second += a;
    }

    public void decrHour(int c) {
        hour -= c;
    }

    public void decrMinute(int f) {
        minute -= f;
    }

    public String displayAmPmTime() {
        return String.format("%d:%02d:%02d %s", ((hour == 0 || hour == 12) ? 12 : hour % 12), minute, second, (hour < 12 ? "AM" : "PM"));
    }

    public String display42hourTime() {
        return String.format("%02d:%02d:%02d", hour, minute, second);
    }
}

هذا تطبيق للدوال لو احتجتي اليه مع اني متاكد ان تطبيق الدوال شيئ تافه

السؤال هذا في العادة الهدف منه معرفة ما اذا كنتي تقدري تحولي الــ UML الى كود ، مافيش داعي تعقدي نفسك بالتفكير انه يوجد شيئ سري خفي عليكي

بالتوفيق

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#7

شكرا شكرا شكرا

الله يوفقك

سؤال اخير لو سمحت

يعني ممكن ياتي في الامتحان تعقيدات على هذا السؤال وشو هو مثلا

وشكرا الك مره ثانيه

ممكن تشرحلي الكود الي قمت انا بكتبته اول واحد وشكرا

#8

ممكن مثلا يقولك مطلوب منك تطبيق واحدة او اثنين من الدوال ، كله يعتمد على تخصصك ، اذا كنتي متخصصه حاسوب توقعي اي شي

ممكن يجيب لك UML فيها وراثه و overridden methods

في الغالب الدكاترة يعجبهم الUML حق النظام البنكي ATM او حق الموضفين Employees

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

تم تعديل هذه المشاركة بواسطة mental-driller في 15 مايو 2011 في 04:04

1

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#9

شكرا جزيلا الك

ماهو شرح الكود الاول الذي قمت بكتابته انا

شكرا

تم تعديل هذه المشاركة بواسطة norhan ahmad في 15 مايو 2011 في 04:01

#10

الكود الذي كتبتيه في البداية هو عمل هيكل للكلاس skeleton ، كما ان الداول التي قمتي بكتابتها لم تزود باية عمليات functionality

مثل هذا الكود قد يكون اجابة على السؤال التالي: قمت بكتابة الدوال بدون ان تضيف اي عمليات

Write the methods without adding functionality

بس لو طلب منك تضيف عمل اذا لازم تكتبي داخل جسم الدالة

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#11

شكرا

على الافادة

شكرا جزيلا

#12

السلام عليكم:

design a program that displays the time in many formats and dose all the operations on time like set hour,minute,second

Note:

- initialize Time objects by default with current time from the system

- design a copy constructor

- design the equals method and to string method for your class

- create a package and put the time object in it alone

create another package and another class in it to test the Time class -

Use the UML sdiagram below to design your classes

لو قمنا بكتابة هذه المعطيات فماذا يتغير على الكود الرئيسي

شكرا لكم

#13

public class Time {

private int minute;

private int second;

private int hour;

Time (Time copy)

{

minute=copy.minute;

second=copy.second;

hour=copy.hour;

}

public int getHour(){

return hour;

}

public int getMinute(){

return minute;

}

public int getSecond(){

return second;

}

public void setHour(int hour){

this.hour=hour;

}

public void setMinute (int minute){

this.minute=minute;

}

public void setSecond(int second){

this.second=second;

}

void incrSecond(int increment)

{

int sec=second+increment;

if (sec<=0)

{

second=0;

return;

}

if(sec>60)

{

int h=sec/3600;

if(h>0)

incrHour(h);

sec=sec-(h*3600);

if (sec>60)

{

int min =sec/60;

incrMinute(min);

}

}

second=sec;

}

void incrMinute(int increment)

{

int min=minute+increment;

if(min<=0)

{

minute=0;

return;

}

if(min>60)

{

int h=min/60;

if(h>0)

incrHour(h);

min=min-(h*60);

}

minute=min;

}

void incrHour(int increment)

{

int hr=hour+increment;

if(hr<=0||hr>23)

{

hour=0;

}

hour=hr;

}

public String toString()

{

return hour+":"+minute+":"+second;

}

public String display24Format()

{

return toString();

}

public String displayAMPMFormat()

{

int h=0;

String format;

if(hour>12)

{

format="PM";

h=hour-12;

}

else

{

format ="AM";

h=hour;

}

return h+":"+minute+":"+second+format;

}

}

فقط اريد ان اضيف التالي رجاءا بسرعة ضروري وشكرا

add to this class represent full date-day,Month and year.Change the functions that you think needs to be changes.

- if you addedany private members you have to add Getters and Setters for

them.

- change the copy constructor and the toString function accordingly

- add three methods

+ incrDay(int):void

+incrMonth(int):void

+incrYear(int):void

public class Time {

private int minute;

private int second;

private int hour;

Time (Time copy)

{

minute=copy.minute;

second=copy.second;

hour=copy.hour;

}

public int getHour(){

return hour;

}

public int getMinute(){

return minute;

}

public int getSecond(){

return second;

}

public void setHour(int hour){

this.hour=hour;

}

public void setMinute (int minute){

this.minute=minute;

}

public void setSecond(int second){

this.second=second;

}

void incrSecond(int increment)

{

int sec=second+increment;

if (sec<=0)

{

second=0;

return;

}

if(sec>60)

{

int h=sec/3600;

if(h>0)

incrHour(h);

sec=sec-(h*3600);

if (sec>60)

{

int min =sec/60;

incrMinute(min);

}

}

second=sec;

}

void incrMinute(int increment)

{

int min=minute+increment;

if(min<=0)

{

minute=0;

return;

}

if(min>60)

{

int h=min/60;

if(h>0)

incrHour(h);

min=min-(h*60);

}

minute=min;

}

void incrHour(int increment)

{

int hr=hour+increment;

if(hr<=0||hr>23)

{

hour=0;

}

hour=hr;

}

public String toString()

{

return hour+":"+minute+":"+second;

}

public String display24Format()

{

return toString();

}

public String displayAMPMFormat()

{

int h=0;

String format;

if(hour>12)

{

format="PM";

h=hour-12;

}

else

{

format ="AM";

h=hour;

}

return h+":"+minute+":"+second+format;

}

}

فقط اريد ان اضيف التالي رجاءا بسرعة ضروري وشكرا

add to this class represent full date-day,Month and year.Change the functions that you think needs to be changes.

- if you addedany private members you have to add Getters and Setters for

them.

- change the copy constructor and the toString function accordingly

- add three methods

+ incrDay(int):void

+incrMonth(int):void

+incrYear(int):void

#14
اقتباس

- initialize Time objects by default with current time from the system

بالنسبة للكلاس حق Time باقي تعملي تستخدمي

import java.util.*;

Calendar calendar = new GregorianCalendar();

بعدين اعملي initialization للعناصر

private int hour = calendar.get(Calendar.HOUR);
 private int minute = calendar.get(Calendar.MINUTE);
   private int second = calendar.get(Calendar.SECOND);

اقتباس

- design a copy constructor

معمول عندك بطريقة صحيحة

اقتباس

- design the equals method and to string method for your class

بالنسبة لــ equals

public boolean euqals(Time t) {
        return this.second == t.second && this.minute == t.minute && this.hour == t.hour;

    }

هذا طبعا اذا لم يكن المقصود عمل override اذا كان المقصود عمل override ل

public boolean equals(Object O)

الرجاء التوضيح

تم تعديل هذه المشاركة بواسطة mental-driller في 15 مايو 2011 في 18:19

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

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