Java Exercise 6 :





write a program to calculate relative size ranges for very small, small, medium, large, and very large ranges using standard deviation.

Thoroughly test the program.  Test the program using the data provided in tables 1, and 2.  Expected values are included in table 3.

Class Name
Class LOC
Number of Methods
each_char
18
3
string_read
18
3
single_character
25
3
each_line
31
3
single_char
37
3
string_builder
82
5
string_manager
82
4
list_clump
87
4
list_clip
89
4
string_decrementer
230
10
Char
85
3
Character
87
3
Converter
558
10
Table 1. LOC/Method Data

Chapter
Pages
Preface
7
Chapter 1
12
Chapter 2
10
Chapter 3
12
Chapter 4
10
Chapter 5
12
Chapter 6
12
Chapter 7
12
Chapter 8
12
Chapter 9
8
Appendix A
8
Appendix B
8
Appendix C
20
Appendix D
14
Appendix E
18
Appendix F
12
Table 2. Pgs/Chapter


VS
S
M
L
VL
LOC/Method
4.3953
8.5081
16.4696
31.8811
61.7137
Pgs/Chapter
6.3375
8.4393
11.2381
14.9650
19.9280
Table 3. Expected Values











relative size tables are used to give you a framework for judging the size of new parts in your planned products.  For example, if you know the sizes of all previously developed parts of a certain type, you can then better judge the likely size of a new part of that type.  The standard deviation procedure described in the following section allows you to balance your esimates so they more or less conform to the normal distribution. 

The medium range (M) is the area from -0.5 standard deviations to +0.5 standard deviations from the mean, as shown in Figure 1.  Assuming that the data approximates a normal distribution, the likely number of parts that are within plus or minus 0.5 standard deviation of the average value is 38.3 percent.  Following similar logic, the range percentages area are as follows:
·         6.68 % should be very small
·         24.17% should be small
·         38.2% should be medium
·         24.17% should be large
·         6.68% should be very large



Example of calculating a relative size table



Class Name
Class LOC
Number of Methods
LOC/method
each_char
18
3
6.0000
string_read
18
3
6.0000
single_character
25
3
8.3333
each_line
31
3
10.3333
single_char
37
3
12.3333
string_builder
82
5
16.4000
string_manager
82
4
20.5000
list_clump
87
4
21.7500
list_clip
89
4
22.2500
string_decrementer
230
10
23.0000
Char
85
3
28.3333
Character
87
3
29.0000
Converter
558
10
55.8000


Class Name
LOC/method
ln(xi)
each_char
6.0000
1.7918
string_read
6.0000
1.7918
single_character
8.3333
2.1203
each_line
10.3333
2.3354
single_char
12.3333
2.5123
string_builder
16.4000
2.7973
string_manager
20.5000
3.0204
list_clump
21.7500
3.0796
list_clip
22.2500
3.1023
string_decrementer
23.0000
3.1355
Char
28.3333
3.3440
Character
29.0000
3.3673
Converter
55.8000
4.0218
Total

36.4197




Class Name
LOC/method
ln(xi)
(ln(xi)-avg)2
each_char
6.0000
1.7918
1.0196
string_read
6.0000
1.7918
1.0196
single_character
8.3333
2.1203
0.4641
each_line
10.3333
2.3354
0.2173
single_char
12.3333
2.5123
0.0836
string_builder
16.4000
2.7973
0.0000
string_manager
20.5000
3.0204
0.0479
list_clump
21.7500
3.0796
0.0773
list_clip
22.2500
3.1023
0.0905
string_decrementer
23.0000
3.1355
0.1115
Char
28.3333
3.3440
0.2943
Character
29.0000
3.3673
0.3201
Converter
55.8000
4.0218
1.4890
Total

36.4197
5.2350



Program :
 

import java.text.DecimalFormat;

public class Day {
      double loc[]={18,18,25,31,37,82,82,87,89,230,85,87,558};
      double methods[]={3,3,3,3,3,5,4,4,4,10,3,3,10};

      public static void main(String[] args) {


            Day myobj=new Day();

            myobj.locpermethod();

      }

      public void locpermethod()
      {
            double locperm[]=new double[50];
            double tot=0,lo=0,avg=0,sq=0,tot1=0,avg1=0,srt=0;
            DecimalFormat df = new DecimalFormat("0.0000");
            for(int i=0;i<13;i++)
            {
                 
                  locperm[i]=loc[i]/methods[i];
                  lo=Math.log(locperm[i]);
                  tot=tot+lo;
     
            }
            avg=tot/13;
            System.out.println(df.format(tot));
            System.out.println(df.format(avg));
           
            for(int i=0;i<13;i++)
            {
                  lo=Math.log(locperm[i]);
                  sq=Math.pow((lo-avg),2);
                  tot1=tot1+sq;
                  }
           
            avg1=tot1/12;
            System.out.println(df.format(tot1));
            System.out.println(df.format(avg1));
            srt=Math.sqrt(avg1);
            System.out.println(df.format(srt));
           
            double vs=avg-(2*srt);
            double s=avg-srt;
            double m=avg;
            double l=avg+(srt);
            double vl=avg+(2*srt);
           
            System.out.println(df.format(vs));
            System.out.println(df.format(s));
            System.out.println(df.format(m));
            System.out.println(df.format(l));
            System.out.println(df.format(vl));

     
      }
         
}

Program developed by Rajkumar

Output :

36.4197
2.8015
5.2350
0.4363
0.6605
1.4805
2.1410
2.8015
3.4620
4.1225



1 comment :

  1. After the total that is 36.4197, the other values are not the expected values that appear in the table, there is something missing or are the values?

    ReplyDelete

Copyright © Rough Record. Designed by OddThemes