Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Statistics Lab - Loop/ File IO NEED HELP!

  1. #1
    Junior Member
    Join Date
    May 2014
    Thanked 0 Times in 0 Posts

    Default Statistics Lab - Loop/ File IO NEED HELP!

    I'm desperate to try and solve this. I forgot to do this lab during mid semester in my computer science class and for some reason i'm drawing complete blanks. This is the last lab I need to complete for full credit. I put in some of the basic variables but really need help completing this.

    I don't have the text files with me.

     * Create a program that will calculate the min, max and average from a
     * data set(s).  The purpose of the lab is to implement a loop construct
     * along with the ability to perform file I/O.
     * 1) Place C4L2_Data1.txt, C4L2_Data2.txt, and C4L2_Data3.txt in the
     *    root directory of your project.  These are your input files.
     * 2) Each file has a list of numbers which is a combination of
     *    integer and floating point values.
     * 3) Each file has the same values, but in different order.
     * 4) Since it is likely you wouldn't know the count of values in an input
     *    file I suggest you use the while or do-while loop.
     * 5) Your program should read the data line-by-line evaluating each value
     *    to determine if it is the min or max while also accumulating the total
     *    which will be used to calculate the avergage upon reading all values.
     * 6) After you execute your program using C4L2_Data1.txt, run it again
     *    using the other two input files.  
     * 7) The purpose of having the same data amongst three files is to test
     *    the logic of your program to handle the case(s) where the min and max
     *    could be anywhere in the file.
     * 8) After you execute your program with the three files you should always
     *    obtain the same min, max, and average.  If your results differ between
     *    the input files then you have a logical error in your program
    import java.io.File;
    import java.util.Scanner;
    import java.text.DecimalFormat;
    public class C4L2_Statistics {
      public static void main(String[] args) throws Exception{
          double num; //Temporary var representing a single value from the file
          double min; //The minimum value in the file
          double max; //The maximum value in the file
          double average; //The average of the values
          int count = 0; //Keeps track of the number of values in the file
          double total = 0; //The accumulator
          DecimalFormat formatter = new DecimalFormat("#,##0.00");
    Last edited by shanevolution; May 3rd, 2014 at 04:17 PM.

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Statistics Lab - Loop/ File IO NEED HELP!

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly.

Similar Threads

  1. Industry Phone Statistics
    By aussiemcgr in forum Android Development
    Replies: 5
    Last Post: February 21st, 2013, 01:35 PM
  2. Need Help with While Loop Lab
    By LennDawg in forum Other Programming Languages
    Replies: 4
    Last Post: June 29th, 2012, 10:41 AM
  3. [SOLVED] Need statistics Homework help?
    By keith thomas in forum Java Theory & Questions
    Replies: 1
    Last Post: January 7th, 2011, 02:20 AM
  4. Black Jack Statistics game? lost.
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2010, 07:20 AM
  5. How to save statistics of a game in a binary file instead of txt file?
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 19th, 2009, 05:05 AM