Question

In: Computer Science

Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an...

  1. Programming assignment (75 pts):

The Lab 1 development assignment was largely an exercise in completing an already started implementation. The Lab 2 development assignment will call on you to implement a program from scratch. It’s an exercise in learning more about Java basics, core Java Classes and Class/ method-level modularity.

Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented.

  • NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric values do not need to be ordered (although you’ll need to display these values sorted ascendingly).

NOTE: Don’t prompt the user for input – this is an exercise passing values to your program via the command line!

  • Error checking: if the user fails to pass in parameters, the program will display an error message (of your choice) and exit early.
  • The main() method’s String [] args argument values must be converted and assigned to a numeric/integer array.
  • Your program will display the following information about the numbers provided by the user:
    1. This list of numbers provided by the user sorted ascendingly.
    2. The size of number list (the number of numbers!)
    3. The average or mean value.
    4. The median - the middle value of the set of numbers sorted. (Simple Algorithm: index = the length of the array divided by 2).
    5. The min value.
    6. The max value.
    7. The sum
    8. The range: the difference between the max and min
    9. Variance: Subtract the mean from each value in the list. This gives you a measure of the distance of each value from the mean. Square each of these distances (and they’ll all be positive values), add all of the squares together, and divide that sum by the number of values (that is, take the average of these squared values) .
    10. Standard Deviation: is simply the square root of the variance.

Development guidelines:

  • The output should be neat, formatted and well organized – should be easy on the eyes!
  • Your code should adhere to naming conventions as discussed in class.
  • Your main() method’s actions should be limited to:
    • gathering command line arguments
    • displaying error messages
    • creating an instance of NumericAnalyzer and invoking its top level method (e.g., “calculate()”, “display()” )
  • The “real work” should be performed by instance methods. That is, your implementation should embrace modularity:
    • Each mathematical calculation should probably be implemented by a separate method.
    • Yet another method should be responsible for displaying a sorted list of the numbers provided, and displaying all derived values above.

NOTE: Deriving calculations and displaying output to a Console are separate threads of responsibility, and should therefore be implemented independently of each other.

  • Your implementation should embrace using core Java modules:
    • Use the java.lang.Math Class methods to calculate square roots and perform power-to values.

So your main() method will include a sequence of instructions similar to this:

// main() method code fragment example
if(args.length == 0 ) {

// Display some error message … (System.err. )

System.exit(1);

}

NumericAnalyzer analyzer = new NumericAnalyzer(args);

analyzer.calculate();

analyzer.display();

System.exit(0);

Your ‘test cases’ should include testing for (see sample output below –PASTE YOUR Console OUTPUT ON PAGE 5 below):

  1. No input parameters – error condition.
  2. 1 value
  3. Multiple values – at least 6+ …

SAMPLE OUTPUT FOR TEST CASES 1, 2,   & 3

  1. Pass in 1 or more positive integer number values.

(2)

256

Count:                             1

Min:                             256

Max:                             256

Range:                             0

Sum:                             256

Mean:                            256

Median:                          256

Variance:                          0

Standard Deviation:                0

(3)

2    4    8    16   32   64   128 256 512

Count:                             9

Min:                               2

Max:                             512

Range:                           510

Sum:                           1,022

Mean:                            113

Median:                           32

Variance:                     25,941

Standard Deviation:              161

PASTE YOUR OUTPUT HERE

0 args

1 arg

multiple args (at least 6)

Sample output

2       4       8       16      32     64   128     256     512   

Size:                              9

Min:                               2

Max:                             512

Range:                           510

Sum:                           1,022

Mean:                            113

Median:                           32

Variance:                     25,941

Standard Deviation:              161

-----------------------------------------------------------------

Lab 1 java code (if needed)

public class JulianCalendar {

         

        static private final int MAX_DAY = 31;
         

        static private final String[] MONTH_NAMES = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",

        "Nov", "Dec" };

         

        static private final int[] MONTH_SIZES = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 

        static private void displayDayHeading() {

                System.out.printf("%6s", "Day");

        }
         

        static private void displayHeading() {

                displayDayHeading();

                for (int i = 0; i < MONTH_NAMES.length; ++i) {

                        System.out.printf("%5s", MONTH_NAMES[i]);

                }

                displayDayHeading();

        }

        static public void display() {

                displayHeading(); 

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

                        System.out.printf("\n%6d", i + 1);

                        for (int j = 0; j < MONTH_NAMES.length; j++) {

                                int sum = 0;

                                for (int k = 0; k < j; k++) {

                                        sum += MONTH_SIZES[k];

                                }

                                if (sum + MONTH_SIZES[j] >= sum + i + 1)

                                        System.out.printf(" %03d", sum + i + 1);

                                else

                                        System.out.printf(" %03d", 0);

                        }

                        System.out.printf("%6d", i + 1);

                }

                System.out.println();

        }



        public static void main(String[] args) {

                 

                display();

        }

}

Solutions

Expert Solution

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

class NumericAnalyzer{

int arr[];

int size;

int average;

int median;

int min;

int max;

int sum;

int range;

int variance;

int stdDev;

public NumericAnalyzer(String args[]){

size = args.length;

arr = new int[size];

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

arr[i] = Integer.parseInt(args[i]);

}

}

public void calcSum(){

sum = 0;

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

sum += arr[i];

}

}

public void calcAverage(){

calcSum();

average = sum/size;

}

public void calcMedian(){

if(size%2!=0)

median = arr[size/2];

else

median = (arr[size/2]+arr[(size/2)+1])/2;

}

public void calcMin(){

min = arr[0];

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

if(min>arr[i])

min = arr[i];

}

}

public void calcMax(){

max = arr[0];

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

if(max<arr[i])

max = arr[i];

}

}

public void calcRange(){

range = max-min;

}

public void calcVariance(){

calcAverage();

variance = 0;

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

variance += (average-arr[i])*(average-arr[i]);

}

variance /= size;

}

public void calcStdDev(){

calcVariance();

stdDev = (int)Math.sqrt(variance);

}

public void calculate(){

calcMin();

calcMax();

calcMedian();

calcRange();

calcStdDev();

}

public void display(){

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

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

}

System.out.println();

System.out.println("Count:\t\t"+size);

System.out.println("Min:\t\t"+min);

System.out.println("Max:\t\t"+max);

System.out.println("Range:\t\t"+range);

System.out.println("Sum:\t\t"+sum);

System.out.println("Mean:\t\t"+average);

System.out.println("Median:\t\t"+median);

System.out.println("Variance:\t\t"+variance);

System.out.println("Stanadard Deviation:\t"+stdDev);

}

}

public class NumericAnalyzerTest {

public static void main(String[] args) {

if (args.length == 0) {

// Display some error message … (System.err. )

System.out.println("Usage: numbers...");

System.exit(1);

}

NumericAnalyzer analyzer = new NumericAnalyzer(args);

analyzer.calculate();

analyzer.display();

System.exit(0);

}

}


Related Solutions

Using Maven and Web Programming Basics 1. Build a program using maven 75 pts A. Create...
Using Maven and Web Programming Basics 1. Build a program using maven 75 pts A. Create file structure Create a file structure for your program like the following: web_app → src → main → java → resources → webapp → target make sure you have in src/main/ the directories java, resources, and webapp. In most Java IDEs (Eclipse, IntelliJ, etc.) you can make a maven project, which will have this structure by default (without the webapp directory), you can use...
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the...
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) − (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers.
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
Lab Assignment 1 2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II STUDENT AFFAIRS DUE...
Lab Assignment 1 2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II STUDENT AFFAIRS DUE DATE: 14.10.2020 – 23:59 In this lab, we will create a model course registration application. Please check out the example run of the program first. You are asked to implement the classes; Student. Course. Grade. StudentAffairs. It will contain the main method. The commands and their arguments for this week are: createCourse <courseCode> <capacity> <day> <studentCount> <averageGrade> createStudent <studentName> <studentID> addGradeStudent <studentID> <letterGrade> addGradeCourse...
Assembly Language Programming Exercise 5. Listing File for AddTwoSum ( 5 pts ) Generate a listing...
Assembly Language Programming Exercise 5. Listing File for AddTwoSum ( 5 pts ) Generate a listing file for the AddTwoSum program and write a description of the machine code bytes generated for each instruction. You might have to guess at some of the meanings of the byte values. Hint: Watch my tutorial and read a little bit of Ch 4.
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a...
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a method swapNodes to SinglyLinkedList class. This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same nodes, etc. Write the main method to test the swapNodes method. Hint: You may need to traverse the list. Exercise 2 In this exercise, you will...
Lab Practical #1 On-line Determination of Bacteria. In this lab exercise you will be given the...
Lab Practical #1 On-line Determination of Bacteria. In this lab exercise you will be given the bacteria and you will need to explain what it would look like on the different medias (NG is suitable for No growth). BA=blood agar, CNA = Columbia nutrient agar, MA=MacConkey agar, MSA=mannitol salt agar, HE=Hektoen enteric Agar Staphylococcus Aureus: Gram stain __________________. Growth on Media: BA _________ CNA__________ MA__________MSA_________HE__________ One place where the bacteria causes infection ________. Streptococcus pneumoniae: Gram stain __________________. Growth on...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
Lab # 4 Multidimensional Arrays Please write in JAVA. Programming Exercise 8.5 (Algebra: add two matrices)...
Lab # 4 Multidimensional Arrays Please write in JAVA. Programming Exercise 8.5 (Algebra: add two matrices) Write a method to add two matrices. The header of the method is as follows: public static double[][] addMatrix(double[][] a, double[][] b In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element cij is aij + bij. For example, for two 3 * 3 matrices...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT