Ask Question
17 November, 13:08

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) ]

+4
Answers (1)
  1. 17 November, 13:32
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers