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

1: Problem Description: JAVA (The Account class) Design a class named Account th

ID: 3672455 • Letter: 1

Question

1: Problem Description: JAVA (The Account class) Design a class named Account that contains: • A private String data field named id for the account (default “00000000”). • A private double data field named balance for the account (default 0.0). • A private String data field named name that stores the student’s full name (default “”). • A private String data field named address that stores the student’s home address (default “”). • A no-arg constructor that creates a default Account. • A constructor that creates an Account with the specified id, initial balance, name, and address. • The getter and setter methods for balance. • A method named withdraw that withdraws (subtracts) a specified amount from the balance. • A method named deposit that deposits (adds) a specified amount to the balance. • A method named clear that clears the balance (sets it to 0.0).

2: Write a test program that creates an Account object with an account ID of 00455420, a balance of $100.50, a name of “David Howe”, and an address of “125 11th St” Use the withdraw method to withdraw $4.50, use the deposit method to deposit $7.75, and use the clear method to set the balance back to 0.0. Use the getter for your balance field to print this balance value after object creation, after the withdrawal, and after the deposit.

Explanation / Answer


public class Account
{
   private double balance;
   private String id;
   private String name;
   private String address;

   public Account() {
       this.balance = 0.0;
       this.id = "00000000";
       this.name = "";
       this.address = "";
   }
  
   public Account(double balance, String id, String name,String address) {
       this.balance = balance;
       this.id = id;
       this.name = name;
       this.address = address;
   }

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

   public void withdraw(double amount)
   {
       if((balance-amount) < 0)
           System.out.println("Insufficient Balance");
       else
           balance = balance - amount;
   }

   public double getBalance()
   {
       return balance;
   }

   public void setBalance(double balance) {
       this.balance = balance;
   }

   public void clear(){
       this.balance = 0.0;
   }
  
}

class Driver{
   public static void main(String[] args) {
       Account a1 = new Account(100.50,"00455420", "David Howe", "125 11th St");
      
       a1.withdraw(4.50);
       System.out.println("Balance: "+a1.getBalance());
       a1.deposit(7.75);
       System.out.println("Balance: "+a1.getBalance());
       a1.clear();
       System.out.println("Balance: "+a1.getBalance());
   }
  
}

/*

OUTPUT:

Balance: 96.0
Balance: 103.75
Balance: 0.0

*/

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