Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is my code and print out. How do I stop the second interest rate from prin

ID: 3674933 • Letter: B

Question

Below is my code and print out. How do I stop the second interest rate from printing?

"----jGRASP exec: java CreditScore
Enter the credit score: 822

Your Interest Rate: 5.56%
Your Interest Rate: 0%

----jGRASP: operation complete."

Start of code:

import java.util.Scanner;


public class CreditScore

{

   public static void main( String[] args )

   {

      // declare and initialize variables

      int creditScore;
      double interestRate;
           
      Scanner input = new Scanner( System.in ); // for receiving input from keyboard

      // get input from user
   
      System.out.print( "Enter the credit score: " );
      creditScore = input.nextInt();

      System.out.println(); // print blank line

       // process data

            if( creditScore >= 720 && creditScore <=850 )
               System.out.println("Your Interest Rate: 5.56%");             
            else if(creditScore >= 690 && creditScore <=719)
               System.out.println("Your Interest Rate: 6.38%");
            else if(creditScore >= 660 && creditScore <=689)
              System.out.println("Your Interest Rate: 7.12%");
            else if(creditScore >= 625 && creditScore <=689)
               System.out.println("Your Interest Rate: 9.34%");
            else if(creditScore >= 590 && creditScore <=624)
               System.out.println("Your Interest Rate: 12.45%");
            else if(creditScore >= 0 && creditScore <=589);
               System.out.println("Your Interest Rate: 0%");
                 
               
} // end main

} // end class

Explanation / Answer

import java.util.Scanner;

public class CreditScore {
   public static void main(String[] args) {
       // declare and initialize variables
       int creditScore;
       double interestRate;

       Scanner input = new Scanner(System.in); // for receiving input from
                                               // keyboard
       // get input from user

       System.out.print("Enter the credit score: ");
       creditScore = input.nextInt();
       System.out.println(); // print blank line
       // process data
       if (creditScore >= 720 && creditScore <= 850)
           System.out.println("Your Interest Rate: 5.56%");
       else if (creditScore >= 690 && creditScore <= 719)
           System.out.println("Your Interest Rate: 6.38%");
       else if (creditScore >= 660 && creditScore <= 689)
           System.out.println("Your Interest Rate: 7.12%");
       else if (creditScore >= 625 && creditScore <= 689)
           System.out.println("Your Interest Rate: 9.34%");
       else if (creditScore >= 590 && creditScore <= 624)
           System.out.println("Your Interest Rate: 12.45%");
       else if (creditScore >= 0 && creditScore <= 589)
          
       System.out.println("Your Interest Rate: 0%");

   } // end main
} // end class

OUTPUT:

Enter the credit score: 822

Your Interest Rate: 5.56%

Note: last else if is ended with ; treats empty statement

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote