Results 1 to 2 of 2
  1. #1
    erichfx is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Read from a text file, then calculate min/max/mode/mean/median...?

    Hello, I am required to write a program that reads from a program a list of grades, then outputs the min/max/mode/median/mean of these grades. What am I genuinely confused with is where to start....? I understand the logic behind the mathematics calculations, however, I don't understand how to structure my program. I've created an array with a max amount of grades in the file being 500. Do I create new methods for each calculation (ie: public static int min ( ))? I'm confused, any guidance would be appreciated. Here is my code thus far.




    Java Code:
    import java.util.Scanner;
    import java.io.*;
    public class statistics
    {
        public static void main (String [] args)
        {
            System.out.println("What file contains the data?");
            Scanner kbd = new Scanner(System.in);
            System.out.println("The maximum grade is: ");
            System.out.println("The minimum grade is: ");
            System.out.println("The mean grade is: ");
            System.out.println("The median grade is: ");
            System.out.println("The modal grade is: ");
        int [] grades = new int [500];
        int count = 0;
        try
        {
            input = new Scanner (new File(file));
        }
        catch(FileNotFoundException e)
        {
            System.err.println("Error blah blah blah");
            System.exit(0);
        }
        while(input.hasNext())
        {
            grades[count] = input.NextInt();
            System.out.println(grades[count]);
            count++;
        }
        input.close();
        Arrays.sort(grades, 0, count);
        }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,043
    Blog Entries
    7
    Rep Power
    23

    Default Re: Read from a text file, then calculate min/max/mode/mean/median...?

    Quote Originally Posted by erichfx View Post
    Do I create new methods for each calculation (ie: public static int min ( ))?
    Yes, do so; it keeps your code cleaner.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Median and mode HELP!
    By Gamedisolver in forum New To Java
    Replies: 2
    Last Post: 10-09-2012, 06:14 AM
  2. Calculating Median and mode
    By rochla16 in forum New To Java
    Replies: 4
    Last Post: 04-29-2011, 04:24 AM
  3. open a file using read or write mode
    By swati.jyoti in forum New To Java
    Replies: 2
    Last Post: 04-25-2009, 04:44 PM
  4. Open xls file in read-write mode
    By rdhaware in forum Advanced Java
    Replies: 1
    Last Post: 02-03-2009, 09:12 AM
  5. Replies: 40
    Last Post: 07-04-2008, 08:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •