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

// SumAndProduct.java This progzam computes sums and producta. // Input: Interac

ID: 3702729 • Letter: #

Question

// SumAndProduct.java This progzam computes sums and producta. // Input: Interactive. // Output: Computed sum and product. import javax. awing.* public class SumAndProduct public static void main(String args[1) int number; string numberstring numberstring JOptionPane . showinputDialog ("Enter a positive integer number Integer.parseInt (numberString) while (number != 0) or 0 to quit: ") // call sums method here // call produets ) method here numbers tring = JOptionPane. showinputDialog ("Enter a positive integer or 0 to quit: ") number Integer.parseInt (numberString); = System.exit(0) ) /End of main() method. // Write sums () method here. // write products( method here.

Explanation / Answer

import javax.swing.JOptionPane;

public class SumAndProduct {

   public static void main(String[] args) {
       int number;
       String numberString;
       numberString = JOptionPane.showInputDialog("Enter a positive integer or 0 to quit :");
       number = Integer.parseInt(numberString);
       while (number != 0) {
           // call sums method
           sums(number);
           product(number);

           numberString = JOptionPane.showInputDialog("Enter a positive integer or 0 to quit :");
           number = Integer.parseInt(numberString);
       }
   }

   private static void sums(int number) {
       int sum = 0;
       for (int i = 1; i <= number; i++) {
           sum += i;
       }
       System.out.println("The Sum is = " + sum);

   }

   private static void product(int number) {
       int product = 1;
       for (int i = 1; i <= number; i++) {
           product *= i;
       }
       System.out.println("The Product is = " + product);

   }

}

Output:

The Product is = 3628800
The Sum is = 55