EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6, Problem 10PE

a.

Explanation of Solution

Program:

File name: “RetirementGoal.java

//Import necessary header files

import java.util.Scanner;

//Define a class named RetirementGoal

public class RetirementGoal

{

    //Define main method

    public static void main (String[] args)

    {

        //Create an object for the Scanner class

        Scanner input = new Scanner(System.in);

        //Declare the variables

        int years;

        int saveAmount;

        int total;

        /*Prompt the user to enter the number of years the user

        has until retirement */

System.out.print("How many years until retirement? >> ");

        years = input.nextInt();

/*While condition if the user enters 0 or a negative number*/

        while(years <= 0)

        {

            //Print the error message

            System.out.println("Years cannot be 0 or negative");

            //Reprompt the user to make a valid entry

            System...

b.

Explanation of Solution

Program:

File name: “RetirementGoal2.java

//Import necessary header files

import java.util.Scanner;

//Define a class named RetirementGoal2

public class RetirementGoal2

{

    //Define main method

    public static void main (String[] args)

    {

        //Create an object for the Scanner class

        Scanner input = new Scanner(System.in);

        //Declare the variables

        int years;

        int saveAmount;

        int total;

        final double RATE = 0.04;

        /*Prompt the user to enter the number of years the user

        has until retirement */

        System.out.print("How many years until retirement? >> ");

        years = input.nextInt();

        /*While condition if the user enters 0 or a negative number*/

        while(years <= 0)

        {

            //Print the error message

            System.out.println("Years cannot be 0 or negative");

            //Reprompt the user to make a valid entry

            System.out.print("Please renter years >> ");

            years = input.nextInt();

        } 

/*Prompt the user to enter the amount of money the user can save annually*/

        System.out.print("How much can you save annually? >> ");

        saveAmount = input.nextInt();

/*While condition if the user enters 0 or a negative number*/

        while(saveAmount <= 0)

        {

            //Print the error message

            System...

Blurred answer
Students have asked these similar questions
CIS 115 Introduction to C++ May I please have a written review expressing my gratitude for a tutor that has given me guidance throughout the computer programming course? Thank you so much!
Math 130 Introduction to Java programming May I please have a written review expressing my gratitude for a tutor that has given my guidance throughout my computer programming course? Thank you
Please help me translate the java code to jack code
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY