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: