Write a program which prompts the user to input their name, checking account bal
ID: 3682043 • Letter: W
Question
Write a program which prompts the user to input their name, checking account balance and savings account balance. If the checking account balance is below $10, the checking account balance is too low. If the savings account balance is below $100, the savings account balance is too low. Depending upon the values input by the user, display the name and one of the following messages: Your checking account balance (actual value) is too low. (For example, “Your checking account balance ($4.19) is too low.”) Your savings account balance (actual value) is too low. Both your checking (actual value) and savings (actual value) account balances are dangerously low. Both your checking (actual value) and savings (actual value) accounts are in good shape. Save the class as Balance.java
Explanation / Answer
import java.util.Scanner;
/**
* @author srinu
*
*/
public class Balance {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
System.out.print("Enter the name :");
String name = scanner.nextLine();
System.out.print("Enter the Account Balance:");
double accBal = scanner.nextDouble();
System.out.print("Enter the Savings Balance:");
double savingsBal = scanner.nextDouble();
System.out.println(name);
if (accBal < 10.00d) {
if (savingsBal < 100.00d) {
System.out.println("($" + accBal + ") and savings ($"
+ savingsBal
+ ") account balances are dangerously low");
} else {
System.out.println("Your checking account balance ($"
+ accBal + ") is too low.");
}
} else if (savingsBal < 100.00d) {
System.out.println("Your savings account balance ($"
+ savingsBal + ") is too low");
} else {
System.out.println(" ($" + accBal + ") and savings ($"
+ savingsBal + ") accounts are in good shape");
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Test 1:
Enter the name :Srinivas Palli
Enter the Account Balance:400
Enter the Savings Balance:500
Srinivas Palli
($400.0) and savings ($500.0) accounts are in good shape
Test 2:
Enter the name :Rajesh
Enter the Account Balance:4.28
Enter the Savings Balance:123.54
Rajesh
Your checking account balance ($4.28) is too low.
Test 3:
Enter the name :Kishore Kumar
Enter the Account Balance:12.34
Enter the Savings Balance:54.54
Kishore Kumar
Your savings account balance ($54.54) is too low
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.