5-7 Method_F

Post date: Apr 4, 2014 4:01:02 PM

package method_f;

import java.util.Scanner;

import javax.swing.JOptionPane;

import java.io.*;

public class Method_F 

{

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

        {

           Scanner scan=new Scanner(System.in);

           System.out.print("Enter your file path : ");

           OutputFile(scan.next());

        }

        public static void OutputFile(String s)throws IOException

        {

            PrintWriter p=new PrintWriter(s);

            p.println("Names\t\tAverage");

            p.println("-------\t\t--------");

            Scanner scan=new Scanner(System.in);

            int pass=0,fail=0;

           System.out.print("How many students who wish to add their names and averages in the file : ");

            for (int i =scan.nextInt(); i>=1; i--)

            {

                String name=get_name();

                double average=get_average();

                if(average>=50)

                    pass++;

                else

                    fail++;

                p.println(name+"\t\t"+average);

 

            }

            p.println("number of student passed = "+pass);

            p.println("number of student failed = "+fail);

            p.close();

        }

        public static String get_name()

        {

            return JOptionPane.showInputDialog("Enter name of student :");

        }

        public static double get_average()

        {

            return Double.parseDouble(JOptionPane.showInputDialog("Enter average of student :"));

        }

    

}