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

Write a program that uses the following formula: _(i=1)^n(ax-ib)^c Your program

ID: 3860182 • Letter: W

Question

Write a program that uses the following formula: _(i=1)^n(ax-ib)^c Your program will prompt the user for the number of iterations for the calculation. input values for n, x, a, b, and c. n must be a positive integer, but x, a, b, and c can be any real numbers. Then it will perform the calculation and output the result. Then, it will ask the user if they would like to perform another calculation. Only if the answer is ‘Y’, prompt the user again for new input values and perform the new calculation. USE EXACT STRING PROVIDED in below example (colored blue below) Your prompt msg and output msg MUST look like this EXACTLY: This program will calculate the sum (ax - ib)^c, where i goes from 1 to n. Enter the values for n, x, a, b, and c separated by spaces then press Enter. 10 2 3 4 5 The sum of (3*2 - i*4)^5 where i goes from 1 to 10 is {Your_calculation_value_here} Would you like to do another calculation (Y/N)? Y This program will calculate the sum (ax - ib)^c, where i goes from 1 to n. Enter the values for n, x, a, b, and c separated by spaces then press Enter. 20 3.5 1.7 2.5 -1 The sum of (1.7*3.5 - i*2.5)^-1 where i goes from 1 to 20 is {Your_calculation_value_here} Would you like to do another calculation (Y/N)? N Sample values: n x a b c sum 1 2 3 4 5 32 2 2 3 4 5 0 10 2 2 2 2 820

Explanation / Answer

package formula;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Calculate {

   public Calculate() {
       // TODO Auto-generated constructor stub
   }

   public static void main(String[] args) throws IOException {
      
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
       boolean again = false;
       int number;
       do{
           System.out.println("Enter the values of n, x, a, b, and c separated by spaces");
           String[] input = br.readLine().split(" ");
           int n = Integer.parseInt(input[0]);
           number = n;
           double x = Double.parseDouble(input[1]);
           double a = Double.parseDouble(input[2]);
           double b = Double.parseDouble(input[3]);
           double c = Double.parseDouble(input[4]);
           double sum = 0;
          
           while(n>0){
               sum += Math.pow((a*x-n*b),c);
               n--;
           }
           System.out.println("The sum of ("+a+"*"+x+" -i *"+c+")^"+c+" where i goes from 1 to +"+number+" is :"+sum);
           System.out.println(" Would you like to do another calculation (Y/N)?");
           again = br.readLine().equalsIgnoreCase("Y");
       }while(again);

   }

}

Output:

Enter the values of n, x, a, b, and c separated by spaces
20 3.5 1.7 2.5 -1
The sum of (1.7*3.5 -i *-1.0)^-1.0 where i goes from 1 to +20 is :-0.40430115725409327

Would you like to do another calculation (Y/N)?
N

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