InstagramTwitterSnapChat


 
وصف

العودة   منتديات سكاو > الكليات الجامعية > منتدى كلية الحاسبات وتقنية المعلومات > المنتدى العام لكلية الحاسبات وتقنية المعلومات
   
   


المنتدى العام لكلية الحاسبات وتقنية المعلومات قسم خاص بالمواد العامة و الطلاب غير المتخصصين بكلية الحاسبات وتقنية المعلومات

[cpcs 202 - برمجة 1] لديك سؤال , شيء غير مفهوم ,,, تفضل هنا , موضوع مفيد

المنتدى العام لكلية الحاسبات وتقنية المعلومات

 
 
أدوات الموضوع إبحث في الموضوع انواع عرض الموضوع
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 23-09-2010, 07:39 PM   #11

Mr.Ahmad

عضو هيئة تدريس

الصورة الرمزية Mr.Ahmad

 
تاريخ التسجيل: Jul 2008
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: IT
نوع الدراسة: عضو هيئة تدريس
المستوى: متخرج
البلد: جــــدة
الجنس: ذكر
المشاركات: 2,477
افتراضي رد: [cpcs 202 - برمجة 1] لديك سؤال , شيء غير مفهوم ,,, تفضل هنا , موضوع مفيد

المشاركة الأصلية كتبت بواسطة هوتميلكوم مشاهدة المشاركة
السلام عليكم ورحمة الله وبركاته

أخي أحمد إن أمكن أتمنى ان تحل لي السؤال التالي بلغة الجافا وجزاك الله خيراً..

Credit card numbers follow certain pattern. A credit card number must be 16 digits, and must start with
• 4 for Visa cards
• 5 for Master cards
• 37 for American Express cards
• 6 for Discover cards
Suppose that you were asked to write down a Java program that validates the credit card number (if it is correct or not!). Here are the rules that determine the correctness of credit card number:
Suppose the credit card number = 4388576018402625
1) Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single digit number:
2*2 = 4
2*2 = 4
4*2 = 8
1*2 = 2
6*2 = 12 (1 + 2) = 3
5*2 = 10 (1 + 0) = 1
8*2 = 16 (1 +6) = 7
4*2 = 8

2) Now add all single-digit number from step 1 (4+4+8+2+3+1+7+8 = 37)

3) Add all digits in the odd places from right to left in the card number:
5+6+0+8+0+7+8+3 = 37

4) Sum the results from step 2 and 3
37 + 37 = 74

5) If the result in step 4 is divisible by 10, then credit card is valid, else it is not valid.
74 is not divisible by 10, so it is not valid!
Write a java program to accept a credit card number from keyboard as long, and then prints on screen, if it is valid or not. You should use the following:
public static int[] fillArray(long) : this method fills the credit card number in an array
public static int getSum(int[]) :calculated the summation from step 1 and 2
Public static int getOddSum(int[]): calculates the summation from step 3
Public static boolean isValid(int, int): determines if valid or not according to step 5.
وعليكم السلام ورحمة الله وبركاته .

تفضلي :



كود PHP:
import java.util.Scanner;
public class 
Main {
    public static 
void main(String[] args) {
        
System.out.print("Please Enter the Number of Cridit Card : ");
        
Scanner sc = new Scanner(System.in);
        
long numberCard sc.nextLong();
        
int[] digit fillArray(numberCard);
        
        if (
digit.length != 16)
        {
            
System.out.println("not valid.");
            return;
        }
        
Boolean isVaild isValid(getSum(digit), getOddSum(digit));
        if (
isVaild)
        {
            
System.out.println("valid.");
        } else {
            
System.out.println("not valid.");
        }
        
    }
    public static 
int[] fillArray (long x)
    {
        
String txt String.valueOf(x);
        
int digit [] = new int[txt.length()];
        for (
int i 0txt.length(); i++)
        {
            
digit[i] = txt.charAt(i);
        }
        return 
digit;
    }
    public static 
int getSum(int[] digit)
    {
        
int doubleEven [] = new int[digit.length 2];
        
int sum 0;
        for (
int i 10digit.length+= 2j++)
        {
            
doubleEven[j] = digit[i] * 2;
        }
        for (
int i doubleEven.length ;i++)
        {
            
sum += doubleEven[i];
        }
        return 
sum;
    }
    public static 
int getOddSum(int[] digit)
    {
        
int oddSum[] = new int[digit.length 2];
        
int sum 0;
        for (
int i 00digit.length+= 2j++) {
            
oddSum[j] = digit[i];
        }
        for (
int i 0oddSum.lengthi++) {
            
sum += oddSum[i];
        }
        return 
sum;
    }
    public static 
boolean isValid(int evenint odd)
    {
        
int sum even odd;
        if ((
sum 10) == ) return true;
        else return  
false;
    }


بالتوفيق .

 


التعديل الأخير تم بواسطة Mr.Ahmad ; 23-09-2010 الساعة 07:42 PM.
Mr.Ahmad غير متواجد حالياً   رد مع اقتباس
 

 

أدوات الموضوع إبحث في الموضوع
إبحث في الموضوع:

البحث المتقدم
انواع عرض الموضوع

تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة

الانتقال السريع

 


الساعة الآن 08:48 PM


Powered by vBulletin® Version 3.8.9 Beta 3
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Ads Organizer 3.0.3 by Analytics - Distance Education

أن كل ما ينشر في المنتدى لا يمثل رأي الإدارة وانما يمثل رأي أصحابها

جميع الحقوق محفوظة لشبكة سكاو

2003-2025