Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What's wrong with this code? import java.util.Scanner; public class Account { public static void main(String[] args) { Account[] accounts = new Account[10]; for (int i

What's wrong with this code?

import java.util.Scanner;

public class Account {

public static void main(String[] args) { Account[] accounts = new Account[10]; for (int i = 0; i < 10; i++) { accounts[i] = new Account(i, 100); } double annualInterestRate = 4.5; for (Account account : accounts) { account.setAnnualInterestRate(annualInterestRate); }

Scanner input = new Scanner(System.in); int id = getId(input); int choice = getChoice(input); while (choice != 5) { switch (choice) { case 1: System.out.println("The balance is " + accounts[id].getBalance()); break; case 2: System.out.print("Enter an amount to withdraw: "); double amount = input.nextDouble(); accounts[id].withdraw(amount); break; case 3: System.out.print("Enter an amount to deposit: "); amount = input.nextDouble(); accounts[id].deposit(amount); break; case 4: accounts[id].printSummary(); break; default: System.out.println("Invalid choice."); break; } choice = getChoice(input); } input.close(); }

public static int getId(Scanner input) { while (true) { System.out.print("Enter an id: "); int id = input.nextInt(); if (id >= 0 && id <= 9) { return id; } System.out.println("Invalid id."); } }

public static int getChoice(Scanner input) { System.out.println("Main menu"); System.out.println("1: check balance"); System.out.println("2: withdraw"); System.out.println("3: deposit"); System.out.println("4: print summary"); System.out.println("5: exit"); System.out.print("Enter a choice: "); int choice = input.nextInt(); return choice; } }

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago