Question
need a java structure chart for the 2 below programs. and an explanation would help. not sure what a structure chart is besides that it
need a java structure chart for the 2 below programs. and an explanation would help. not sure what a structure chart is besides that it lists the methods.
import java.util.Scanner;
public class Problem_5_22 { public static void main(String[] args) { boolean run = true; while(run) { //Creates a Scanner to take in user input Scanner input = new Scanner(System.in);
//Prompts the user to enter the loan amount, the number of years //and the annual interest rate System.out.printf(" Loan Amount: "); double loanAmount = input.nextDouble(); System.out.printf("Number of Years: "); int years = input.nextInt(); System.out.printf("Annual Interest Rate: "); double annualRate = input.nextDouble();
//Calculates the monthly interest rate double monthlyRate = annualRate/1200;
//Calculates the monthly payment amount double monthlyPayment = loanAmount * monthlyRate / (1-1/Math.pow(1 + monthlyRate, years * 12));
//Displays the monthly payment amount System.out.printf("Monthly Payment: %.2f ", monthlyPayment);
//Displays total payments made YTD System.out.printf("Total Payment: %.2f ", (monthlyPayment * 12) * years);
//Creates the amortization/payment schedule and displays by month double balance = loanAmount, principal, interest; System.out.println("Payment# Interest Principal Balance"); for (int i = 1; i <= years * 12; i++) { interest = monthlyRate * balance; principal = monthlyPayment - interest; balance = balance - principal; System.out.printf("%-13d%-13.2f%-13.2f%.2f ", i, interest, principal, balance); } } } }
____________________________________________________________________________
import java.util.Scanner;
public class Problem_6_22 { public static void main(String[] args) { boolean run = true; while(run) { //Creates a Scanner to take in user input Scanner input = new Scanner(System.in);
//Prompts the user to enter an integer System.out.printf("Enter a number: "); long number = input.nextLong();
//Displays the square root System.out.printf("The approximated square root of " + number + " is: " + sqrt(number)); System.out.printf(" "); } }
public static double sqrt(long n) { //makes the initial guess to positive value long lastGuess = 1; long nextGuess = (lastGuess + n / lastGuess) / 2;
//If the difference between nextGuess and lastGuess is less than 0.0001, //it returns nextGuess as the approximated square root of n. while (nextGuess - lastGuess > 0.0001) { lastGuess = nextGuess; nextGuess = (lastGuess + n / lastGuess) / 2; } lastGuess = nextGuess; return nextGuess = (lastGuess + n / lastGuess) / 2; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started