Reference no: EM132271202
Description:
Write a Java program that inputs an unspecified number of integers from the user. The program should calculate the following statistics:
• The total of all the numbers
• The average (mean) of all the numbers (displayed as a floating-point value)
• The number of positive values
• The number of negative values
• The highest number entered
• The lowest number entered
The end of the input is indicated by the value 999, which does not count as one of the numbers. This is known as a sentinel value. When all the numbers have been processed the statistics should be printed out, for example
Enter one or more integers (0 marks the end of input): 1 2 -1 3 999
The total is 5
The average is 1.25
The number of positives is 3 The number of negatives is 1 The highest number is 3
The lowest number is -1
The program should work with any number of input values. Assume that the user always types integer values, no need to properly handle wrong input. Program should not have any unnecessary duplicated code.
Hints:
• To calculate the average you'll need to keep track of how many numbers were entered
• To determine the highest or lowest number your program will need to keep track of the highest/lowest number seen so far
Part B
Write a Java program that prints rectangles of three different sizes to the screen, with a blank line between each rectangle.
• A 5 x 3 rectangle made of the letter ‘O'
• A 16 x 6 rectangle made of the letter ‘T'
• A 2 x 4 rectangle made of the left square bracket ‘%'
In the dimensions given above the first number is the horizontal width and the second number is the vertical height of the rectangle. Here is what your output should look like. Your program should be written in a flexible, general way so that the rectangle dimensions and the letter/character used to print each rectangle can be changed easily without rewriting the whole program.
Your program must have a class called RectangleMaker to do most of the work. The class RectangleMaker should have
1. Private fields that define:
a. The dimensions of the rectangle (width & height)
b. The character used to print the rectangle
2. Mutator methods (setters) to set the fields.
3. A print() method to print the rectangle.
4. Optional accessor methods (getters), not necessary.
5. The main() method that creates three objects (instances) of class RectangleMaker and call the print() methods. As usual keep your program efficient and try to minimize the amount of duplicated code.
Important: You should not use 'static' variables or methods except for the main() method declaration itself. Use one class that creates objects of its own type in the main() method.
Attachment:- Assignment.rar