Question
using BlueJ “jave program” please
Exercise P3.1. Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class BankAccount {

   private double balance;
   // deposits the amount to the bank
   public void deposit(double aBalance) {

       balance += aBalance;

   }
   // withdraws amount from the bank
   public void withdraw(double aAmount) {

       //checking if amount is valid
       if (aAmount <= balance && aAmount > 0) {

           balance -= aAmount;

       } else {

           System.out.println("Not valid amount");

       }

   }
   public double get() {

       return balance;

   }

}

public class BankAccountTester {

   public static void main(String[] args) {

       int ch = 0;

       double amount = 0;

       BankAccount b = new BankAccount();

       Scanner sc = new Scanner(System.in);

       do {
           // displaying menu to user
           System.out.println("-----------");
           System.out.println("1 Deposit");

           System.out.println("2 Withdraw");

           System.out.println("3 Print");

           System.out.println("4 Quit");
           System.out.println("-----------");
           System.out.println("Your choice: ");
           //reading user choic
           ch = sc.nextInt();

           switch (ch) {

           case 1:
               //reading amount
               System.out.println("Amount");

               amount = sc.nextDouble();
               //calling deposit

               b.deposit(amount);

               break;

           case 2:
               //reading amount

               System.out.println("Amount");
               //calling withdraw

               amount = sc.nextDouble();

               b.withdraw(amount);

               break;

           case 3:

               System.out.println("Your balance : " + b.get());

               break;

           case 4:
               ch=10;

               break;


           }

       } while (ch <4);
       System.out.println("Thank you");

   }

}

Your choice: 1 Amount 1000 1 Deposit 2 Withdraw 3 Print 4 Quit Your choice: 2 Amount 500 1 Deposit 2 Withdraw 3 Print 4 Quit

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
using BlueJ “jave program” please Exercise P3.1. Write a BankAccountTester class whose main method constructs a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Week 4 Write a BankAccount Tester class whose main method constructs a bank account, deposits $1,000,...

    Week 4 Write a BankAccount Tester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result. Submit a screenshot of the code and output Note*: You need to have two files to run this program. BankAccount and BankAccountTester. BankAccount class is provided BankAccount.java

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • C++ Simple code please Thank you in advance B. Write a C++ program as per the...

    C++ Simple code please Thank you in advance B. Write a C++ program as per the following specifications: a. Define the class BankAccount to store a bank customer's account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank...

  • Write a program called CountFlips whose main method flips a coin 100 times and counts how...

    Write a program called CountFlips whose main method flips a coin 100 times and counts how many times each side comes up. Make sure to include comments of what is being done in the code. Verify whether the head comes up or not by calling isHeads method of Coin class. Increment the heads count if head comes up. Increment the tails count if tail comes up. Display the head and tails counts. Print the results SEND AS A TEXT FILE...

  • Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.

    Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • Write a parser program for cSub using the method of recursive descent. The main program here...

    Write a parser program for cSub using the method of recursive descent. The main program here will effectively be the main program of the compiler as a whole. The input to the program will be a Csub source file, specified on the command line. The program will construct a parse tree for the program, with one interior node for every nonterminal in the derivation of the program, and one leaf node for each of the id, num, and real tokens...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT