Answer to Question #312635 in Java | JSP | JSF for GEO

Question #312635

Write an application that allows the user to select from a menu a checking account (1) and a savings account (2) (The balance of these two account should be generated automatically by the program within this range 1 to 100 rand and stored into an array ). Compare the two balances and Display the message “Checking account balance is low” if the checking account balance is less than R10 do the same for the saving account. Again, display the message “Savings account balance is lower or greater then the checking account and visa versa . Save the file as Balance.java.

1. Use of a random function

2. use of an array to store the generated balance

3. use of an if statement

4 . Display of correct output


1
Expert's answer
2022-03-16T10:23:15-0400


import java.util.*;


class Balance {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		int generatedBalances[] = new int[2];
		Random r = new Random();
		generatedBalances[0] = r.nextInt(100) + 1;
		generatedBalances[1] = r.nextInt(1000) + 1;
		System.out.println("1. Display checking account balance");
		System.out.println("2. Display savings account balance");
		System.out.print("Your choice: ");
		int choice = keyboard.nextInt();


		if (choice == 1) {
			if (generatedBalances[0] < 10) {
				System.out.println("Checking account balance is low");
			} else {
				System.out.println("Checking account balance is " + generatedBalances[0]);
			}
		} else {
			if (generatedBalances[1] < 100) {
				System.out.println("Savings account balance is low");
			} else {
				System.out.println("Savings account balance is " + generatedBalances[1]);
			}
		}


		keyboard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS