• Home
  • Blog
  •   These are two separate problems with attached starter codes for JAVA programming, I need help desperately. The project is due…

  These are two separate problems with attached starter codes for JAVA programming, I need help desperately. The project is due…

0 comments

 
These are two separate problems with attached starter codes for JAVA programming, I need help desperately. The project is due Sunday. 2/2
 
 
ARRAY PROJECT: Standard Deviation

The Standard Deviation is a statistic frequently used in education measurement.  

Write a program that will allow a user to enter a list of test scores (use 999 as a sentinel value).  These scores should be stored in an integer array.  Then a method calcStDev is invoked with the scores array as a parameter and should return the standard deviation.  Make sure you keep track of the number of scores that are input.

The standard deviation = (x-x)2n     

 

 x  = the average of all the scores,        x = a score in the array

 

    x    x           (x-x)     (x-x)2

    10    30    -20    400

    20    30    -10    100

    30    30    0    0                   

    40    30    10    100

    50    30    20    400

                1000 = sum of last column        st dev = 10005  = 14.1

STARTER CODE JUST PASTE IN
 
 

 

/**  STARTER CODE

* Write a description of class stDeviation: Allows a user to enter scores and then calculate std Dev.

*

* @author D.Engel

* @version 2015

*/

import java.util.Scanner;

 

public class stDeviation

{

   public static void main(String [] args)

   {

       System.out.println(“fStarting the standard deviation program…”);

       Scanner user = new Scanner(System.in);                  //data declarations

       int MAX = 100;

       int [] score = new int [MAX];

       int logLen = 0, value = 0;

              

       //seed loop value before entering and be sure it is a valid score

       System.out.print(“Please enter a score from 0 to 100 or 999 to end : “);

       value = user.nextInt();

       while ((value != 999) && (value <0 || value > 100))

       {

           System.out.print(“illegal input: Please enter a score from 0 to 100 or 999 to end : “);

           value = user.nextInt();

       }

       

       while ((value != 999) && (value >=0 && value <= 100))

       {

           //place valid score into array

           score[logLen]=value;

           logLen++;

           System.out.print(“Please enter a score from 0 to 100 or 999 to end : “);

           value = user.nextInt();

           while ((value != 999) && (value <0 || value > 100))

           {

               System.out.print(“illegal input: Please enter a score from 0 to 100 or 999 to end : “);

               value = user.nextInt();

           }

       }

       //all scores are now in the array – next find the average of all the scores

       if (logLen ==0)

            System.out.println(“no scores entered, the standard deviation is 0”);

        else

    {     double stdev = calcStdDev(score,logLen);

                  System.out.println(“The standard deviation of the scores entered is : “+ stdev);

          }

   }    //end of main

      

      /*

       * calcStdDev

       * @param : input array of scores

       *        : return standard deviation of the scores array

       */

      public static double calcStdDev(int [] s, int len)

      {

          //your code here

     }

       

        

}

 

ARRAYS PROJECT- asterisk

Design and implement an application that reads a set of values from 1 to 99 and creates a chart showing how often the values appeared.  The chart should look like the one shown here.   It shows how many values fell in the range 0 to 9, 10 to 19, and so on.  Prints asterisks for each value entered.  If we use one asterisk for each value then the line of asterisks may be too long, so the program should print out an asterisk for every five values in each category – ignore the leftovers.  For example, if the category had 17 values, print three asterisks in that row.  If a category had 4 values, then do not print any asterisks in that row.   Your program must use at least one array but it can use more if you would like.  An example of the output is below:

0 – 9      | *****

10-19      | **

20-29      |***********************

30-39      | *************

40-49      | **

50-59      | *****

60-69      | *********

70-79      |

80-89      | ******

90-99      | *************

The values to be used are in the test file called values.txt – copy this from google classroom to your s drive.
These are the values I have to use for the code –
8 22 33 44 55 66 77 88 99 95
5 20 35 49 51 60 32 80 85 89
3 81 81 82 99 91 92 93 94 95
21 74 73 37 88 22 29 27 38 37
55 56 77 75 72 78 88 81 92 1
21 74 73 37 88 22 29 27 38 37
55 20 35 49 51 60 32 80 85 89
83 81 81 82 99 91 92 93 94 95
21 74 73 37 88 22 29 27 38 37
98 88 77 66 98 89 90 22 44 33
88 80 81 89 88 84 85 82 83 81
55 56 77 75 72 78 88 81 92 1 999
 
 
STARTER CODE JUST PASTE IN
 
 

/**  STARTER CODE

* Write a description of class asterisk here.

*

* @author (your name)

* @version (2015)

*/

 

import java.util.Scanner;

import java.io.*;

 

import java.io.*;

 

public class asterisk

{

   public static void main(String [] args)throws FileNotFoundException

   {

       // The name of the file to open.

       String fileName = “s:\values.txt”;                 //your file name here

       File aFile = new File(fileName);

       Scanner scan = new Scanner(new FileReader(aFile));

       int value=0;

       int [] numbers = new int [10];

       while (scan.hasNext() && value !=999)

       {

           value = scan.nextInt();                            //value is  in the file

           if (value !=9999)

           {

               // your code here to tally in the numbers array

 

               

               

           }

           

       }

       scan.close();                   //close the file

       

       //output Histogram

       //your code here

   }

}

 

 

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}