InstagramTwitterSnapChat


 
وصف

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


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

ممكن اعرف الخطأ في هذآ الكود *_^

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

 
 
أدوات الموضوع إبحث في الموضوع انواع عرض الموضوع
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 12-05-2011, 01:17 AM   #3

Mr.Ahmad

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

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

 
تاريخ التسجيل: Jul 2008
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: IT
نوع الدراسة: عضو هيئة تدريس
المستوى: متخرج
البلد: جــــدة
الجنس: ذكر
المشاركات: 2,477
افتراضي رد: ممكن اعرف الخطأ في هذآ الكود *_^

السلام عليكم ورحمة الله وبركاته .

تصحيح أخطاء اللغة والأخطاء المنطقية وتعديل الكود :

الكلاس الأول :
كود PHP:
/*
Class representing an amount of U.S. money
 */
public class Money {
    
/*
    Dollars in this amount of money. If the instance represents a
    negative amount of money, dollars should be negative.
     */
    
private int dollars;
    
/*
    Cents in this amount of money. In this implementation, cents should
    always be non-negative.
     */
    
private int cents;
    
// --------------------------------
    // ----- ENTER YOUR CODE HERE -----
    // --------------------------------
    
private int hundred;        //Dollars and cents in this amount of money.
    
private int aBuckFiftyaDollarFiftyaBuckHalf;
    public 
Money() //no argument constructor
    
{
        
this.dollars 0;
        
this.cents 0;
    }
    public 
Money(int dollars//constructor for dollars and no cents
    
{
        
this.dollars dollars;
    }
    public 
Money(int dollarint cents//two parameter constructor
    
{
        
this.dollars dollar;
        
this.cents cents;
    }
    public 
int getDollars() {
        return 
dollars;
    }
    public 
void setDollars(int dollars) {
        
this.dollars dollars;
    }
    public 
int getCents() {
        return 
cents;
    }
    public 
void setCents(int cents) {
        
this.cents cents;
    }
    public 
boolean equals(Money amount) {
        return ((
this.dollars == amount.getDollars()) && (this.cents == amount.getCents()));
    }
    public 
Money add(Money m) {
        
Money temp = new Money();
        
temp.setDollars(this.dollars m.dollars);
        
temp.setCents(this.cents m.cents);
        return 
temp;
    }
    public 
Money minus(Money m) {
        
Money temp = new Money();
        
temp.setDollars(this.dollars m.dollars);
        
temp.setCents(this.cents m.cents);
        if (
temp.getCents() != 0) {
            
temp.setDollars(temp.getDollars() - 1);
        }
        return 
temp;
    }
    static 
Money add(Money amount1Money amount2) {
        
Money temp = new Money();
        
temp.setDollars(amount1.getDollars() + amount2.getDollars());
        
temp.setCents(amount1.getCents() + amount2.getCents());
        return 
temp;
    }
    static 
Money minus(Money amount1Money amount2) {
        
Money temp = new Money();
        
temp.setDollars(amount1.getDollars() - amount2.getDollars());
        
temp.setCents(amount1.getCents() - amount2.getCents());
        if (
temp.getCents() != 0) {
            
temp.setDollars(temp.getDollars() - 1);
        }
        return 
temp;
    }

    
/*
    Returns a string representation of this objects amount
     */
    
public String toString() {
        
// Note that we could use a DecimalFormat object here instead
        // of doing this test.
        
String result;
        if (
dollars 0) {
            
result "-$";
        } else {
            
result "$";
        }
        if (
cents 10) {
            
result result Math.abs(dollars) + "." Math.abs(cents);
        } else {
            
result result Math.abs(dollars) + "." cents;
        }
        return 
result;
    }
}
// --------------------------------
// --------- END USER CODE --------
// --------------------------------a 

الكلاس الثاني :
كود PHP:

/*
Test class for exercising the methods of the Money class
 */
public class MoneyDemo {
    public static 
void main(String[] args) {
        
// Test the no-arg constructor, setter methods, and toString
        
Money nickel = new Money();
        
nickel.setCents(5);
        
System.out.println("A nickel: " nickel);
        
Money aBuckFifty = new Money();
        
aBuckFifty.setDollars(1);
        
aBuckFifty.setCents(50);
        
System.out.println("A buck fifty: " aBuckFifty);
        
// Test the one- and two-argument constructors
        
Money cNote = new Money(100);
        
System.out.println("A C-Note: " cNote);
        
Money aDollarFifty = new Money(150);
        
System.out.println("One dollar and fifty cents: " aDollarFifty);
        
// Test for equality
        
System.out.println("C-Note equals a nickel? " cNote.equals(nickel));
        
System.out.println("A buck fifty equals one dollar and fifty cents? "
                
aBuckFifty.equals(aDollarFifty));
        
// Test add and minus methods
        
System.out.println();
        
System.out.println(
                
cNote " + " aBuckFifty " = " Money.add(cNoteaBuckFifty));
        
System.out.println(
                
cNote " - " aBuckFifty " = " Money.minus(cNoteaBuckFifty));
        
Money aDebt Money.minus(nickelcNote);
        
System.out.println(nickel " - " cNote " = " aDebt);
        
System.out.println(
                
aDollarFifty " - " aBuckFifty " = "
                
Money.minus(aDollarFiftyaBuckFifty));
        
System.out.println(
                
aDollarFifty " + " aBuckFifty " = "
                
Money.add(aDollarFiftyaBuckFifty));
        
System.out.println(
                
aDebt " + " aBuckFifty " = "
                
Money.add(aDebtaBuckFifty));
    }

 

توقيع Mr.Ahmad  

 

سبحان الله وبحمد ,,, سبحان الله العظيم
الحمد لله كما ينبغي لجلال وجهه وعظيم سلطانه .
اللهم صل على محمد وعلى آل محمد كما صليت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد . اللهم بارك على محمد وعلى آل محمد كما باركت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد.

 

Mr.Ahmad غير متواجد حالياً   رد مع اقتباس
 

 


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

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

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

 


الساعة الآن 10:32 AM


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