Question

In: Computer Science

Create a Java Program to show a savings account balance. using eclipse IDE This can be...

Create a Java Program to show a savings account balance. using eclipse IDE

This can be done in the main() method.

    1. Create an int variable named currentBalance and assign it the value of 0.
    2. Create an int variable named amountToSaveEachMonth.
    3. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2.
    4. Create an int variable name numberOfMonthsToSave.
    5. Prompt "Enter the number of months to save:" and store the input value into the variable in step 4.
    6. Create an int variable named currentSavingsMonth and assign it the value of 1.
    7. Using a while loop, do the following while the currentSavingsMonth <= numberOfMonthsToSave
    1. Add the amountToSaveEachMonth to the current balance.
    2. Display the currentSavingsMonth and the current balance
    3. Add 1 to the currentSavingsMonth

Enter amount to save each month:35
Enter the number of months to save:12
For month 1, the balance is 35
For month 2, the balance is 70
For month 3, the balance is 105
For month 4, the balance is 140
For month 5, the balance is 175
For month 6, the balance is 210
For month 7, the balance is 245
For month 8, the balance is 280
For month 9, the balance is 315
For month 10, the balance is 350
For month 11, the balance is 385
For month 12, the balance is 420

Solutions

Expert Solution

Below is your code:

import java.util.Scanner;

public class SavingsAccountDriver {
        public static void main(String[] args) {
                // initializing Scanner object to get entries from user
                Scanner sc = new Scanner(System.in);
                // Create an int variable named currentBalance and assign it the value
                // of 0.
                int currentBalance = 0;
                // Create an int variable named amountToSaveEachMonth.
                int amountToSaveEachMonth;
                // Prompt "Enter amount to save each month:" and assign the result to
                // the int variable in step 2.
                System.out.print("Enter amount to save each month:");
                amountToSaveEachMonth = Integer.parseInt(sc.nextLine());
                // Create an int variable name numberOfMonthsToSave.
                int numberOfMonthsToSave;
                // Prompt "Enter the number of months to save:" and store the input
                // value into the variable in step 4.
                System.out.print("Enter the number of months to save:");
                numberOfMonthsToSave = Integer.parseInt(sc.nextLine());
                // Create an int variable named currentSavingsMonth and assign it the
                // value of 1.
                int currentSavingsMonth = 1;
                // Using a while loop, do the following while the currentSavingsMonth <=
                // numberOfMonthsToSave
                while (currentSavingsMonth <= numberOfMonthsToSave) {
                        // Add the amountToSaveEachMonth to the current balance.
                        currentBalance = currentBalance + amountToSaveEachMonth;
                        // Display the currentSavingsMonth and the current balance
                        System.out.println("For month " + currentSavingsMonth
                                        + ", the balance is " + currentBalance);
                        // Add 1 to the currentSavingsMonth
                        currentSavingsMonth++;
                }
        }
}

Output


Related Solutions

Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
using C++ 23. Savings Account Balance Write a program that calculates the balance of a savings...
using C++ 23. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three- month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following steps: A) Ask the user for the total amount deposited into the account during that month and add it to the balance. Do not accept negative...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT