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

ووين الغلط بهذا الكود!

بدأه *en* في 17 أكتوبر 2010 · 5 رد · 469 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Q5) write a java program that will be used by customers of a Bank to deposit or withdraw an amount

of money. Your program will consist of two classes: Bank and BankApplication. Class Bank has two

instance variables: account Number (type int) and balance (type double). In addition to the

constructor, set and get methods, the class has the following methods:

1) public void deposit(double amount)

//This method will add the amount to the balance.

2) public void withdraw(double amount)

//This method will debit the amount from the balance.

The program will start by displaying a welcome message and the available balance. The program

should ask the customer for his choice: deposit or withdraw an amount. The user then has to enter

the amount. At the end, the program should display the account number and the available balance for

this customer.

Create object of class Bank and initialize it with the following values:

account number= 552211 balance = 3000.500

Sample output:

Welcome to our Bank

You have 3750.900 KD

Enter:

1: for deposit

2: for withdraw

2

Enter the amount:

1500

The available balance of your account 552211 is 2250.900

الكووووووووووووووووووووود للسؤال

import java.util.Scanner;



public class BankApplication {




	public static void main(String[] args){
		int am;

	Scanner input = new Scanner(System.in);


	System.out.println("Welcome to our Bank ");

	Bank r1 = new Bank(552211,3750.900);

	r1.setbalance(3750.900);

	System.out.printf("you have %.3f KD",r1.getbalance());

	System.out.println("Enter: ");

	System.out.println("1: for deposit");

	System.out.println("2: for withdraw");

	int choice = input.nextInt();

	if (choice == 1){

		r1.deposit(am);
	    r1. setaccountnumber(552211);


	System.out.print("The available balance of your account ");
	System.out.print(r1.getaccountnumber());
	System.out.printf(" is %.3f ",r1.deposit(am));

	}
	else
	{
		r1.withdraw(am);

		r1. setaccountnumber(552211);


		System.out.printf("The available balance of your account %d is %.3f",r1.getaccountnumber(),r1.withdraw(am));

	}



	}	

}

الغلط بهذا الكود فقط

............................................................

هذا مافيه غلط

import java.util.Scanner;


public class Bank {

   private int accountNumber;
   private double balance;
   Scanner input = new Scanner(System.in);

   public Bank (int an,double b){

	   accountNumber = an;
	   balance = b;

   }
   public void setaccountnumber (int an){
	   accountNumber = an;

   }

   public void setbalance (double b){
	   balance = b;

   }
   public int getaccountnumber (){
	   return accountNumber;

   }
   public double  getbalance (){
	   return balance;

   }

   public void deposit(double amount){



	   System.out.println("Enter the amount:");
	   amount = input.nextDouble();

	   amount += balance;
   }

   public void withdraw(double amount){


	   System.out.println("Enter the amount:");
	   amount = input.nextDouble();
	   amount -= balance;



   }
}

بليييييييييييييز باجر أخر يوم تسليم

:mellow: :mellow:

بليييييييييييييز باجر أخر يوم تسليم

:mellow: :mellow:

#2
/**
 *
 * @author Mahmoud Kelany
 */
import java.util.Scanner;

public class Bank {

    private int accountNumber;
    private double balance;
    Scanner input = new Scanner(System.in);

    public Bank(int an, double b) {
        accountNumber = an;
        balance = b;
    }

    public void setaccountnumber(int an) {
        accountNumber = an;
    }

    public void setbalance(double b) {
        balance = b;
    }

    public int getaccountnumber() {
        return accountNumber;
    }

    public double getbalance() {
        return balance;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public void withdraw(double amount) {
        balance -= amount;
    }
}

import java.util.Scanner;

/**
 *
 * @author Mahmoud Kelany
 */
public class BankApplication {

    public static void main(String[] args) {
        double am = 0;
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to our Bank ");
        Bank r1 = new Bank(552211, 3750.900);
        r1.setbalance(3750.900);
        System.out.printf("you have %.3f KD%n", r1.getbalance());
        System.out.println("Enter: ");
        System.out.println("1: for deposit");
        System.out.println("2: for withdraw");
        int choice = input.nextInt();
        if (choice == 1) {
            System.out.println("Enter the deposit amount:");
            am = input.nextDouble();
            r1.deposit(am);
            r1.setaccountnumber(552211);
            System.out.print("The available balance of your account ");
            System.out.print(r1.getaccountnumber());
            System.out.printf(" is %.3f %n", r1.getbalance());
        } else {
            System.out.println("Enter the withdraw amount:");
            am = input.nextDouble();
            r1.withdraw(am);
            r1.setaccountnumber(552211);
            System.out.printf("The available balance of your account %d is %.3f%n", r1.getaccountnumber(), r1.getbalance());
        }
    }
}

الخطأ عندك فى الدوال withdraw , deposit

فى تعريفهم واستدعائهم

بالتوفيق:)

Software Developer
Mahmoudkelany.com


 

#3

حاجه اضافيه بس يا ريت لو تعمليها

انتى لم تيجى تسحبى من هذا الحساب قيمه اكبر من الموجوده به

المفروض هيطلع ان الحساب بالسالب

المفروض يطلع للمستخدم ان رصيدك غير كافى لسحب هذا المبلغ

حاولى فيها وان شاء الله نساعدك ان لزم الامر

Software Developer
Mahmoudkelany.com


 

#4

yes................ :wink:

وأخيراً طلع معاااااااااااي الكود صح ونفس الoutput اللي حاااااااااااااااااااااااااااااااطه الدكتووووووووووووووور

مشكووووور ويزاك الله خير أخي الكريم

ربي يوفق دنيا وأخره

:)

import java.util.Scanner;


public class BankApplication {

    public static void main(String[] args) {
        double am = 0;
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to our Bank ");
        Bank r1 = new Bank(552211, 3750.900);
        r1.setbalance(3750.900);
        System.out.printf("you have %.3f KD%n", r1.getbalance());
        System.out.println("Enter: ");
        System.out.println("1: for deposit");
        System.out.println("2: for withdraw");
        int choice = input.nextInt();
        if (choice == 1) {

            r1.deposit(am);
            r1.setaccountnumber(552211);
            System.out.print("The available balance of your account ");
            System.out.print(r1.getaccountnumber());
            System.out.printf(" is %.3f %n", r1.getbalance());
        } else {

            r1.withdraw(am);
            r1.setaccountnumber(552211);
            System.out.printf("The available balance of your account %d is %.3f%n", r1.getaccountnumber(), r1.getbalance());
        }
    }
}

هذا الكووووووووووووووووود طبعاً مع المساعده قدرت أعرف ووووووين الغلط :happy: :happy:

#5
*en* كتب:

yes................ :wink:

وأخيراً طلع معاااااااااااي الكود صح ونفس الoutput اللي حاااااااااااااااااااااااااااااااطه الدكتووووووووووووووور

مشكووووور ويزاك الله خير أخي الكريم

ربي يوفق دنيا وأخره

:)

هذا الكووووووووووووووووود طبعاً مع المساعده قدرت أعرف ووووووين الغلط :happy: :happy:

العفو

ربنا يجازينا جميعا يارب

اختى الكريمه

طريقه تصميمك للدوال

ان كنتى تردين ان تجعليها بالشكل الذى عليه مع التعديل على الخطا الموجود فى دوال الطباعه

فمن الافضل الا تجعلى لدوال الـ deposit , withdraw متغيرات

يعنى فى كل مره عند الـ am =0

وانتى لا تستفيدين به

فمن الافضل ان تجعلى الدوال هكذا

public void deposit(){
System.out.println("Enter the amount:");
amount = input.nextDouble();
 balance += amount;
}

ان اردتى ان تأخذى القيمه من المستخدم بداخل الداله

لكن هذا غير مفضل

لكن طريقه ان تأخذى القيمه وتعطيها للداله هذا المفضل دائما

كما عدلت لكى الكود هكذا

   public void deposit(double amount) {
        balance += amount;
    }

بالتوفيق :)

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 17 أكتوبر 2010 في 22:49

Software Developer
Mahmoudkelany.com


 

#6

شكراً على النصائح القيمه

بارك الله فيك

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

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

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

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

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