12-05-2011, 01:17 AM
|
#3
|
تاريخ التسجيل: 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 aBuckFifty, aDollarFifty, aBuckHalf; 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 dollar, int 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 amount1, Money amount2) { Money temp = new Money(); temp.setDollars(amount1.getDollars() + amount2.getDollars()); temp.setCents(amount1.getCents() + amount2.getCents()); return temp; } static Money minus(Money amount1, Money 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(1, 50); 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(cNote, aBuckFifty)); System.out.println( cNote + " - " + aBuckFifty + " = " + Money.minus(cNote, aBuckFifty)); Money aDebt = Money.minus(nickel, cNote); System.out.println(nickel + " - " + cNote + " = " + aDebt); System.out.println( aDollarFifty + " - " + aBuckFifty + " = " + Money.minus(aDollarFifty, aBuckFifty)); System.out.println( aDollarFifty + " + " + aBuckFifty + " = " + Money.add(aDollarFifty, aBuckFifty)); System.out.println( aDebt + " + " + aBuckFifty + " = " + Money.add(aDebt, aBuckFifty)); } }
|
|
سبحان الله وبحمد ,,, سبحان الله العظيم الحمد لله كما ينبغي لجلال وجهه وعظيم سلطانه . اللهم صل على محمد وعلى آل محمد كما صليت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد . اللهم بارك على محمد وعلى آل محمد كما باركت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد.
|
|
|
|