Question

In .java Write a program that simulates 2 bank transactions. The user will enter: the original...

In .java

Write a program that simulates 2 bank transactions. The user will enter: the original amount in the bank, the money for transaction 1 and the money for transaction. If a transaction has a negative number it means that money was removed from bank (an withdrawal). If a transaction has a positive number it means that money was deposited in the bank. Hint: if you add a negative number you are effectively subtracting. E.g. 100 + (-10) = 90. Sample run 1:

This program will simulate 2 bank transactions.

Enter the original amount of money in the bank: 1000.5

Enter the 1st transaction: 35 Current amount: 1035.50

Enter the 2nd transaction: -20.1

Current amount: 1015.40

The original amount was: 1000.50

Homework Answers

Answer #1
//BankTransactions.java
import java.util.Scanner;
public class BankTransactions {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double orig;
        System.out.print("Enter the original amount of money in the bank: ");
        orig = scan.nextDouble();

        double n = orig;

        System.out.print("Enter the 1st transaction: ");
        double first = scan.nextDouble();

        n = n + first;
        System.out.printf("Current amount = %.2f\n",n);

        System.out.print("Enter the 2nd transaction: ");
        double second = scan.nextDouble();

        n = n + second;
        System.out.printf("Current amount = %.2f\n",n);

        System.out.printf("The original amount was: %.2f\n",orig);
    }
}

Know the answer?
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
Similar Questions
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts.
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
Write a program that asks the user to enter a U.S. dollar amount and then shows...
Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $100, $20, $10, and $5 bills. Following are a few test cases for your program: Enter the amount for withdrawal: 125 Please collect your bills as follows: $100: 1 $20: 1 $5: 1 Enter the amount for withdrawal: 94 The amount cannot be withdrawn. Note: Be sure to use integer values throughout, not floating...
Binary Search Tree Code in Java Write a program that prompts user to enter however many...
Binary Search Tree Code in Java Write a program that prompts user to enter however many numbers they want to add to the binary search tree. Then have the user input numbers until the tree contains that many elements. If the user enters a number that already exists in the tree, then a message should be displayed "Number is already in the tree". Once all elements are added to the tree print its contents in sorted order. Assume all user...
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Write a Java program and Flowchart that prompts the user to enter two characters and displays...
Write a Java program and Flowchart that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: I: Information Management C: Computer Science A: Accounting
Write a C program that allows the user to balance a credit card account. The program...
Write a C program that allows the user to balance a credit card account. The program should first prompt the user to enter the Bank Name, and the beginning balance of his/her credit card account (must allow for dollars and cents). The program should then prompt the user to enter the number of refunds to be posted, and then the number of payments to be posted, and then the number of charges to be posted. For this assignment, let's set...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's profit (or loss) within a certain period of time. 1) First, the program need to get user's name, the stock's code, number of shares and the price he/she purchased the stock, it also asks the user for the price he/she sold the stock later on. The program then compute the following: The amount of money the customer paid for the stock. The amount of...
Question 2: write a java program    A Hypermarket makes an offer for its customers according...
Question 2: write a java program    A Hypermarket makes an offer for its customers according to the number of items to be bought as follows: Number of purchased items Discount percentage Less than 25 2.5% 25 – 50 5.0% 51 – 100 6.25% Greater than 100 7.5% The hypermarket also adds 2% city taxes to the purchases after the sale discount. Reads from the user the number of items to be purchased and the item price. Calculates and prints...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT