Answer to Question #257269 in Java | JSP | JSF for deek

Question #257269

Write a java program that will satisfy the given requirements:


A. It will display the given menu:


A - Arithmetic Series

B - Geometric Series

C - Harmonic Mean

D - Largest Prime Number

E - Largest Prime Number

Q - Quit the Program


B. The program will ask the user his/her choice.

C. If the choice is A,B,C,D or E, It will prompt the user for the required inputs, then compute and display the required outputs. If the choice is Q, the program will terminate

D. Validate all your inputs by promptingg for a new value if input is invalid.

E. Display also a description of your program

F. Program should execute for as long as the user wants to continue

G. Use of arrays is not allowed


1
Expert's answer
2021-10-27T10:15:36-0400
import java.util.Scanner;
public class Main
{
	static void displayAP(int a, int d, int n) {
        for (int i = 1; i <= n; i++) {
            System.out.print(a + (i - 1) * d + " ");
        }
    }
    	static void displayGP(int a, int r, int n) {
        for (int i = 1; i <= n; i++) {
            System.out.print(a * Math.pow(r, (i-1)+" ");
        }
    }
    public static double harmonicMean(double[] data)  
{  
	double sum = 0.0;


	for (int i = 0; i < data.length; i++) { 
		sum += 1.0 / data[i]; 
	} 
	return data.length / sum; 
}
	public static void main(String[] args) {
	System.out.printf("A - Arithmetic Series\nB - Geometric Series\nC - Harmonic Mean\nD - Largest Prime Number");
  System.out.printf("\nE - Largest Prime Number\nQ - Quit the Program");
  Scanner scan = new Scanner(System.in);
  char c = scan.next().charAt(0);
  switch(c){
      case 'A': 
          displayAP(1, 5, 20);
          break;
     case 'B':
         displayGP(1,5,20);
         break;
     case 'C':
         double [] arr = {90,32,24,57,100,199};
         harmonicMean()
          System.out.println("\nHarmonic mean is: "+harmonicMean(arr));
          
      case 'Q':
          System.exit(0);
      
      
      
  }
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS