i need help with solving these two programs and write comment so i can understand

Analysis of Scores

Write a program that reads an unspecified umber of scores and determines how many scores are above or equal to the average and how many scores are below the average. For this exercise, assume that the maximum number of scores that can be entered is 50. Use a sentinel value of -1 to stop reading scores.

(Note: Neither the sentinel nor any negative values should be read into the array.)

You will need:

  • Scanner class for input
  • A 1 dimensional array that can hold up to 50 scores
    • Note: you are not expected to fill the entire array every time you test the code – this is why you need a sentinel
  • A while or do while loop to receive scores and calculate the running sum
  • A variable to keep track of the number of valid scores (e.g. count)
    • Don’t forget to initialize it to 0.
  • A nested if statement within the while/do-while loop to prevent negative values from being read into the array. This nested if statement should include:
    • A statement that assigns each valid score into the array
    • The calculation of the sum
    • The increment of count
      • Note: You do not have to inform the user to re-enter scores because you would already be in a loop that accepts new scores
  • An if else statement to report if useful values were entered.
    • If the sentinel was entered first then count should still be 0. In that case, do not calculate the average.
    • Otherwise, report the number of values and calculate the average
  • A second loop to compare each score to the average. (Use the variable count to determine when to stop the loop). This loop would include:
    • Another nested if statement to compare each score to the average
    • Two variables to keep track of the number of scores above or equal to the average and the number of scores below the average

(Tip: See Listing 5.7 in the text (pg. 215) for a reminder of how to use the sentinel, calculate a running sum, and keep track of values. It also shows you how to set up your code if no valid values are entered. This example is also in Module 6 materials, slide 19 in the lecture given on February 13th.)

Samples of the output is shown below:

Sample 1:

Enter a new score (enter -1 to stop): 90
Enter a new score (enter -1 to stop): 86
Enter a new score (enter -1 to stop): 72.5
Enter a new score (enter -1 to stop): 65.5
Enter a new score (enter -1 to stop): 57
Enter a new score (enter -1 to stop): 89
Enter a new score (enter -1 to stop): 78
Enter a new score (enter -1 to stop): 45
Enter a new score (enter -1 to stop): -1
The number of scores you entered is 8
Average is 72.875
Number of scores above or equal to the average: 4
Number of scores below the average: 4

Sample 2:

(Notice that a negative value is entered, but is ignored by the code when the number of valid scores and average is computed)

Enter a new score (enter -1 to stop): 90
Enter a new score (enter -1 to stop): 45
Enter a new score (enter -1 to stop): -57
Enter a new score (enter -1 to stop): 89
Enter a new score (enter -1 to stop): 67
Enter a new score (enter -1 to stop): 72.5
Enter a new score (enter -1 to stop): -1
The number of scores you entered is 5
Average is 72.7
Number of scores above or equal to the average: 2
Number of scores below the average: 3

Sample 3:

(This output shows you what should happens if you don’t enter any valid scores)

Enter a new score (enter -1 to stop): -1
No useful values were entered!
Average is 0.0
Number of scores above or equal to the average: 0
Number of scores below the average: 0

Positive Markov Matrix

An n x n matrix is a positive Markov Matrix if each element is positive and the sum of the elements in each column is 1.

Write a program that prompts the user to enter values for a 3 x 3 matrix. The program should then output the numbers in a matrix format and use a method to determine if it is a positive markov matrix. The method should return true if it is a positive markov matrix and return false if it is not.

You will need:

  • Scanner class for input
  • A 2 dimensional array that can hold 9 values
  • Nested for loops that do the following:
    • Input the values into the array
    • Print the values from the array in a 3 x 3 matrix format
  • An if else statement that uses the returned value from the method to report that the matrix is a positive markov matrix or not
  • A method that does the following:
    • Accepts a 2 dimensional array as a format parameter
    • Checks each element to see if it is positive
      • If an element is negative, return false
    • Finds the sum of values in each column
      • Don’t forget to initialize/reset your sum to 0!
      • If the sum is equal to 1, return true; otherwise return false.

Samples of the output is shown below:

Sample 1:

(Note that the user can enter the 9 values in a row, but the results are still output in a 3 x 3 matrix)

Enter a 3 by 3 matrix row by row:
0.15 0.875 0.375 0.55 0.005 0.225 0.3 0.12 0.4
The matrix you entered is:
0.15 0.875 0.375
0.55 0.005 0.225
0.3 0.12 0.4
It is a Markov matrix

Sample 2:

Here the values are entered in a matrix format by pressing enter after each 3rd value:

Enter a 3 by 3 matrix row by row:
0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.120 0.400
The matrix you entered is:
0.15 0.875 0.375
0.55 0.005 0.225
0.3 0.12 0.4
It is a Markov matrix

Sample 3:

Enter a 3 by 3 matrix row by row:
0.5 0 0 -0.5 0.5 0 0 -0.5 1
The matrix you entered is:
0.5 0.0 0.0
-0.5 0.5 0.0
0.0 -0.5 1.0
It is not a Markov matrix

Sample 4:

Enter a 3 by 3 matrix row by row:
4 5 6
7 8 9
1 2 3
The matrix you entered is:
4.0 5.0 6.0
7.0 8.0 9.0
1.0 2.0 3.0

It is not a Markov matrix

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.