Write a program to extend program below, by adding an option 'f' to your 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 sum of the 10 numbers entered b) The average of the 10 numbers entered c) The highest number entered d) The lowest number entered import java.util.*;   //create a main class called Task public class NewClass { static Scanner kb = new Scanner(System.in);   //definition of the function Largest_And_Smallest_Number() public static void Largest_And_Smallest_Number() { System.out.print("Enter three numbers: "); //get the numbers from the user double x = kb.nextInt(); double y = kb.nextInt(); double z = kb.nextInt(); //print the largest and smallest number by calling the respective functions System.out.println("The largest of three numbers is " + largest(x,y,z)); System.out.println("The smallest of the three numbers is " + smallest(x,y,z)); }   //definition of the function largest() public static double largest(double x, double y, double z) { double large = x; if(x >= y && x >= z) large = x; else if(y>=x && y >=z) large = y; else large = z; //return the largest number to the calling function return large; }   //definition of the funcction smallest() public static double smallest(double x, double y, double z) { double small = x; if(x <= y && x <= z) small = x; else if(y<=x && y <=z) small = y; else small = z; //return the smallest number to the calling function return small; }   //definition of the function odd_Num() public static void odd_Num() { System.out.print("Enter two integer numbers: "); //get the numbers from the user int m = kb.nextInt(); int n = kb.nextInt(); int num_count = 0; int sum_Odd = 0; int i; for(i=m; i<=n; ++i) { System.out.print(i + " "); ++num_count; if(num_count==5) { System.out.println(); num_count = 0; } if(i%2 != 0) sum_Odd = sum_Odd + i; } System.out.println(); //print the sum of all odd numbers between m and n System.out.println("Sum of all the odd numbers between " + m + " and " + n + " is " + sum_Odd); }   //definition of the function check_Triangle() public static void check_Triangle() { System.out.print("Enter the sides of a triangle: "); //get the input from the user int p = kb.nextInt(); int q = kb.nextInt(); int r = kb.nextInt(); String res = ""; if(!((p+q) > r && (q+r) > p && (p+r) > q)) res = "not"; //print the output System.out.println("The three sides " + p + ", " + q + ", " + r + " can" + res + " form a triangle"); }   //definition of the function num_Prime() public static void num_Prime() { System.out.print("Enter a number: "); int num = kb.nextInt(); int i; boolean prime = true; if(num<2) prime = false; else { for(i=2; i<(num/2); ++i) { if(num %i == 0) { prime = false; break; } } } //print the output if(prime) System.out.println(num + " is a Prime number"); else System.out.println(num + " is not a Prime number"); }   //definition of the main function public static void main(String[] args) { //prompt the user to enter a character System.out.print("Enter one of the characters 'a, b, c, d, e, q:' "); //get the character by the user char ch = kb.next().trim().toLowerCase().charAt(0); //check the condition under while loop while (ch != 'q') { //switch case to selection the option entered by the user switch(ch) { case 'a': //write your name and your tutor name inside " " System.out.println("Your_Name"); System.out.println("Your_Tutor_Name"); break; case 'b': Largest_And_Smallest_Number(); break; case 'c': odd_Num(); break; case 'd': check_Triangle(); break; case 'e': num_Prime(); break; case 'q': break ; default: System.out.println("Invalid Input"); break; } System.out.println(); System.out.print("Enter a character: "); System.out.println(); ch=kb.next().toLowerCase().charAt(0); } }   }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question

Write a program to extend program below, by adding an option 'f' to your 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 sum of the 10 numbers entered
b) The average of the 10 numbers entered
c) The highest number entered
d) The lowest number entered

import java.util.*;

 

//create a main class called Task

public class NewClass

{

static Scanner kb = new Scanner(System.in);

 

//definition of the function Largest_And_Smallest_Number()

public static void Largest_And_Smallest_Number()

{

System.out.print("Enter three numbers: ");

//get the numbers from the user

double x = kb.nextInt();

double y = kb.nextInt();

double z = kb.nextInt();

//print the largest and smallest number by calling the respective functions

System.out.println("The largest of three numbers is " + largest(x,y,z));

System.out.println("The smallest of the three numbers is " + smallest(x,y,z));

}

 

//definition of the function largest()

public static double largest(double x, double y, double z)

{

double large = x;

if(x >= y && x >= z)

large = x;

else if(y>=x && y >=z)

large = y;

else

large = z;

//return the largest number to the calling function

return large;

}

 

//definition of the funcction smallest()

public static double smallest(double x, double y, double z)

{

double small = x;

if(x <= y && x <= z)

small = x;

else if(y<=x && y <=z)

small = y;

else

small = z;

//return the smallest number to the calling function

return small;

}

 

//definition of the function odd_Num()

public static void odd_Num()

{

System.out.print("Enter two integer numbers: ");

//get the numbers from the user

int m = kb.nextInt();

int n = kb.nextInt();

int num_count = 0;

int sum_Odd = 0;

int i;

for(i=m; i<=n; ++i)

{

System.out.print(i + " ");

++num_count;

if(num_count==5)

{

System.out.println();

num_count = 0;

}

if(i%2 != 0)

sum_Odd = sum_Odd + i;

}

System.out.println();

//print the sum of all odd numbers between m and n

System.out.println("Sum of all the odd numbers between " + m + " and " + n + " is " + sum_Odd);

}

 

//definition of the function check_Triangle()

public static void check_Triangle()

{

System.out.print("Enter the sides of a triangle: ");

//get the input from the user

int p = kb.nextInt();

int q = kb.nextInt();

int r = kb.nextInt();

String res = "";

if(!((p+q) > r && (q+r) > p && (p+r) > q))

res = "not";

//print the output

System.out.println("The three sides " + p + ", " + q + ", " + r + " can" + res + " form a triangle");

}

 

//definition of the function num_Prime()

public static void num_Prime()

{

System.out.print("Enter a number: ");

int num = kb.nextInt();

int i;

boolean prime = true;

if(num<2)

prime = false;

else

{

for(i=2; i<(num/2); ++i)

{

if(num %i == 0)

{

prime = false;

break;

}

}

}

//print the output

if(prime)

System.out.println(num + " is a Prime number");

else

System.out.println(num + " is not a Prime number");

}

 

//definition of the main function

public static void main(String[] args)

{

//prompt the user to enter a character

System.out.print("Enter one of the characters 'a, b, c, d, e, q:' ");

//get the character by the user

char ch = kb.next().trim().toLowerCase().charAt(0);

//check the condition under while loop

while (ch != 'q')

{

//switch case to selection the option entered by the user

switch(ch)

{

case 'a':

//write your name and your tutor name inside " "

System.out.println("Your_Name");

System.out.println("Your_Tutor_Name");

break;

case 'b':

Largest_And_Smallest_Number();

break;

case 'c':

odd_Num();

break;

case 'd':

check_Triangle();

break;

case 'e':

num_Prime();

break;

case 'q':

break ;

default:

System.out.println("Invalid Input");

break;

}

System.out.println();

System.out.print("Enter a character: ");

System.out.println();

ch=kb.next().toLowerCase().charAt(0);

}

}

 

}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning