Question
Calling on my Chegg experts, I need your help on this long difficult task I have to complete this week. Below is the task for
Calling on my Chegg experts, I need your help on this long difficult task I have to complete this week. Below is the task for this week. Since many people had problems with this weeks task the instructor gave us SKELETON CODE (S-CODE) that he would like us to use when writing the program. I need your help CHEGG writing the code within the guidelines of the S-CODE. The book for the class is Introduction to Java Programming, Comprehensive Version Y. Daniel Liang & Prentice Hall 11th Edition / 2018. We are currently working in Chapter 12. but this task covers all learned from week 1 through week 12.
Below is the TASK
Write a program that writes user supplied data to a text file and can perform a few statistical calculations on the data.
Constraints
The file directory will be C:/W12Assignment. Mac and Linux distro users can modify this location (What do they mean by this how do I modify for my MAC?)
Only one file will be created, used, and updated while the program runs
Requirements
Use exception handling and validation where appropriate
Use PrintWriter and Scanner for writing and reading data
Use a separate (external to the main class) subclass to write data
Use a separate (external to the main class) subclass to read data
Use a separate (external to the main class) subclass to validate entries
Use set and get methods in the subclasses
Find the average of all the numbers in the file
Find the smallest number in the file
Find the largest number in the file
Find the standard deviation (StdDev) of the number set (Follow the Basic Example as a
model for your StdDev algorithm located here at https://en.wikipedia.org/wiki/Standard_deviation
Implement a loop to run the program again if the user wishes (Note: this will only allow updates
or reading of the same file since only one file is used for duration of the program run)
Use the supplied MyNumbersLarge.txt file to make sure you are obtaining the correct
information as such:
o All numbers printed (500 numbers) o The average of the numbers in file name is: 502.3212 o The smallest number in the file is: 1.2416 o The largest number in the file is: 999.3116 o The standard deviation for the numbers in this file is: 287.6556
This program will utilize code learned from Week 1 through Week 12
Hints
Consider using an ArrayList of Doubles to store numbers as they are entered
Research Collections to assist with minimums and maximums
Considering writing the code to work with all correct entries before implementing validation and
-exception handling. Once the code works, then try to break it with bad entries. This way, you
-can separate the requirements (Code in chunks!)
Make sure you use Java coding conventions
Expected Output
The following pages show a sample run with a few iterations. User input is in BOLD Additional notes identified with arrow and dashes <-----------
Welcome to My Statistics Calculator Enter the name of your text file (e.g. MyNumbers) The file extension will be added after entry.
(How do I do this?)
->: MyNumbers <--------------note you must add the extension .txt in your code
The directory does not exist. Creating directory... Directory created at this location ->: C:\W12Assignment <----------if either the directory or the file do not exit, create them. If they do, notify the user that they exist.
The file does not exist. Creating file... File created at this location ->: C:\W12Assignment\MyNumbers.txt <---------if either the directory or the file do not exit, create them. If they do, notify the user that they exist.
Please select from the following menu of options:
1. Enter Data 2. Read Data 3. Exit
->: 2
The file contains no data. Enter data? ->: n <------------The user should be able to enter data here if they wish. Would you like to run the program again? ->: y
Please select from the following menu of options:
1. Enter Data 2. Read Data 3. Exit
->: 1
How many numbers would you like to send to the file? ->: 6
Enter number 1 -> 89.635 Enter number 2 -> 100.3069 Enter number 3 -> 101.0009
Enter number 4 -> 95.365 Enter number 5 -> 99.3644 Enter number 6 -> 90.00049 Would you like to read the see the results? ->: y
The numbers in this file are:
89.6350 100.3069 101.0009 95.3650 99.3644 90.0005 The average of the numbers in file name is: 95.9455
The smallest number in the file is: 89.6350
The largest number in the file is: 101.0009 The standard deviation for the numbers in this file is: 4.6863
Would you like to run the program again? ->: y
Please select from the following menu of options:
1. Enter Data 2. Read Data 3. Exit
->: 2
The numbers in this file are:
89.6350 100.3069 101.0009
95.3650 99.3644 90.0005 The average of the numbers in file name is: 95.9455
The smallest number in the file is: 89.6350
The largest number in the file is: 101.0009 The standard deviation for the numbers in this file is: 4.6863
Would you like to run the program again? ->: y
Please select from the following menu of options:
1. Enter Data 2. Read Data 3. Exit
->: 1 <-----------If the user wishes to enter data again then all data in the current fille will be replaced with new data
How many numbers would you like to send to the file? ->: 3
Enter number 1 -> 789.3600 Enter number 2 -> 790.4600 <--------If the user wishes to enter data again then all data in the current fille will be replaced with new data Enter number 3 -> 698.9900
Would you like to read the see the results? ->: y
The numbers in this file are: 789.3600 790.4600
698.9900 The average of the numbers in file name is: 235.6064 The smallest number in the file is: 89.6350 The largest number in the file is: 790.4600 The standard deviation for the numbers in this file is: 179.6279
Would you like to run the program again? ->: n Thank you for using the program! Good Bye!
Expected output (I downloaded .txt file and the numbers are below.
(I need to add these number as a .txt file how do I do this?)
588.0404
1.8024
796.2091
187.1421
913.5861
562.0032
398.7931
300.7516
691.1280
561.7554
345.0988
517.3222
801.3383
89.4341
593.7353
981.4529
700.4672
842.6350
586.4591
140.0335
590.5660
847.0467
533.6489
275.4296
148.7136
143.1141
921.2031
498.7419
55.6438
639.2337
375.7029
278.6517
102.1831
652.6057
949.9356
748.0228
763.1718
153.6562
636.6267
582.1941
358.4062
590.4848
735.7230
547.1980
729.5120
839.1169
312.3900
496.9060
924.9727
286.4120
681.1210
600.5570
421.7771
576.4295
362.4861
990.8485
711.2038
350.3288
150.6715
424.2155
24.9271
554.3728
474.6541
761.1032
20.3024
797.5754
375.2626
816.8862
430.2377
577.5020
850.0525
804.7889
494.0800
88.4272
356.6653
857.7006
294.6377
23.2147
517.6072
562.3849
857.1135
826.3703
910.5834
882.1574
664.0634
197.0440
825.1341
605.1174
221.8751
775.0522
518.0574
610.7801
486.6121
807.1619
459.1286
870.7134
953.5621
88.3601
133.8460
892.4429
341.6915
258.3062
274.9971
725.7676
892.5722
418.0810
565.6779
689.6867
614.4455
71.6363
870.6985
519.9652
948.2832
101.8197
971.9652
177.6445
875.2482
601.3602
805.5316
18.4893
609.1291
110.4279
317.9489
830.9979
322.9913
325.7546
215.6010
427.1931
36.0541
291.8477
835.5779
190.1979
282.9873
694.5902
306.0921
147.6094
81.4356
927.6904
27.9071
817.2867
810.9055
449.4563
998.6847
587.8673
929.3619
517.8548
524.0459
842.3743
949.7916
457.4106
970.7438
557.0282
143.3081
729.9803
805.6974
952.8297
538.1010
362.9612
558.4033
532.7070
185.3231
64.5726
79.3799
312.2817
453.8534
256.9978
535.7240
117.5080
566.5487
909.1575
891.9026
623.3489
670.9335
375.9949
698.1215
711.4962
222.9955
705.0119
218.1998
478.9778
865.1153
927.0552
94.6078
154.5682
135.5920
504.5733
396.1988
248.9294
606.8202
585.3740
87.1378
722.2657
7.2816
620.7662
821.7577
27.9664
89.9640
410.1543
819.3470
74.1460
434.7925
927.5058
804.9614
408.9735
710.2472
782.8044
217.5289
739.7886
739.3300
592.7230
110.5417
646.8143
314.9320
144.0187
109.3729
329.5919
49.9437
274.3749
710.7683
420.3713
726.8851
659.6910
712.6249
648.4428
442.8629
921.2601
841.1889
286.5431
801.9144
870.1773
753.9283
227.0065
666.4983
618.6658
502.0801
802.3206
687.7633
31.8126
286.8506
671.1931
869.7880
979.1742
406.2071
584.3213
33.0796
296.9150
993.1300
937.9262
274.6397
284.2520
636.1334
985.4342
174.1475
890.0089
925.7979
366.1684
451.4462
98.6472
7.9340
238.4342
113.5635
542.4935
848.0661
63.8003
576.0465
1.2416
513.0439
382.8866
923.0236
851.2038
670.7651
498.7931
76.9642
909.2212
990.9131
396.9182
761.8651
2.8189
333.5505
367.5546
335.7282
143.4794
729.3989
958.6923
433.8809
261.2837
154.4472
334.1416
57.3908
190.9248
54.8194
274.5043
111.1228
586.2439
112.2041
180.0953
11.8281
652.7943
113.0369
806.1284
749.8562
473.5225
58.2603
404.3629
891.1758
966.1444
31.7866
278.1248
709.4295
915.4521
302.2412
210.3074
458.8659
315.5073
803.2415
645.3773
546.4924
550.4559
763.5641
318.2033
915.2083
285.6920
645.4679
252.4024
851.0548
370.5136
330.4132
588.2498
577.0240
391.2195
838.1349
563.2447
332.0691
484.2559
564.7372
69.5830
717.9360
874.2169
678.4950
252.8561
508.4068
755.6400
49.4928
415.5923
539.9353
833.8474
160.7384
20.9476
550.3614
137.2525
259.5675
105.4479
240.1246
386.5260
492.7529
577.2400
934.4845
170.6696
343.8803
852.8622
768.4380
641.3442
382.7333
391.6423
832.6928
711.5520
315.2522
461.8681
540.9083
99.7503
85.0544
411.8822
737.6714
597.5859
58.1690
417.5036
853.6539
462.9997
506.6597
457.9555
871.7473
992.1552
983.2187
72.2241
215.1809
932.3528
289.2514
844.8102
129.1300
796.7864
963.4398
109.0223
462.4344
122.1240
448.0579
453.0650
83.1267
23.3310
299.1306
13.3609
737.4086
683.2768
486.1555
444.1339
549.8032
911.4697
326.3280
947.2593
700.1402
599.2472
24.0355
149.5580
921.4538
373.1252
262.9807
135.2126
659.8402
725.2453
44.2587
666.1363
665.5406
914.2352
431.6242
397.8444
303.9959
709.5794
407.0260
724.2926
248.4480
576.6962
213.0153
690.7014
776.7001
75.2919
49.3305
208.4368
724.9339
782.3799
200.9543
355.8919
841.8875
12.6172
600.9618
605.5890
225.1065
406.9080
908.3569
16.8593
589.1662
201.4270
643.5193
221.4490
275.5347
82.1463
486.5421
666.5026
223.4184
821.1481
76.9245
689.2036
896.2459
622.5702
139.3342
355.4270
188.2754
773.9769
788.7121
252.2420
336.4170
899.8276
649.1331
900.4704
53.1810
828.2534
550.3576
999.3116
950.1910
655.3838
573.8862
776.8237
597.6887
264.2085
615.2555
377.2088
366.8262
954.0966
489.6323
771.2001
25.1834
518.6808
785.1155
195.2235
379.1435
887.8645
637.7054
800.4876
910.1807
466.5068
875.6005
219.5030
**************************************************************************************************************************************************
Below in Bold is Week 12 Skeleton Code S-Code from the Instructor
Week12_Skeleton
package week12_skeleton;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name:
* @Assignment Name: week12_skeleton
* @Date: Nov 21, 2016
* @Description:
*/
//Imports
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.InputMismatchException;
//Begin Class Week12_Skeleton
public class Week12_Skeleton {
/**
* Declare some static variables and objects so they may have class-wide scope
*/
/* New Class-wide Scanner object */
/**
* Subclass declarations. Declare the three subclasses. ReadData is complete
*/
static ReadData_Skeleton rData = new ReadData_Skeleton();
//WriteData declaration
//CheckErrors declaration
/*
* Class-wide variables here
*/
//Static String variable for you answer loop (to rerun)
static final File FILE_DIR = new File("C:/W12Assignment"); /* Default assignments */
static File file = new File("C:/W12Assignment/MyNumbers.txt"); /* Default assignments */
//Declare a static boxed ArrayList here to store number
static boolean exit = false; //Used for an exit flag
//Begin Main Method
public static void main(String[] args) throws FileNotFoundException, IOException {
//Instance of the subclass CheckErrors_Skeleton here
/*
* Variables
*/
//Menu choice integer
//Exit number to be used in an exit method below. Type int initialized to 1
//Integer variable for the lower range of the menu. Used for validation. Set = to 1
//Integer variable for the upper range of the menu. Used for validation. Set = to 3
//Welcome statement here
/**
* Call menu options list method (below)
*/
enterFileName();
//Begin outer do loop here
do {
/**
* Handle menu selections. Validate and check for errors. Begin an
* inner do loop here (below this comment block)
*/
do {
System.out.println("Please select from the following menu of options:");
//Output menu of options here
/**
* Begin try block here (below this comment block). This will be
* used to validate the user's entry is an integer AND if it is
* within range.
*/
try {
//Begin 2nd inner do loop here
do {
//Receive the user's input from the menu here
/*Call set method (below this comment): Name of error checking subclass.setRange(User's menu choice, Integer variable for the lower range, Integer variable for the upper range);*/
System.out.println(); //Clears the buffer
/**
* End 2nd inner do loop here (below this comment block) with
* while that looks for a boolean value from the check errors
* subclass method
*/
} while (!/*Name of error checking subclass.getRange()*/);
} catch (InputMismatchException IME) {
System.err.println("Exception. You must enter a number. Please try again.");
sc.nextLine(); //Clears the buffer
}
} while (!/*Name of error checking subclass.getRange()*/); // End inner do loop
/* Handle menu entries */
switch (/*variable used for menu choice entry*/) {
case 1:
//Call to write data to a file method here
System.out.print("Would you like to read the see the results? ->: ");
//Begin do loop
do {
ans = sc.next();
if (ans.equalsIgnoreCase("Y")) {
//Call to read data from file method here
} else if (ans.equalsIgnoreCase("N")) {
break;
}
/*Name of error checking subclass.setYesNo(ans);*/
} while (!/*Name of error checking subclass.getYesNo()); // End inner loop */
break;
case 2:
//Call to read data from file method here
break;
case 3:
/**
* Call to exit method here and send it the exit number. This should
* be a 1 as initialized above that will exit the program
* cleanly. See Exit method below
*/
break;
default:
/**
* First, set exit number to 2 here. Then,
* Call to exit method here and send it the exit number. This
* should be a 2 as set just above. This will exit the program
* with a fault. See Exit method below
*/
break;
}
do { //Begin another do loop here
System.out.print("Would you like to run the program again? ->: ");
ans = sc.next();
if (ans.equalsIgnoreCase("Y")) {
exit = false;
} else {
exit = true;
}
//Call to check input /*Name of error checking subclass.setYesNo(ans, exit); /* Send answer to CheckErrors subclass for eval */
} while (!/*Name of error checking subclass.getYesNo()*/); // End inner loop
} while (ans.equalsIgnoreCase("Y"));
} //End Main Method
/**
* Method readData: Used to call to subclass ReadData to read a files
* contents Find minimum, maximum, average, and standard deviation of
* numbers in file
*
* @throws FileNotFoundException
*/
public static void readData() throws FileNotFoundException {
if (file.length() != 0) { //Check file length is not = 0
/*name of read data subclass*/.setData(/*send file directory declared at top, send file declared at top */);
try (Scanner input = new Scanner(file)) {
System.out.println("The numbers in this file are:");
while (input.hasNextLine()) {
String line = input.nextLine();
System.out.println(line);
}
}
System.out.printf("The average of the numbers in file name is: %.4f ", /*name of read data subclass.get average method from subclass*/());
System.out.printf("The smallest number in the file is: %.4f ", /*name of read data subclass.get smallest number method from subclass*/());
System.out.printf("The largest number in the file is: %.4f ", /*name of read data subclass.get largest number method from subclass*/());
System.out.printf("The standard deviation for the numbers in this file is: %.4f ", /*name of read data subclass.get standard deviation method from subclass*/());
} else {
System.out.print("The file contains no data. Enter data? ->: ");
do {
ans = sc.next();
if (ans.equalsIgnoreCase("Y")) {
//Call Write data method
System.out.print("Would you like to read the see the results? ->: ");
do {
ans = sc.next();
if (ans.equalsIgnoreCase("Y")) {
//Call read data method
} else if (ans.equalsIgnoreCase("N")) {
break;
}
/*Name of error checking subclass.setYesNo(ans);*/
} while (!/*Name of error checking subclass.getYesNo()*/); // End inner loop
} else if (ans.equalsIgnoreCase("N")) {
break;
}
/*Name of error checking subclass.setYesNo(ans);*/
} while (!/*Name of error checking subclass.getYesNo()*/); // End inner loop
}
}
/**
* Method Exit: Used to exit program cleanly
*
* @param num
*/
public static void Exit(int num) {
if (num == 1) {
//Tell user goodbye
System.exit(0);
} else {
//Tell user there was a System Error Exiting Program"
System.exit(1);
}
}
/**
* Method writeData: Used to write data to file
*
* @throws FileNotFoundException
*/
private static void writeData() throws FileNotFoundException {
int high; /*Used for number of elements to enter*/
double num; /*variable for entered number*/
boolean flag; /* Used for outer do loop */
boolean iFlag; /* Used for inner do loop */
do { //Begin do loop
System.out.print("How many numbers would you like to send to the file? ->: ");
try { //Begin try block
/*variable for number of elements = sc.nextInt();*/
do { //Begin inner do loop
for (int i = 1; i <= high; i++) {
try {
System.out.printf("Enter number %d -> ", i);
/*variable for entered number = sc.nextDouble();*/
/*static ArrayList to store numbers declared at top of code.add(num);*/ //Add user entry to arraylist
} catch (InputMismatchException IME) { //Catch block to catch errors
iFlag = false; //If error, set inner flag variable
sc.nextLine(); /* Clear buffer */
i -= 1; //Reset counter variable
System.err.println("Entry Error: Please enter a number.");
}
}
iFlag = true; //Reset value if errored once so it can continue on a proper entry after retry
} while (!iFlag); //Condition to continue loop
/*Name a object variable declared for the WriteData subclass from top of code.setData(file directory variable, file variable, variable for number of elements, high variable declared in this method);*/
flag = true; //reset outer flag value
} catch (InputMismatchException IME) {
/*set outer flag value to false*/
sc.nextLine(); /* Clear buffer */
System.err.println("Entry Error: Please enter a number.");
}
} while (!flag); //While inner flag variable is true
/*static ArrayList to store numbers declared at top of code.clear();*/ //clears the arraylist of all values.
}
/**
* Method enterFileName: Used to create file and directory
*
* @throws IOException
*/
private static void enterFileName() throws IOException {
/*Declare a String variable for file name*/
System.out.print("Enter the name of your text file (e.g. MyNumbers) "
+ "The file extension will be added after entry. ->: ");
/*String variable for file name = sc.next();*/
/*Declare another (different) String variable for file name and set equal to fName.concat(".txt");*/
File file_Name = new File(/*file directory variable*/ + "/" + /*variable for file name declared on line directly above this line*/);
/* Create directory */
if (!/*file directory variable*/.exists()) {
/*file directory variable*/.mkdirs();
System.out.printf(" The directory does not exist. Creating directory..."
+ " Directory created at this location ->: "
+ "%s ", /*file directory variable*/.getAbsolutePath());
} else {
System.out.printf(" The directory exists at this location ->: "
+ "%s ", /*file directory variable*/.getAbsolutePath());
}
/* Create file */
/*file variable declared at top of code*/ = file_Name;
if (!/*file variable declared at top of code*/.exists()) {
System.out.println("The file does not exist. Creating file...");
/*file variable declared at top of code*/.createNewFile();
System.out.printf(" File created at this location ->: "
+ "%s ", /*file variable declared at top of code*/.getAbsolutePath());
} else {
System.out.printf("The file exists at this location ->: "
+ "%s ", /*file variable declared at top of code*/.getAbsolutePath());
}
}
} //End Class Week12_Skeleton
********************************************************************************************************************************************
CheckErrors
package week12_skeleton;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name:
* @Assignment Name: week12_skeleton
* @Date: Nov 21, 2016
* @Subclass CheckErrors_Skeleton Description:
*/
//Imports
import java.util.Scanner;
//Begin Subclass CheckErrors_Skeleton
public class CheckErrors_Skeleton {
//Declare a private boolean variable for a flag
//New Scanner object here
//SET METHODS*******************************************************************
/**
* Method setYesNo: Used to set result for checking proper entry of Yes or
* No to continue program. Method is overloaded
*
* @param ans
* @param exit
*/
public void setYesNo(String ans, boolean exit) {
if (!(ans.equalsIgnoreCase("Y") || ans.equalsIgnoreCase("N"))) { //If not either y of n
System.err.println("Exception! Please enter only a Y for Yes or an N for No.");
/*Private variable declared above for flag*/ = false;
} else if (ans.equalsIgnoreCase("y")) {
System.out.println();
/*Private variable declared above for flag*/ = true;
} else if (ans.equalsIgnoreCase("n") && !exit) {
System.out.println();
/*Private variable declared above for flag*/ = true;
} else {
System.out.println("Thank you for using the program! Good Bye!");
/*Private variable declared above for flag*/ = true;
}
}
/**
* Method setYesNo: Used to set result for checking proper entry of Yes or
* No
*
* @param ans
*/
public void setYesNo(String ans) {
if (!(ans.equalsIgnoreCase("Y") || ans.equalsIgnoreCase("N"))) {
System.err.println("Exception! Please enter only a Y for Yes or an N for No.");
/*Private variable declared above for flag*/ = false;
} else if (ans.equalsIgnoreCase("y")) {
/*Private variable declared above for flag*/ = true;
} else {
/*Private variable declared above for flag*/ = false;
}
}
/**
* Method setRange: Used to set method to check for menu range
*
* @param x
* @param minVal
* @param maxVal
*/
public void setRange(int x, int minVal, int maxVal) {
if ((x < minVal) || (x > maxVal)) {
/*Inform user of exception here. Use formatted output and tell user choice must be between minVal and maxVal*/
/*Private variable declared above for flag*/ = false;
} else {
/*Private variable declared above for flag*/ = true;
}
}
//GET METHODS*******************************************************************
/**
* Method getYesNo: Return boolean value for loop in main that checks for
* proper entry
*
* @return
*/
public boolean getYesNo() {
return /*Private variable declared above for flag*/;
}
/**
* Method getRange: Return boolean value for menu range checking
*
* @return
*/
public boolean getRange() {
return /*Private variable declared above for flag*/;
}
} //End Subclass CheckErrors_Skeleton
****************************************************************************************************************************************
readData
package week12_skeleton;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name:
* @Assignment Name: week12_skeleton
* @Date: Nov 21, 2016
* @Subclass ReadData_Skeleton Description:
*/
//Imports
import java.io.File;
import java.io.FileNotFoundException;
import static java.lang.Math.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
//Begin Subclass ReadData_Skeleton
class ReadData_Skeleton {
/* Declare the following Variables */
//Private File type variable for file. Example: private File fFile;
//Private File type variable for file directory
//Private double variable (number 1) for average and initialize to = 0;
ArrayList nums = new ArrayList<>(); //Used for numbers
ArrayList sdNums = new ArrayList<>(); //Used for standard deviation calculation
//private double for maximum value
//private double for minimum value
//Another private double variable for average (number 2) and initialize to = 0; Different name than one above
//Another private double variable for average (number 3)and initialize to = 0; Different name than two above
//Private double for a standard deviation and initialize to 0;
//SET METHODS*******************************************************************
/**
* Method setData: Method to read numbers from the file and place them into
* an ArrayList. The list is then sent to the other set methods
*
* @param fileDir
* @param file
* @throws FileNotFoundException
*/
public void setData(File fileDir, File file) throws FileNotFoundException {
//File type variable for file declared at top = file;
//File type variable for file directory declared at top = fileDir;
nums.clear(); /* Clears numbers from array for input of new data */
//Try block to add data
try (Scanner input = new Scanner(file)) {
while (input.hasNextLine()) {
nums.add(input.nextDouble());
}
}
//Call set average method and send it (nums);
//Call set method for min and max (one method, below) and send it (nums);
//Call standard deviation method and send it (nums);
}
/**
* Method setAvg: Used to calculate the average of the numbers in the file
*
* @param nums
*/
private void setAvg(ArrayList nums) {
/* Rest variable */
/*variable for average (number 1) declared at top*/ = 0;
/*for loop throw the nums arraylist and add each element to the next for a total of all elements (which will be avg variable declared in this method*/
/*variable for average (number 1) declared at top*/ /= nums.size();
}
/**
* Method setMinMax: Determine min and max values of data in file
*
* @param nums
*/
private void setMinMax(ArrayList nums) {
/*variable for maximum value*/ = Collections.max(nums); //Finds the highest number in the set
/*variable for minimum value*/ = Collections.min(nums); //Finds the lowest number in the set
}
/**
* Method setStdDev: Used to determine the StdDev for the file data
*
* @param nums
*/
private void setStdDev(ArrayList nums) {
/* Rest variables */
/*variable for average (number 3) declared at top*/ = 0;
/*variable for a standard deviation declared at top */= 0;
/* reset array */
sdNums.clear();
/* Get Mean/Average of numbers */
/*variable for average (number 2) declared at top*/ = getAvg();
/**
* Calculate deviations for each number and place the results into a new
* ArrayList.
*/
for (double i : nums) {
i -= /*variable for average (number 2) declared at top*/;
sdNums.add(pow(i, 2));
}
/**
* Get Mean/Average of numbers in new ArrayList
*/
for (double x : sdNums) {
/*variable for average (number 3) declared at top*/ += x;
}
/**
* Find variance which is mean/average of new ArrayList
*/
/*variable for average (number 3) declared at top*/ /= sdNums.size();
/**
* The population standard deviation = SQRT of variance
*/
/*variable for standard deviation*/ = sqrt(/*variable for average (number 3) declared at top*/);
}
//GET METHODS*******************************************************************
/**
* Method getAvg: Return the calculated average
*
* @return avg
*/
public double getAvg() {
return /*variable for average (number 1) declared at top*/;
}
/**
* Method getMax: Return max value
*
* @return max
*/
public double getMax() {
return /*variable for maximum value*/;
}
/**
* Method getMin: Return min value
*
* @return min
*/
public double getMin() {
return /*variable for minumim value*/;
}
/**
* Method getStdDev: return calculated StdDev
*
* @return sd
*/
public double getStdDev() {
return /*variable for standard deviation*/;
}
} //End Subclass ReadData_Skeleton
***********************************************************************************************************************************************
writeData
package week12_skeleton;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name:
* @Assignment Name: week12_skeleton
* @Date: Nov 21, 2016
* @Subclass WriteData_Skeleton Description:
*/
//Imports
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
//Begin Subclass WriteData_Skeleton
class WriteData_Skeleton {
/* Variables */
//Private File type variable for file. Example: private File fFile;
//Private File type variable for file directory
/**
* Method SetData: Used to write data passed in the form of an ArrayList
* into a data file.
*
* @param fileDir
* @param file
* @param nums
* @param max
* @throws FileNotFoundException
*/
void setData(File fileDir, File file, ArrayList nums, int max) throws FileNotFoundException {
/*variable for file*/ = file;
/*variable for file directory*/ = fileDir;
int flag = 1; //Flag variable
try (PrintWriter output = new PrintWriter(file)) {
for (double i : nums) {
if (flag < max) {
output.printf("%.4f" + System.getProperty("line.separator"), i);
flag += 1;
} else {
output.printf("%.4f", i);
}
}
output.close();
}
}
} //End Subclass WriteData_Skeleton
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started