Ask Java Expert


Home >> Java

Write a program that will read in a list of positive integers (including zero) and display some statistics regarding the integers.

The user is assumed to enter the list in sorted order, starting with the smallest number and ending with the largest number.

Your program must store the all of the integers in an array. The maximum number of integers that you can expect is 100, however there may not necessarily be that many. Your program should allow the user to continue entering numbers until they enter a negative number or until the array is filled - whichever occurs first. If the user enters 100 numbers, you should output an message stating that the maximum size for the list has been reached, then proceed with the calculations.

After you have placed all of the integers into an array, your program should perform the following tasks, in this order:

  1. Display the count of how many numbers were read
  2. Display the smallest number in the array
  3. Display the largest number in the array
  4. Display the median (the median is the integer that is stored in the middle position of the array)
  5. Display the average of all the numbers
  6. Allow the user to search the array for a specified value.
    1. First, ask the user to enter an integer to search for.
    2. Next, search the array to determine if the given integer is in the array.
    3. If the integer is not found, display a message stating that the integer is not in the list.
    4. If the integer is found, then display the position number of where you found the integer. If the integer happens to be in the array more than once, then you only need to tell the first position number where you found it.
    5. After performing the search, ask the user if he/she wants to search for more integers. Continue searching for numbers until the user answers "N".

Technical notes and restrictions:

  • Remember that the keyboard object should be declared as a class variable (global).
  • Absolutely NO other global variables (class variables) are allowed (except for the keyboard object).
  • You are only allowed to use the number 100 one time in your program! You are not allowed to use the numbers 101, 99, 98, or any other number that is logically related to 100 anywhere in your program. If you need to make reference to the array size then, use the length variable to reference this rather than hard-coding numbers into your program.
  • You are required to write and use at least the following FOUR methods in this program:
    • A method to get the numbers from the user, and place them into an array. This method should return the number of integers that it actually retrieved. The array will be passed back through a parameter (remember that the method can make changes to an array's contents and the main program will automatically see the results).
    • A method to calculate, and return, the median of the array. This will be a double value.
      • If there are an odd number of integers in the array, then the median is defined as the integer stored in the middle array position.
      • If there are an even number number of integers in the array, then the median is defined as the average of the integers stored in the two middle array positions.
    • A method to calculate, and return, the average of the numbers in the array. This will be a double value.
    • A method to search for a specified value in the array. This method should return the first position number where the item is found, or return -1 if the item is not found.
  • The two calculating methods, and the searching method, should not get any values from the user, and should not print anything to the screen. The main program is responsible for all of the printing.
    The method which gets the numbers will need (of course) to get values from the user, but should not print anything to the screen.
  • Remember that at this stage, COMMENTING IS A REQUIREMENT! Make sure you FULLY comment your program. You must include comments that explain what sections of code is doing. Notice the key word "sections"! This means that you need not comment every line in your program. Write comments that describe a few lines of code rather than "over-commenting" your program.
  • You MUST write comments about every method that you create. Your comments must describe the purpose of the method, the purpose of every parameter the method needs, and the purpose of the return value (if the method has one).
  • Build incrementally. Don't tackle the entire program at once. Write a little section of the program, then test it AND get it working BEFORE you go any further. Once you know that this section works, then you can add a little more to your program. Stop and test the new code. Once you get it working, then add a little bit more.
  • Make sure you FULLY test your program! Make sure to run your program multiple times, inputting combinations of values that will test all possible conditions for your IF statements and loops. Also be sure to test border-line cases.

Java, Programming

  • Category:- Java
  • Reference No.:- M9456671

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As