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

اتمنى مساعدتي في مشروعي

بدأه smart princess في 15 ديسمبر 2009 · 11 رد · 1,017 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

كيفكم؟؟

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

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

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

//this programe will find your age
import java.util.*;
public class Age1{
  public static void main(String[] args){
    int x,y,z,s,m,k,a,d,r;
   String name;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter your name");
    name=scan.nextLine();
      do{
    System.out.println("Enter the day of the month your born on");
    x=scan.nextInt();
    if(x<=0||x>31){
      System.out.println("oobs there are no date like this");
    }
      }while(x<=0||x>31);
      do{
    System.out.println("Enter the month you born in");
    y=scan.nextInt();
    if(y<=0||y>31){
      System.out.println("oobs there are no date like this");
    }
      }while(y<=0||y>31);
      do{
    System.out.println("Enter the year you born in");
    z=scan.nextInt();
    if(z<=0||z>2011){
      System.out.println("oobs there are no date like this");
    }
      }while(z<=0||z>2011);
      do{
    System.out.println("Enter the date of today");
    s=scan.nextInt();
    if(s<=0||s>31){
      System.out.println("oobs there are no date like this");
    }
      }while(s<=0||s>31);
      do{
    System.out.println("Enter this month");
    m=scan.nextInt();
    if(m<=0||m>31){
      System.out.println("oobs there are no date like this");
    }
      }while(m<=0||m>31);
      do{
    System.out.println("Enter this year");
    k=scan.nextInt();
    if(k<=0||k>2011){
      System.out.println("You are not born right now :)");
    }
    }while(k<=0||k>2011);
     r=s-x;
    if(r<0){
      r=x-s;
    }
    a=m-y;
    if(a<0){
      a=y-m;
    }
    d=k-z;
    System.out.println("Dear "+name+" your age is "+d+" year\n and "+a+" month \n and "+r+" day");
  }
}

اتمنى الرد باسرع وقت لان المشروع لازم نسلمه خلال السبوع القادم ان شاء الله

#2

بداية أختي أحب أن أرحب بك هنا في المنتدى

وأتمنى منك أن لا تقومي بكتابة كلمات أجنبية بكلمات عربية مثل أسايمنت

إما أن تكتبي بالعربية أو تكتبي المصطلح بالعربية

نأتي لسؤالك

لم أستطع فهم ما تحتاجين إليه بالضبط

لذا أعيدي صياغة السؤال بشكل أفضل

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3
علاء الصالحي كتب:

بداية أختي أحب أن أرحب بك هنا في المنتدى

وأتمنى منك أن لا تقومي بكتابة كلمات أجنبية بكلمات عربية مثل أسايمنت

إما أن تكتبي بالعربية أو تكتبي المصطلح بالعربية

نأتي لسؤالك

لم أستطع فهم ما تحتاجين إليه بالضبط

لذا أعيدي صياغة السؤال بشكل أفضل

تحياتي

بداية اشكر اخي على الترحيب والرد,,,

سؤالي هو مثل ما ذكر ان الدكتور الذي يقوم بتدريسنا الجافا اخبرني بان البرنامج صحيح ولكن ينقصه بعض الاضافات مثل اخذ السنه الكبيسة في الاعتبار ووضع if لكل شهر وبصراحه لم افهم مطلوبه بالضبط ولكن سؤالي ماذا ينقص برنامجي ليكون صحيح على ضوء النقاط التي ذكرها الدكتور (السنة الكبيسة والif لكل شهر)؟

#5
NullOne كتب:

طريقة الحل خطأ، لا يمكن أن تحسبي العمر من خلال ال-integer subtraction

يجب أن تستخدمي ال- GregorianCalendar

http://java.sun.com/j2se/1.5.0/docs/api/java/util/GregorianCalendar.html

يعطيك الف عافية اخي على الرد,,

ولكن هل من الممكن ان توضح اكثر لاني لازلت مبتدأه في الجافا

#6

هل من الضروري أن يقوم المستخدم بإدخال تاريخ اليوم؟؟ لأنك ممكن تحصلي عليه برمجيا وتختصري الكود بشكل كبير

#7
/**
 *  I changed the whole code, but didn't test it properly
 *  So if you find some mistake try to fix it :) some practice for you :)
 */

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.InputMismatchException;
import java.util.Scanner;


public class AgeCalculator {

    String name;
    int birthYear, birthMonth, birthDay;
    int ageYears, ageMonths, ageDays;


    public void getUserData()
    {
         Scanner scan=new Scanner(System.in);
        System.out.print("Enter your name: ");
        name=scan.nextLine();

        // read year from input
        try
        {
            do{
                 System.out.print("Enter your birth year: ");
                 birthYear=scan.nextInt();
                if(birthYear > GregorianCalendar.getInstance().get(Calendar.YEAR))
                {
                    System.out.println("Enter a valid year");
                }
              }
            while(birthYear > GregorianCalendar.getInstance().get(Calendar.YEAR));

        // read month from input
             do{
                 System.out.print("Enter your birth month: ");
                 birthMonth = scan.nextInt();
                if(birthMonth < 1 || birthMonth > 12)
                {
                    System.out.println("Enter a valid month");
                }
              }
            while(birthMonth < 1 || birthMonth > 12);

        // read month from input
            do{
                 System.out.print("Enter your birth day: ");
                 birthDay = scan.nextInt();
                if(birthDay < 1 || birthDay > 31)
                {
                    System.out.println("Enter a valid day");
                }
              }
            while(birthDay < 1 || birthDay > 31);

    }
     catch(ArithmeticException e)
        {
            System.out.println("Invalid input, Exiting ...");
            System.exit(0);
        }
        catch(InputMismatchException e1)
        {
            System.out.println("Invalid input, Exiting ...");
            System.exit(0);
        }

    }


    public void calculateAge()
    {
        Calendar currentDate = GregorianCalendar.getInstance();
        Calendar birthDate = new GregorianCalendar(birthYear, birthMonth - 1, birthDay);

    // exit if birth date is after the current date
        if(birthDate.after(currentDate))
        {
            {
                System.out.print("Invalid date!");
                System.exit(0);
            }

        }


     ageYears = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);


    if(currentDate.before(new GregorianCalendar(currentDate.get(Calendar.YEAR), birthMonth, birthDay)))
    {
        if(ageYears > 0)
        {
            ageYears--;
        }

      ageMonths = (12 - (birthDate.get(Calendar.MONTH) + 1)) + (birthDate.get(Calendar.MONTH));

      if(birthDay > currentDate.get(Calendar.DAY_OF_MONTH))
      {
        ageDays = birthDay - currentDate.get(Calendar.DAY_OF_MONTH);
      }
      else if(birthDay < currentDate.get(Calendar.DAY_OF_MONTH))
      {
        ageDays = currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;
      }
      else
      {
        ageDays = 0;
      }
    }
    else
        if(currentDate.after(new GregorianCalendar(currentDate.get(Calendar.YEAR), birthMonth, birthDay)))
        {
           ageMonths = (currentDate.get(Calendar.MONTH) - (birthDate.get(Calendar.MONTH)));
          if(birthDay > currentDate.get(Calendar.DAY_OF_MONTH))
          {
                int days = birthDate.getActualMaximum(Calendar.DAY_OF_MONTH);
                ageDays = days + currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;
                ageMonths--;
          }
          else
            if(birthDay < currentDate.get(Calendar.DAY_OF_MONTH))
            {
                ageDays = currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;

            }
          else
            ageDays = 0;
    }
    else{
      ageYears = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);
      ageMonths = 0;
      ageDays = 0;
    }

     System.out.println("Dear " + name + ", your current age is: " + ageYears +
             " years, " + ageMonths + " months, and " + ageDays + " days");
   }

    public static void main(String [] args)
    {
        AgeCalculator calculator = new AgeCalculator();

        calculator.getUserData();
        calculator.calculateAge();

    }

}
#8
herch كتب:

هل من الضروري أن يقوم المستخدم بإدخال تاريخ اليوم؟؟ لأنك ممكن تحصلي عليه برمجيا وتختصري الكود بشكل كبير

بصراحه اخي العزيز انا مبتدأه في مجال الجافا وقد كتبت هذه البرنامج على حسب معرفتي وطرحته هنا حتى تساعدوني في تصحيحه,,,

هل من الممكن ان توضح أكثر؟؟,,

ولك جزيل الشكر على الرد,,,

NullOne كتب:

/**
 *  I changed the whole code, but didn't test it properly
 *  So if you find some mistake try to fix it :) some practice for you :)
 */

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.InputMismatchException;
import java.util.Scanner;


public class AgeCalculator {

    String name;
    int birthYear, birthMonth, birthDay;
    int ageYears, ageMonths, ageDays;


    public void getUserData()
    {
         Scanner scan=new Scanner(System.in);
        System.out.print("Enter your name: ");
        name=scan.nextLine();

        // read year from input
        try
        {
            do{
                 System.out.print("Enter your birth year: ");
                 birthYear=scan.nextInt();
                if(birthYear > GregorianCalendar.getInstance().get(Calendar.YEAR))
                {
                    System.out.println("Enter a valid year");
                }
              }
            while(birthYear > GregorianCalendar.getInstance().get(Calendar.YEAR));

        // read month from input
             do{
                 System.out.print("Enter your birth month: ");
                 birthMonth = scan.nextInt();
                if(birthMonth < 1 || birthMonth > 12)
                {
                    System.out.println("Enter a valid month");
                }
              }
            while(birthMonth < 1 || birthMonth > 12);

        // read month from input
            do{
                 System.out.print("Enter your birth day: ");
                 birthDay = scan.nextInt();
                if(birthDay < 1 || birthDay > 31)
                {
                    System.out.println("Enter a valid day");
                }
              }
            while(birthDay < 1 || birthDay > 31);

    }
     catch(ArithmeticException e)
        {
            System.out.println("Invalid input, Exiting ...");
            System.exit(0);
        }
        catch(InputMismatchException e1)
        {
            System.out.println("Invalid input, Exiting ...");
            System.exit(0);
        }

    }


    public void calculateAge()
    {
        Calendar currentDate = GregorianCalendar.getInstance();
        Calendar birthDate = new GregorianCalendar(birthYear, birthMonth - 1, birthDay);

    // exit if birth date is after the current date
        if(birthDate.after(currentDate))
        {
            {
                System.out.print("Invalid date!");
                System.exit(0);
            }

        }


     ageYears = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);


    if(currentDate.before(new GregorianCalendar(currentDate.get(Calendar.YEAR), birthMonth, birthDay)))
    {
        if(ageYears > 0)
        {
            ageYears--;
        }

      ageMonths = (12 - (birthDate.get(Calendar.MONTH) + 1)) + (birthDate.get(Calendar.MONTH));

      if(birthDay > currentDate.get(Calendar.DAY_OF_MONTH))
      {
        ageDays = birthDay - currentDate.get(Calendar.DAY_OF_MONTH);
      }
      else if(birthDay < currentDate.get(Calendar.DAY_OF_MONTH))
      {
        ageDays = currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;
      }
      else
      {
        ageDays = 0;
      }
    }
    else
        if(currentDate.after(new GregorianCalendar(currentDate.get(Calendar.YEAR), birthMonth, birthDay)))
        {
           ageMonths = (currentDate.get(Calendar.MONTH) - (birthDate.get(Calendar.MONTH)));
          if(birthDay > currentDate.get(Calendar.DAY_OF_MONTH))
          {
                int days = birthDate.getActualMaximum(Calendar.DAY_OF_MONTH);
                ageDays = days + currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;
                ageMonths--;
          }
          else
            if(birthDay < currentDate.get(Calendar.DAY_OF_MONTH))
            {
                ageDays = currentDate.get(Calendar.DAY_OF_MONTH) - birthDay;

            }
          else
            ageDays = 0;
    }
    else{
      ageYears = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);
      ageMonths = 0;
      ageDays = 0;
    }

     System.out.println("Dear " + name + ", your current age is: " + ageYears +
             " years, " + ageMonths + " months, and " + ageDays + " days");
   }

    public static void main(String [] args)
    {
        AgeCalculator calculator = new AgeCalculator();

        calculator.getUserData();
        calculator.calculateAge();

    }

}

بدايه اشكر لك ردك اخي العزيز,,,

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

#9

في الكود الذي كتبت تطلبين من المستخدم إدخال تاريخ ميلاده ثم تطلبين أن يدخل تاريخ اليوم

سؤالي كان هل من الازم أن يقوم المستخدم بإدخال تاريخ اليوم بنفسه؟ فالجافا تتيح إمكانية معرفة تاريخ اليوم

#10

هل جربتي ال code الذي وضعته ؟

في ال-java يمكن أن تعرف تاريخ اليوم والوقت من خلال التاريخ والوقت الموجودين في ال-system . بدون داعي أن يدخل المستخدم تاريخ اليوم

في ال-code الذي وضعته يدخل المستخدم فقط تاريخ ميلاده

إذا أضفت comments لشرح ال-code في ال-english يكفي ؟

تم تعديل هذه المشاركة بواسطة NullOne في 22 ديسمبر 2009 في 19:27

#11
herch كتب:

في الكود الذي كتبت تطلبين من المستخدم إدخال تاريخ ميلاده ثم تطلبين أن يدخل تاريخ اليوم

سؤالي كان هل من الازم أن يقوم المستخدم بإدخال تاريخ اليوم بنفسه؟ فالجافا تتيح إمكانية معرفة تاريخ اليوم

انا عملت هذا البرنامج على اعتبار انني لا اعرف ان الجافا تتيح معرفه تاريخ اليوم ف مثل ما ذكرت سابقا انني مبتدأه فيه :) ,,,

#12
NullOne كتب:

هل جربتي ال code الذي وضعته ؟

في ال-java يمكن أن تعرف تاريخ اليوم والوقت من خلال التاريخ والوقت الموجودين في ال-system . بدون داعي أن يدخل المستخدم تاريخ اليوم

في ال-code الذي وضعته يدخل المستخدم فقط تاريخ ميلاده

إذا أضفت comments لشرح ال-code في ال-english يكفي ؟

بصراحه لم اجربه بعد بسبب انشغالي بالاختبارات هذه الايام ولكن ساجربه ان شاء الله,,

نعم قد تفي الcomments بالغرض,,,

وشكرا لك تعبتك وياي,,,

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…