Answer to Question #308768 in Java | JSP | JSF for Mia

Question #308768

Write an application that prompts the user for a checking account balance and a savings account balance (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 ). Display the message “Checking account balance is low” if the checking account balance is less than R10. Display the message “Savings account balance is low” if the savings account balance is less than R100. Save the file as Balance.java.

Marks allocation 

1. Use of a random function- 5

2. use of an array to store the generated balance -5

3. use of an if statement -5

4 . Display of correct output -10

1
Expert's answer
2022-03-10T10:18:59-0500


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