Question

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

File: HW2_BankTable.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 2.
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 (so if you just add the transaction, it will do teh correct computation for both positive/deposit and negative/removal transactions)
Print the data as a table. Use System.out.printf and reserve a minimum number of spaces to ensure the table stays aligned. Count the - to see how many spaces to reserve.

This program will simulate 2 bank transactions.
Enter the original amount of money in the bank: 100.03
Enter the 1st transaction: 1000.2
Enter the 2nd transaction: 36
---------------------------
| Transaction |  Account  |
|             |    100.03 |
|     1000.20 |   1100.23 |
|       36.00 |   1136.23 |
---------------------------

Sample run 2:

This program will simulate 2 bank transactions.
Enter the original amount of money in the bank: 10023
Enter the 1st transaction: -56
Enter the 2nd transaction: 90.3
---------------------------
| Transaction |  Account  |
|             |  10023.00 |
|      -56.00 |   9967.00 |
|       90.30 |  10057.30 |
---------------------------
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*PROGRAM */

/* import scanner class with util package */
import java.util.Scanner;
/* import package for decimal point selection to format decimal number */
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class HW2_BankTable
{
public static void main(String args[])
{
    double amt,t1,t2,amt1,amt2;
       int c=0;
       int l,i;   
       /* Application of scanner class */
       /* sc is the object of scanner class */
       /* sc is used to take input from console */
       Scanner sc=new Scanner(System.in);
       /* after point two decimal value and last digit will be 0 */
       DecimalFormat ob = new DecimalFormat("##.00");
   /* taking all values from console */
       System.out.print("\nEnter the original amount of money in the bank: ");
       amt=sc.nextDouble();
       System.out.print("\nEnter the 1st transaction: ");
       t1=sc.nextDouble();
       System.out.print("\nEnter the 2nd transaction: ");
       t2=sc.nextDouble();
       amt1=amt+t1;
       amt2=amt1+t2;
       /* print the result as formated tabular format according to
       output format */
       String name="| Transaction | Account |";
       /* no of "-" according to the length of table header */
       /* it helps to use minimum space */
l=name.length();
       /* table formating structure */
System.out.print(" ");
       for(i=0;i<l;i++)
       {
          
           System.out.print("-");
}
System.out.println();
System.out.print(" ");      
       System.out.println(name);
       System.out.println(" | | " + ob.format(amt) + "|" );
       System.out.println(" | " + ob.format(t1) + "| " + ob.format(amt1) + "|" );
       System.out.println(" | " + ob.format(t2) + "| " + ob.format(amt2) + "|" );
       System.out.print(" ");
       for(i=0;i<l;i++)
       {
          
           System.out.print("-");
          
}
      
      
   }
}  
      
      
SCREEN SHOT

/* import scanner class with util package */ import java.util.Scanner; /* import package for decimal point selection to forma

/* table formating structure */ System.out.print( ); for(i=0;i<l;i++) System.out.print(-); System.out.println(); System.o

OUTPUT

C:\Program Files\Java\jdk1.8.0_131\bin>javac HW2_BankTable.java C:\Program Files\Java\jdk1.8.0_131\bin>java HW2_BankTable Ent

Add a comment
Know the answer?
Add Answer to:
File: HW2_BankTable.java Write a program that simulates 2 bank transactions. The user will enter: the original...
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
  • This is a Java program Write a program that reads an unspecified number of integers, determines...

    This is a Java program Write a program that reads an unspecified number of integers, determines home many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number to 2 decimal places. System.out.println(countPositive); System.out.println(countNegative); System.out.println(total); System.out.printf("%.2f",total * 1.0 / count); Assume inputs are always integer [-912985158, 912985158] and ends with 0. Input 1 2 -1 3...

  • Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your l...

    Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer...

  • Write a Python program which simulates how a bank account works. (1) create a global constant...

    Write a Python program which simulates how a bank account works. (1) create a global constant INTEREST_RATE as the interest rate, which is assigned value 0.01. (2) create a global variable balance, which is initialized to 1000. (3) define a function named deposit which takes no parameter, it asks user to enter the amount of money that will be deposited into this account, then updates the global variable balance (which should increase by the amount of the deposit) and prints...

  • In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that...

    In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that represents an annual salary for employees. This program should all be written in the main driver program no additional classes are needed. Your program should do the following: Prompt the user for a salary continually until the user enters a sentinel value, a negative number. Keep two running totals the first is the total of all original salaries and the second is a total...

  • Java project: A Bank Transaction System For A Regional Bank User Story A regional rural bank...

    Java project: A Bank Transaction System For A Regional Bank User Story A regional rural bank CEO wants to modernize banking experience for his customers by providing a computer solution for them to post the bank transactions in their savings and checking accounts from the comfort of their home. He has a vision of a system, which begins by displaying the starting balances for checking and savings account for a customer. The application first prompts the user to enter the...

  • Write a C++ program to allow the user to create a test bank of questions. The...

    Write a C++ program to allow the user to create a test bank of questions. The program should first ask the user how many questions he or she wishes to create. This quantity will be the first line in the test bank. The user should now be prompted for all information for each question, and then that question is written out to the test bank in the exact format specified in the Phase 2 Individual Project. For each question, the...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • You are to write a Java program using the following instructions to build a bank-ATM server...

    You are to write a Java program using the following instructions to build a bank-ATM server system with sockets. A bank holds accounts that can have deposits, withdrawals, or retrievals of balance. The bank server provides the account for transactions when a client uses and ATM machine. The ATM asks for the type of transaction and the amount (if needed), then creates a socket connection to the bank to send the transaction for processing. The bank performs the transaction on...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

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
ADVERTISEMENT