Question

In: Computer Science

Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...

Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire list of entries on one line and then the minimum, maximum, and average. values on separate lines with nice readable labels. 5. Make sure your code runs without error and handles bad inputs and 0 and negative numbers are valid. 6. Followed instructions and include to get full credit file must include your name, date, class and Javadoc code comments for each and every method as well as logic comments.m

Solutions

Expert Solution

If you have any doubts, please give me comment...

import java.util.Scanner;

public class Numbers{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        int numbers[] = new int[50];

        System.out.print("Enter number(Q or q to exit): ");

        String temp = scnr.next();

        int n=0;

        while(!temp.equalsIgnoreCase("Q")){

            numbers[n] = Integer.parseInt(temp);

            n++;

            System.out.print("Enter number(Q or q to exit): ");

            temp = scnr.next();    

        }

        if(n==0)

            System.out.println("No numbers are entered!");

        else{

            System.out.println("\nThe entered numbers are:");

            for(int i=0; i<n; i++){

                System.out.print(numbers[i]+" ");

            }

            System.out.println("\nMinimum: "+calcMinimum(numbers, n));

            System.out.println("\nMaximum: "+calcMaximum(numbers, n));

            System.out.println("\nAverage: "+calcAverage(numbers, n));

        }

    }

    public static int calcMinimum(int nums[], int n){

        int min = nums[0];

        for(int i=1; i<n; i++){

            if(min>nums[i])

                min = nums[i];

        }

        return min;

    }

    public static int calcMaximum(int nums[], int n){

        int max = nums[0];

        for(int i=1; i<n; i++){

            if(max<nums[i])

                max = nums[i];

        }

        return max;

    }

    public static double calcAverage(int nums[], int n){

        double avg = 0.0;

        for(int i=0; i<n; i++){

            avg += nums[i];

        }

        avg  /= n;

        return avg;

    }

}


Related Solutions

Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
Write a Java program that reads a list of 30 fruits from the file “fruits.txt”, inserts...
Write a Java program that reads a list of 30 fruits from the file “fruits.txt”, inserts them into a string array, and sorts the array in alphabetical order. String objects can be compared using relational operators such as <, >, or ==. For example, “abc” > “abd” is false, but “abc” < “abd” is true. Sample output: Before Sorting: Cherry, Honeydew, Cranberry, Lemon, Orange, Persimmon, Watermelon, Kiwifruit, Lime, Pomegranate, Jujube, Pineapple, Durian, Plum, Banana, Coconut, Apple, Tomato, Raisin, Mandarine, Blackberry,...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Write a program in Java that reads a file containing data about the changing popularity of...
Write a program in Java that reads a file containing data about the changing popularity of various baby names over time and displays the data about a particular name. Each line of the file stores a name followed by integers representing the name’s popularity in each decade: 1900, 1910, 1920, and so on. The rankings range from 1 (most popular) to 1000 (least popular), or 0 for a name that was less popular than the 1000th name. A sample file...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total number of numbers in the file, Calculate the sum of all the numbers in the file, Calculate the average of all the numbers in the file, Find the smallest value of all the numbers in the file, Find the largest value of all the numbers in the file, Calculate the standard deviation of all the numbers in the file
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all the lyrics from a file named lyrics.txt that is to be found in the same directory as the running program. The program should read the lyrics for each line and treat each word as a token. If the line contains a double (an integer is also treated as a double) it should use the first double it finds in line as the timestamp for...
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. In paragraph 1 Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. In pragraph 2 Replace "We" with v"i" This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would...
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. Replace "sh" with ph This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would not do that Paragraph 2 We...
Using Java Project 2: Deduplication Write a program that reads a file of numbers of type...
Using Java Project 2: Deduplication Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT