Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Looking for some examples in Java programming using object oriented examples to

ID: 3579827 • Letter: L

Question

Looking for some examples in Java programming using object oriented examples to help study for my final Below is what the instructor is looking for: The exam will be a coding exam where you will create a bank account class, The BankAccount class will have: an accountNumber variable (int), a balance variable (double), firstName variable as a String lastName variable as a String. I will give you the specifications in class, however there is enough above to create all your "getter" and "setter" methods plus a couple of constructors. Plus... drop a main method in your class so you can test it.

Explanation / Answer

Hi, Please find my implementation of BankAccount class.

Please let me know in case of any issue.

public class BankAccount {

  

   // instance variables

   private int accountNumber;

   private double balance;

   private String firstName;

   private String lastName;

  

   // constructors

   public BankAccount(int accNo, String firstName, String lastName, double bal) {

       accountNumber= accNo;

       this.firstName = firstName;

       this.lastName = lastName;

       balance= bal;

   }

  

   public BankAccount(int accountNo){

       accountNumber = accountNo;

       firstName = "";

       lastName = "";

       balance = 0.0;

   }

  

   // setters and getters

   public int getAccountNumber() {

       return accountNumber;

   }

   public double getBalance() {

       return balance;

   }

   public void setBalance(double balance) {

       this.balance = balance;

   }

   public String getFirstName() {

       return firstName;

   }

   public void setFirstName(String firstName) {

       this.firstName = firstName;

   }

   public String getLastName() {

       return lastName;

   }

   public void setLastName(String lastName) {

       this.lastName = lastName;

   }

  

   public void withdraw(double amount){

       if(amount > balance){

           System.out.println("Insufficient Balance!!");

           return;

       }

      

       balance = balance - amount;

   }

  

   public void deposite(double amount){

       balance = balance +amount;

   }

  

   @Override

   public String toString() {

       return "Account Number: "+accountNumber+" "+

               "First Name: "+firstName+" "+

               "Last Name: "+lastName+" "+

               "Balance: $"+balance+" ";

   }

  

  

   public static void main(String[] args) {

      

       // creating BankAccount Object

       BankAccount acc = new BankAccount(1212343);

      

       acc.setFirstName("Pravesh");

       acc.setLastName("Kumar");

      

       acc.deposite(5432.34);

      

       System.out.println(acc);

      

       acc.withdraw(2000);

      

       System.out.println(acc);

      

      

   }

}

/*

Sample run:

Account Number: 1212343

First Name: Pravesh

Last Name: Kumar

Balance: $5432.34

Account Number: 1212343

First Name: Pravesh

Last Name: Kumar

Balance: $3432.34

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote