Ask Question
15 September, 21:20

Suppose you write the following program that prompts the user to enter the current year tuition and finds out how many years the tuition will be doubled. There is an error in the highlighted line. Fix it. You don't need to write the complete new program, just circle the affected code and replace it with the new code.

import java. util. Scanner;

public class Test {

public static void main (String[] args) {

Scanner input = new Scanner (System. in);

System. out. print ("Enter the current year tuition: ");

double tuition = input. nextDouble ();

int year = 0;

while (tuition < 2 * tuition) {

tuition = tuition * 1.07; year++;

}

System. out. println ("Tuition will be doubled in " + year + " years"); System. out. printf ("Tuition will be $%.2f in %1d years ", tuition, year);

}

}

fyi:highlighted line is [while (tuition < 2 * tuition) ]

+1
Answers (1)
  1. 15 September, 22:49
    0
    The problem there is tuition will always be less than tuition * 2, a better solution would be to make a variable for doubleTuition, and compare to that value in loop.

    example:

    double tuition;

    int year = 0;

    double doubleTuition = tuition * 2

    while (tuition < doubleTuition) {

    tuition = tuition * 1.07;

    year++;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Suppose you write the following program that prompts the user to enter the current year tuition and finds out how many years the tuition ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers