Answer to Question #229813 in Java | JSP | JSF for Jaden

Question #229813

Create a program where you have to design your own Java console application about any valid problem that your application must solve. Your solution can include solving a business problem, a new idea or even a game. Your application must make use of concepts such as arrays, loops, inheritance, constructors and information hiding. Output must be shown in the form of a report using the console. Use Advanced arrays & Introduction to inheritance


1
Expert's answer
2021-08-26T02:26:17-0400


package bankproblem;
import java.util.Scanner;


public class BankProblem {
private String name;
private int accountNumber;
private double balance;
public BankProblem(){
    
}
public BankProblem(String n, int acc, double ba){
    setBankDetails(n, acc, ba);
}
public void setBankDetails(String n, int acc, double ba){
    name = n;
    accountNumber = acc;
    balance = ba;
}
public String getName(){
    return name;
}
public int getAccountNumber(){
    return accountNumber;
}
public double getBalance(){
    return balance;
}
   
    public static void main(String[] args) {
        System.out.println("Enter the number of customers\n");
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        Operations [] bank = new Operations[3];
        for(int i=0; i<n; i++){
            System.out.println("Enter the details of customer "+ (i+1));
            System.out.println("Enter the customer name\n");
            String name = input.next();
            System.out.println("Enter the customer account number\n");
            int number = input.nextInt();
            System.out.println("Enter the initial balance of the customer\n");
            double bal = input.nextDouble();
            bank[i] = new Operations(name, number, bal);
            System.out.println("Enter 1 for deposit\n Enter 2 to withdraw\nEnter 0 to exit\n");
            int choice = input.nextInt();
            if(choice==1){
                System.out.println("Enter amount to deposit\n");
                double amount = input.nextDouble();
                bank[i].deposit(amount);
            }
            else if(choice == 2){
                System.out.println("Enter amount to deposit\n");
                double amount = input.nextDouble();
                bank[i].withdraw(amount);
            }
            
            
        }
    }
    
}
class Operations extends BankProblem{
    Operations(String n, int acc, double ba){
        super(n, acc, ba);
    }
    public double withdraw(double amount){
        if(amount< getBalance()){
            System.out.println("The balance is less than the amount to be withdrawn\n");
            return 0;
        }
        else{
            double bal = (getBalance()- amount);
            System.out.printf("%f withdrawn successfully.\n The remaining "
                    + "balance is %f\n", amount, bal );
            return bal;
            
        }
        
    }
    public  void deposit(double amount){
        
        double bal = (getBalance() +  amount);
            System.out.printf("%f withdrawn successfully.\n The remaining "
                    + "balance is %f\n", amount, bal );
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS