عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 12-05-2011, 12:44 AM   #2

زهرة البنفسج

مراقبة سابقاً

الصورة الرمزية زهرة البنفسج

 
تاريخ التسجيل: Jan 2009
التخصص: Computer Science
نوع الدراسة: إنتظام
المستوى: التاسع
الجنس: أنثى
المشاركات: 1,458
افتراضي رد: ممكن اعرف الخطأ في هذآ الكود *_^

بصراحة انا فتحته و حاولت اصحح الأخطاء اللي يظهرها الكومبايلر .....بس ماقرأته
كود PHP:
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
    
{
    }
 
    public 
Money(int dollars)    //constructor for dollars and no cents
    
{
    }    
 
        public 
Money(int dollarint cents)    //two parameter constructor
    
{
    }    
 
    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 obj)
    {
        return ((
aBuckHalf == aDollarFifty) && (hundred == cents));
    }    
 
    public 
int Moneyadd (Money m1Money m2)//you musn't put space between name of the method
        
{
 
        return (
m1.dollars m2.dollars);//the operator + can't use to add objects .you must choose the data member to add them ...
    
}    
 
    public 
int Moneyminus (Money m1Money m2)
    {
        return (
m1.dollars-m2.dollars);
    }    
 
 
    
// --------------------------------
    // --------- END USER CODE --------
    // --------------------------------
 
 
    /*
      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) + ".0" cents;
        else
            
result result Math.abs(dollars) + "." cents;
 
        return 
result;
    }
}
 
/*
  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);
         
Money c = new Money();
          
Money cN = new Money();
           
Money cn = new Money();
         
        
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 " = " +cMoneyadd(cNoteaBuckFifty));//you can't call the method with class Name you must create an objects
        
System.out.println(
            
cNote " - " +aBuckFifty " = " cn.Moneyminus(cNoteaBuckFifty));
        
Money aDebt = new Money();
        
//you can't call the method with class Name you must create an objects
        
System.out.println(nickel " - " +cNote " = " aDebt.Moneyminus(nickelcNote));
        
System.out.println(
            
aDollarFifty " - " aBuckFifty " = " cn.Moneyminus(aDollarFiftyaBuckFifty));
        
System.out.println(
            
aDollarFifty " + " aBuckFifty " = " 
           
c.Moneyadd(aDollarFiftyaBuckFifty));
        
System.out.println(
            
aDebt " + " aBuckFifty " = " 
           
c.Moneyadd(aDebtaBuckFifty));
    }
 

هذا عمل رن .....بس شوفي هل يؤدي الغرض المطلوب ....؟؟؟

 

توقيع زهرة البنفسج  

 

 

زهرة البنفسج غير متواجد حالياً   رد مع اقتباس