Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java- I need help adding a loop to my program Description : Let's simply add a LOOP structure, so that we can continue to create

Java- I need help adding a loop to my program

Description: Let's simply add a LOOP structure, so that we can continue to create customer Bank Accounts until a sentinel value (loop control variable) (refer to section 5.5) is entered. if we enter "STOP" for the name the program ends, otherwise we continue to create customer bank accounts.

My Code below:

package javaPrac; import java.util.Scanner; public class Accounts { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter your first name"); String fName = sc.nextLine().toUpperCase(); System.out.println("Enter your last name"); String lName = sc.nextLine().toUpperCase(); System.out.println("Enter the type of account you want to open: Savings or Checking? "); String accType = sc.nextLine(); String checkingAc=""; double checkingDeposit = 0; if (accType.equalsIgnoreCase("Savings")) { checkingAc = checkingAc + 0; } else if (accType.equalsIgnoreCase("Checking")) { int randomNum = (int) (Math.round(Math.random()*10000)+1); checkingAc = randomNum + " " + "Checking"; System.out.println("Enter the initial deposit in checking account: "); checkingDeposit = sc.nextDouble(); } String savingsAc = (Math.round(Math.random()*10000)+1) + " " + "Savings"; System.out.println("Enter the initial deposit in savings account: "); double savingDeposit = sc.nextDouble(); if (savingDeposit<=100) { System.out.println("no accounts opened - initial deposit requirements not met."); } else { double interestRate; double balance = 0; if(savingDeposit<=100) { System.out.println("Initial deposit in savings account must be over $100. "); balance = savingDeposit; } else if(savingDeposit>100 && savingDeposit<=500) { interestRate = 0.035; balance = savingDeposit + savingDeposit*interestRate; } else if(savingDeposit>500 && savingDeposit<=1000) { interestRate = 0.045; balance = savingDeposit + savingDeposit*interestRate; } else { interestRate = 0.05; balance = savingDeposit + savingDeposit*interestRate; } System.out.println("Name: "+fName +"," +lName); System.out.println("Acct: "+checkingAc+"\t Acct: "+ savingsAc+"\t Estimated Savings balance in 1 Year"); System.out.println("deposit: $"+checkingDeposit+ "\t deposit: $"+savingDeposit+"\t $"+balance); if (Math.max(savingDeposit, checkingDeposit)==savingDeposit) { System.out.println("Savings account has the higher initial deposit"); } else { System.out.println("Checking account has the higher initial deposit"); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Why is a Notice necessary before a meeting? Section B

Answered: 1 week ago