I made an atm program in java. Overall, it works. However, I'm trying to have it print "You have exceeded the limit" when the user enters a successful savings and checking amount. I use an if statement to do this. However, I'm not sure if it can generate the "You have exceeded the limit" print. I'm new to learning java so please bear with me.
package atm; import java.util.Scanner; public class atm { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int checking = 1000, savings = 5000, withdrawal = 0, deposit = 0; System.out.println("======================"); System.out.println("Welcome to Sound Bank!"); System.out.println("======================"); while (true) { System.out.println("Please select which options: \n (C)Checking Balance \n (S)Savings"); String choice1 = cin.nextLine(); System.out.println("Please select of the following: "); System.out.println("(D)Deposit \n (W)Withdrawal \n (B)Check Balance \n (E)Exit"); String choice2 = cin.nextLine(); switch(choice2.toUpperCase()) { case "D": if (choice1.equalsIgnoreCase("C")) { System.out.println("Enter your deposit amount:"); double num = cin.nextDouble(); double total = checking + num; System.out.println("You entered" + num); System.out.println("You have" + total); if(num > checking) { System.out.println("You are over the limit."); } } else if (choice1.equalsIgnoreCase("S")) { System.out.println("Enter your deposit amount"); double num1 = cin.nextDouble(); double total1 = savings + num1; System.out.println("You entered" + num1); System.out.println("You have" + total1); if(num1 > savings) { System.out.println("You are over the limit."); } } break; case "W": if (choice1.equalsIgnoreCase("C")) { System.out.println("Enter your withdrawal amount:"); double w = cin.nextDouble(); double total2 = checking - w; System.out.println("You entered" + w); System.out.println("You have" + total2); if(w > checking) { System.out.println("You are over the limit."); } } else if (choice1.equalsIgnoreCase("S")) { System.out.println("Enter your withdrawal amount:"); double w2 = cin.nextDouble(); double total3 = cin.nextDouble(); System.out.println("You entered " + w2); System.out.println("You have" + total3); if(w2 > savings) { System.out.println("You are over the limit."); } } break; case "B": if (choice1.equalsIgnoreCase("C")) { double t1 = (checking + deposit) - withdrawal; System.out.println("Your total amount is:" + t1); } else if (choice1.equalsIgnoreCase("S")) { double t2 = (savings + deposit) - withdrawal; System.out.println("Your total amount is:" + t2); } break; case "E": System.exit(0); break; } } } }
Correct answer
The question is not very clear. But I assume your problem has been solved
double w2 = cin.nextDouble();
double Total3 = cin.nextDouble();
with
double w2 = cin.nextDouble();
double Total3 = Savings - w2;
It should work as expected.
The above is the detailed content of Print successful amount statement on if statement. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
