Write a program to extend the below program, by adding an option 'f' to the menu program. If this option is chosen, the program should ask the user to enter 10 integers. The program should store each integer into an array (as each one is entered). Once the array contains the 10 integers, the program should output: a) The average of the 10 numbers entered b) The highest number entered c) The lowest number entered

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a program to extend the below program, by adding an option 'f' to the menu program. If this option is chosen, the program should ask the user to enter 10 integers. The program should store each integer into an array (as each one is entered). Once the array contains the 10 integers, the program should output:

a) The average of the 10 numbers entered

b) The highest number entered

c) The lowest number entered

import java.util.Scanner;
public class Main {
    static Scanner kb = new Scanner(System.in);
    public static void displayMenu(){
        System.out.println("a-Print Name and Tutor Name");
        System.out.println("b-Largest of 3 Number");
        System.out.println("c-Display Numbers in range of two numbers");
        System.out.println("d-Check for Triangles");
        System.out.println("e-Check for prime");
        System.out.println("q-Quit");
        System.out.print("Enter Your Choice (a,b,c,d,e,q) : ");
        
    }
    public static void findLargestOf3(){
        double x,y,z,smallest,largest;
        System.out.println("Enter 3 Numbers : ");
        System.out.print("x : ");
        x=Double.parseDouble(kb.nextLine());
        System.out.print("y : ");
        y=Double.parseDouble(kb.nextLine());
        System.out.print("z : ");
        z=Double.parseDouble(kb.nextLine());
        smallest=(x<y&&x<z)?x:(y<x&&y<z)?y:z;
        largest=(x>y&&x>z)?x:(y>x&&y>z)?y:z;
        System.out.println("The Smallest Number is : "+smallest);
        System.out.println("The Largest Number is : "+largest);
    }
    public static void displayNumbersinRange(){
        int m,n,s=0,t;
        System.out.println("Enter 2 Numbers : ");
        System.out.print("m : ");
        m=Integer.parseInt(kb.nextLine());
        System.out.print("n : ");
        n=Integer.parseInt(kb.nextLine());
        if(m>n){
            t=n;
            n=m;
            m=t;
        }
        for(int i=m,j=1;i<n;i++,j++){
            System.out.print(i+" ");
            if(j%5==0)
                System.out.println();
            if(i%2!=0)
                s+=i;
        }
        System.out.println("\nThe Sum of all odd numbers between "+m+" and "+n+" is : "+s);
    }
    public static void checkTriangle(){
         double s1,s2,s3;
        System.out.println("Enter 3 Sides of Triangle : ");
        System.out.print("s1 : ");
        s1=Double.parseDouble(kb.nextLine());
        System.out.print("s2 : ");
        s2=Double.parseDouble(kb.nextLine());
        System.out.print("s3 : ");
        s3=Double.parseDouble(kb.nextLine());
        if(s1>s2+s3||s2>s1+s3||s3>s1+s2){
            System.out.println("The Given sides can from a Triangle");
        }else
            System.out.println("The Given sides can not from a Triangle");
    }
    public static void checkPrime(){
         int m,c=0;
        System.out.print("Enter a Numbers : ");
       m=Integer.parseInt(kb.nextLine());
        for(int i=1;i<=m;i++){
            if(m%i==0)
                c++;
        }
        if(c==2)
            System.out.println("The given number is Prime");
        else
            System.out.println("The given number is not a Prime");
    }
    public static void main(String[] args) {
        char ch='x';
        while(ch!='q'){
            displayMenu();
            ch=kb.nextLine().toLowerCase().charAt(0);
            switch(ch){
                case 'a': System.out.println("My Name \n My Tutor Name");break;
                case 'b': findLargestOf3();break;
                case 'c': displayNumbersinRange();break;
                case 'd': checkTriangle();break;
                case 'e': checkPrime();break;
                case 'q':break;
                default : System.out.println("Error : Invalid Input ");break;
            }
        }
    }
    
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY