SlideShare a Scribd company logo
1 of 8
Download to read offline
Create a menu-driven program that will accept a collection of non-negative integers from the
keyboard, calculate the mean and median values and display those values on the screen. Your
menu should have 6 options: 1. Add a number to the array 2. Display the mean 3. Display the
median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit
Program particulars: Use an array of type int to store the integers entered by the user. There
must be error checking on the input integer. If it is negative, the program will print an error
message and re-prompt. This process will continue until a non-negative integer is entered. You
must use a try-catch structure to trap both types of input errors (like letters where numbers
should go) and range errors (like -1). You must write your own selectionSort utility method to
sort your array. Place the method in an external file named SortSearchUtil.java. There must be
error checking on the menu choice entered. If the user enters a choice not on the menu, the
program will print an error message, re-display the menu and re-prompt. This process will
continue until a valid option value is entered. Your solution must be modular. The design of your
methods is up to you, but the rules of “highly cohesive” and “loosely coupled” must be followed.
Your program should be well-documented. Explain what you’re doing in your code. Be sure to
include the usual name and assignment notes. Note your program will have to sort your array
before you can find the median. Include your SortSearchUtil.java file which will contain your
sort method.
This is what my project looks like already: Please fix it thanks. The SortSearchUtil will also be
included.
import java.util.Scanner;
public class ArraySorting
{
public static void main(String[] args)
{
int option;
int integer = 0;
int optionOne;
int optionTwo;
int optionThree;
int optionFour;
int optionFive;
int[] numbers = new int[5];
Scanner kb = new Scanner(System.in);
System.out.println("Please enter a non-negative integer: ");
integer = kb.nextInt();
while((integer < 0))
{
System.out.println("I am sorry that is not a non-negative integer.");
System.out.println("");
System.out.println("Please enter a non-negative integer: ");
integer = kb.nextInt();
}
option = displayMenu(kb);
while (option != 6)
{
switch (option)
{
case 1:
optionOne(numbers);
System.out.println("");
break;
case 2:
optionTwo(numbers);
System.out.println("");
case 3:
//optionThree();
System.out.println("");
break;
case 4:
//optionFour();
System.out.println("");
break;
case 5:
//optionFive();
System.out.println("");
break;
}
option = displayMenu(kb);
}
if (option == 6)
{
System.out.println();
System.out.println("Thank you. Have a nice day.");
}
}
private static int displayMenu(Scanner kb)
{
int option = 0;
while (option != 1 && option != 2 && option != 3 && option != 4 && option !=5 && option
!=6)
{
System.out.println("tt1. Add a number to the array tt2. Display the mean tt3. Display
the median  tt4. Print the array to the screen  tt5. Print the array in reverse order  tt6.
Quit");
option = kb.nextInt();
if (!(option == 1 || option == 2 || option == 3 || option == 4 || option == 5 || option == 6))
System.out.println("I am sorry that is an invalid choice. Please try again.");
}
return option;
}
private static int[] optionOne()
{
Scanner input = new Scanner(System.in);
int[] numbers = new int[1];
for (int i = 0; i < numbers.length; i++)
{
System.out.println("Please enter number");
numbers[i] = input.nextInt();
}
return numbers;
}
private static void optionTwo(int[] numbers)
{
int sum = 0;
for(int i=0; i < numbers.length; i++)
sum = sum + numbers[i];
double average = sum / numbers.length;
System.out.println("Average value of array element is: " + average);
}
public class SortSearchUtil
{
public static void selectionSort(int[] array)
{
int current, indexSmallest, posToFill;
int temp;
for(posToFill = 0; posToFill < array.length - 1; posToFill++)
{
indexSmallest = posToFill;
for(current = posToFill + 1; current < array.length; current++)
{
if(array[current] < array[indexSmallest])
{
indexSmallest = current;
}
}
temp = array[posToFill];
array[posToFill] = array[indexSmallest];
array[indexSmallest] = temp;
}
}
public static void selectionSort(String[] array)
{
int current, indexSmallest, posToFill;
String temp;
for (posToFill = 0; posToFill < array.length - 1; posToFill++)
{
indexSmallest = posToFill;
for (current = posToFill + 1; current < array.length; current++)
{
if (array[current].compareTo(array[indexSmallest]) <0)
{
indexSmallest = current;
}
}
temp = array[posToFill];
array[posToFill] = array[indexSmallest];
array[indexSmallest] = temp;
}
}
}
Solution
import java.util.Arrays;
import java.util.Scanner;
public class ArraySorting
{
public static void main(String[] args)
{
int option;
int integer = 0;
int optionOne;
int optionTwo;
int optionThree;
int optionFour;
int optionFive;
Scanner kb = new Scanner(System.in);
System.out.println("Enter size of array ");
int n=kb.nextInt();
int[] numbers = new int[n];
System.out.println("Enter elements of array ");
for(int i=0;i=0 ; i--)
System.out.println(" array element in reverse are: " + numbers[i]);
}
public class SortSearchUtil
{
public void selectionSort(int[] array)
{
int current, indexSmallest, posToFill;
int temp;
for(posToFill = 0; posToFill < array.length - 1; posToFill++)
{
indexSmallest = posToFill;
for(current = posToFill + 1; current < array.length; current++)
{
if(array[current] < array[indexSmallest])
{
indexSmallest = current;
}
}
temp = array[posToFill];
array[posToFill] = array[indexSmallest];
array[indexSmallest] = temp;
}
}
public void selectionSort(String[] array)
{
int current, indexSmallest, posToFill;
String temp;
for (posToFill = 0; posToFill < array.length - 1; posToFill++)
{
indexSmallest = posToFill;
for (current = posToFill + 1; current < array.length; current++)
{
if (array[current].compareTo(array[indexSmallest]) <0)
{
indexSmallest = current;
}
}
temp = array[posToFill];
array[posToFill] = array[indexSmallest];
array[indexSmallest] = temp;
}
}
}
}
==========================================================
Enter size of array
3
Enter elements of array
1
2
3
1. Add a number to the array
2. Display the mean
3. Display the median
4. Print the array to the screen
5. Print the array in reverse order
6. Quit
1
enter number
4
1. Add a number to the array
2. Display the mean
3. Display the median
4. Print the array to the screen
5. Print the array in reverse order
6. Quit
5
array element in reverse are: 4
array element in reverse are: 3
array element in reverse are: 2
array element in reverse are: 1
1. Add a number to the array
2. Display the mean
3. Display the median
4. Print the array to the screen
5. Print the array in reverse order
6. Quit
4
array element are: 1
array element are: 2
array element are: 3
array element are: 4
1. Add a number to the array
2. Display the mean
3. Display the median
4. Print the array to the screen
5. Print the array in reverse order
6. Quit
6
Thank you. Have a nice day.

More Related Content

Similar to Create a menu-driven program that will accept a collection of non-ne.pdf

The java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfThe java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfakaluza07
 
This is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfThis is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfoptokunal1
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docxdavinci54
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfezhilvizhiyan
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfdeepua8
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 

Similar to Create a menu-driven program that will accept a collection of non-ne.pdf (14)

The java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfThe java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdf
 
This is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfThis is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
Oot practical
Oot practicalOot practical
Oot practical
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 

More from rajeshjangid1865

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfrajeshjangid1865
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfrajeshjangid1865
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfrajeshjangid1865
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfrajeshjangid1865
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfrajeshjangid1865
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfrajeshjangid1865
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfrajeshjangid1865
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfrajeshjangid1865
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdfrajeshjangid1865
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfrajeshjangid1865
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfrajeshjangid1865
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfrajeshjangid1865
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfrajeshjangid1865
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfrajeshjangid1865
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfrajeshjangid1865
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfrajeshjangid1865
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfrajeshjangid1865
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfrajeshjangid1865
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfrajeshjangid1865
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfrajeshjangid1865
 

More from rajeshjangid1865 (20)

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdf
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdf
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdf
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdf
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdf
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdf
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdf
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdf
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdf
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdf
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Create a menu-driven program that will accept a collection of non-ne.pdf

  • 1. Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options: 1. Add a number to the array 2. Display the mean 3. Display the median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit Program particulars: Use an array of type int to store the integers entered by the user. There must be error checking on the input integer. If it is negative, the program will print an error message and re-prompt. This process will continue until a non-negative integer is entered. You must use a try-catch structure to trap both types of input errors (like letters where numbers should go) and range errors (like -1). You must write your own selectionSort utility method to sort your array. Place the method in an external file named SortSearchUtil.java. There must be error checking on the menu choice entered. If the user enters a choice not on the menu, the program will print an error message, re-display the menu and re-prompt. This process will continue until a valid option value is entered. Your solution must be modular. The design of your methods is up to you, but the rules of “highly cohesive” and “loosely coupled” must be followed. Your program should be well-documented. Explain what you’re doing in your code. Be sure to include the usual name and assignment notes. Note your program will have to sort your array before you can find the median. Include your SortSearchUtil.java file which will contain your sort method. This is what my project looks like already: Please fix it thanks. The SortSearchUtil will also be included. import java.util.Scanner; public class ArraySorting { public static void main(String[] args) { int option; int integer = 0; int optionOne; int optionTwo; int optionThree; int optionFour; int optionFive; int[] numbers = new int[5];
  • 2. Scanner kb = new Scanner(System.in); System.out.println("Please enter a non-negative integer: "); integer = kb.nextInt(); while((integer < 0)) { System.out.println("I am sorry that is not a non-negative integer."); System.out.println(""); System.out.println("Please enter a non-negative integer: "); integer = kb.nextInt(); } option = displayMenu(kb); while (option != 6) { switch (option) { case 1: optionOne(numbers); System.out.println(""); break; case 2: optionTwo(numbers); System.out.println(""); case 3: //optionThree(); System.out.println(""); break; case 4: //optionFour(); System.out.println(""); break; case 5: //optionFive(); System.out.println("");
  • 3. break; } option = displayMenu(kb); } if (option == 6) { System.out.println(); System.out.println("Thank you. Have a nice day."); } } private static int displayMenu(Scanner kb) { int option = 0; while (option != 1 && option != 2 && option != 3 && option != 4 && option !=5 && option !=6) { System.out.println("tt1. Add a number to the array tt2. Display the mean tt3. Display the median tt4. Print the array to the screen tt5. Print the array in reverse order tt6. Quit"); option = kb.nextInt(); if (!(option == 1 || option == 2 || option == 3 || option == 4 || option == 5 || option == 6)) System.out.println("I am sorry that is an invalid choice. Please try again."); } return option; } private static int[] optionOne() { Scanner input = new Scanner(System.in); int[] numbers = new int[1]; for (int i = 0; i < numbers.length; i++) { System.out.println("Please enter number"); numbers[i] = input.nextInt(); } return numbers;
  • 4. } private static void optionTwo(int[] numbers) { int sum = 0; for(int i=0; i < numbers.length; i++) sum = sum + numbers[i]; double average = sum / numbers.length; System.out.println("Average value of array element is: " + average); } public class SortSearchUtil { public static void selectionSort(int[] array) { int current, indexSmallest, posToFill; int temp; for(posToFill = 0; posToFill < array.length - 1; posToFill++) { indexSmallest = posToFill; for(current = posToFill + 1; current < array.length; current++) { if(array[current] < array[indexSmallest]) { indexSmallest = current; } } temp = array[posToFill]; array[posToFill] = array[indexSmallest]; array[indexSmallest] = temp; } } public static void selectionSort(String[] array) { int current, indexSmallest, posToFill;
  • 5. String temp; for (posToFill = 0; posToFill < array.length - 1; posToFill++) { indexSmallest = posToFill; for (current = posToFill + 1; current < array.length; current++) { if (array[current].compareTo(array[indexSmallest]) <0) { indexSmallest = current; } } temp = array[posToFill]; array[posToFill] = array[indexSmallest]; array[indexSmallest] = temp; } } } Solution import java.util.Arrays; import java.util.Scanner; public class ArraySorting { public static void main(String[] args) { int option; int integer = 0; int optionOne; int optionTwo; int optionThree; int optionFour; int optionFive;
  • 6. Scanner kb = new Scanner(System.in); System.out.println("Enter size of array "); int n=kb.nextInt(); int[] numbers = new int[n]; System.out.println("Enter elements of array "); for(int i=0;i=0 ; i--) System.out.println(" array element in reverse are: " + numbers[i]); } public class SortSearchUtil { public void selectionSort(int[] array) { int current, indexSmallest, posToFill; int temp; for(posToFill = 0; posToFill < array.length - 1; posToFill++) { indexSmallest = posToFill; for(current = posToFill + 1; current < array.length; current++) { if(array[current] < array[indexSmallest]) { indexSmallest = current; } } temp = array[posToFill]; array[posToFill] = array[indexSmallest]; array[indexSmallest] = temp; } } public void selectionSort(String[] array) { int current, indexSmallest, posToFill;
  • 7. String temp; for (posToFill = 0; posToFill < array.length - 1; posToFill++) { indexSmallest = posToFill; for (current = posToFill + 1; current < array.length; current++) { if (array[current].compareTo(array[indexSmallest]) <0) { indexSmallest = current; } } temp = array[posToFill]; array[posToFill] = array[indexSmallest]; array[indexSmallest] = temp; } } } } ========================================================== Enter size of array 3 Enter elements of array 1 2 3 1. Add a number to the array 2. Display the mean 3. Display the median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit 1 enter number 4
  • 8. 1. Add a number to the array 2. Display the mean 3. Display the median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit 5 array element in reverse are: 4 array element in reverse are: 3 array element in reverse are: 2 array element in reverse are: 1 1. Add a number to the array 2. Display the mean 3. Display the median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit 4 array element are: 1 array element are: 2 array element are: 3 array element are: 4 1. Add a number to the array 2. Display the mean 3. Display the median 4. Print the array to the screen 5. Print the array in reverse order 6. Quit 6 Thank you. Have a nice day.