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

Please help! Chapter 3 Input/output 183 Page Assignments 1 calculating Interest

ID: 3850074 • Letter: P

Question

Please help! Chapter 3 Input/output 183 Page Assignments 1 calculating Interest Using Boxes: Your goal is to ask the user 3 different questions with 3 different dialog boxes concerning borrowed, rate, dollars interest and number of years borrowed. The computer should then calculate simple and display all 4 pieces of information in sentence form on a dialog box Your program should have the following: Make the name of the project Have a dialog box appear on screen that requests the user to type in amount of dollars borrowed. Place the response that a user types in into a String variable. Convert that using the method in Double class and place this double into a double variable named dollars. How many dollars do you wish to borrow? ok cancel Have a dialog box appear on screen that requests the interest rate from user. Place the response that a user types in into a new String variable. Convert that string using the parse Double method in Double class and place this double into a double variable named rate. What is the interest rate? 5.85 Cancel Have a dialog box appear on screen that requests the number of years of the loan from user. Place the response that a user types in into a new String variable. Convert that string using the parselnt method in the Integer class and place the result into a variable named years.

Explanation / Answer

Java code:

Create a file Code.java and paste given code into it!


import javax.swing.JOptionPane;
import java.util.Scanner;
import java.text.DecimalFormat;

public class Code
{

    public static void main(String[] args)
    {
    int a1,a2;
        String s = JOptionPane.showInputDialog(null,"How many dollars you want to borrow?");
        Double dollars = Double.parseDouble(s);

        s = JOptionPane.showInputDialog(null,"What is interest rate?");
        Double rate = Double.parseDouble(s);

        s = JOptionPane.showInputDialog(null,"How many years will you take the loan?(whole number)");
        int years = Integer.parseInt(s);
        Double interest = (dollars*rate*years/100.0);       
        JOptionPane.showMessageDialog(null,"If you borrowed $" + dollars + " at the interest rate of " + rate + " for " + years + " you will pay " + interest + " in interest!");
    }
}