Results 1 to 2 of 2
  1. #1
    aznlnja is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Urgent help! npassing and highest grade

    Hi guys, im new to java, and i need help, I thank you ahead for your kind help
    Can you guys explain and show me how to do it. I need help asap, Thanks!

    The program would read a file and examine it , and compute number of students, # of passing students, and highest grade.

    I still need to write:

    -a method nPassing which computes how many Students in a Section have a passing grade. “Passing” means 60 or above.

    -a method highestGrade which computes the highest grade in a Section. If the Section is empty — used == 0 — then execute the statement
    throw new Error
    ("Attempt to find the maximum of an empty Section");

    Code so far:

    import java.io.*;
    import java.util.Scanner;
    /////////////////////////////////////////////////////////////////////////
    class Hw07
    {
    //-----------------------------------------------------------------------
    public static void main (String [] args) throws Exception
    {
    Scanner kb = new Scanner(System.in);

    System.out.print("\nEnter name of a file of Students: ");
    String filename = kb.nextLine();

    Section sec = new Section(filename);

    System.out.println("\nIn forward order:");
    sec.print(System.out);

    System.out.println("\nThat Section contains " +
    sec.howMany() +
    " Student(s).");

    System.out.println("\nThat Section contains " +
    sec.nPassing() +
    " passing Student(s).");

    System.out.println("\nThe highest grade is " +
    sec.highestGrade() + ".");
    }
    //-----------------------------------------------------------------------
    } // end class Hw07
    /////////////////////////////////////////////////////////////////////////
    class Section
    {
    private Student [] a;
    private int used;
    private static final int INIT_SIZE = 20;
    //-----------------------------------------------------------------------
    public Section ( String filename ) throws Exception
    {
    Scanner sc = new Scanner(new File(filename));

    a = new Student[INIT_SIZE];
    used = 0;

    while ( sc.hasNext() )
    {
    Student s = Student.read(null,sc);

    if ( used == a.length )
    {
    Student[] newA = new Student[2*a.length+1];
    for ( int i = 0 ; i < used ; i++ ) newA[i] = a[i];
    newA[used] = s;
    used++;
    a = newA;
    }
    else
    {
    a[used] = s;
    used++;
    }
    }
    }
    //-----------------------------------------------------------------------
    public void print ( PrintStream ps )
    {
    for ( int i = 0 ; i < used ; i++ )
    {
    ps.println(a[i]);
    }
    }
    //-----------------------------------------------------------------------
    public int howMany() { return used; }
    //-----------------------------------------------------------------------
    public double average ()
    {
    int sum = 0;

    for ( int i = 0 ; i < used ; i++ )
    {
    Student s = a[i];
    sum += s.getGrade();
    }

    return 1.0 * sum / used;
    }
    //-----------------------------------------------------------------------
    } // end class Section
    /////////////////////////////////////////////////////////////////////////
    class Student
    {
    private String name;
    private int grade;
    //-----------------------------------------------------------------------
    public Student ( String name, int grade )
    {
    this.name = name;
    this.grade = grade;
    }
    //-----------------------------------------------------------------------
    public String toString ()
    {
    return name + " (" + grade + ")";
    }
    //-----------------------------------------------------------------------
    public String getName() { return name; }
    //-----------------------------------------------------------------------
    public int getGrade() { return grade; }
    //-----------------------------------------------------------------------
    public void setGrade( int newGrade ) { grade = newGrade; }
    //-----------------------------------------------------------------------
    public static Student read ( PrintStream ps, Scanner sc )
    {
    if ( ps != null ) ps.println("Reading a Student record ...");
    if ( ps != null ) ps.print("Enter the name: ");
    String name = sc.nextLine();
    if ( ps != null ) ps.print("Enter the grade: ");
    int grade = sc.nextInt(); sc.nextLine();
    return new Student(name,grade);
    }
    //-----------------------------------------------------------------------
    } // end class Student
    /////////////////////////////////////////////////////////////////////////
    Last edited by aznlnja; 10-13-2011 at 10:52 AM.

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Urgent help! npassing and highest grade

    People can't do your homework for you. You just have to write down what you want to do and then code what you wrote down.

Similar Threads

  1. Help with calculation for final grade of student
    By Braxtonmj in forum New To Java
    Replies: 7
    Last Post: 05-11-2010, 12:49 AM
  2. Array highest grade
    By Cdlove in forum New To Java
    Replies: 5
    Last Post: 05-05-2010, 10:25 PM
  3. Grade my questions, lol
    By syntrax in forum New To Java
    Replies: 4
    Last Post: 12-16-2009, 07:03 AM
  4. Help with JAVA (Grade Book)
    By Sara_21 in forum New To Java
    Replies: 3
    Last Post: 11-30-2009, 03:45 PM
  5. beginner grade 11-need help with RaceCar Game
    By bobmasta5 in forum New To Java
    Replies: 0
    Last Post: 01-09-2009, 10:04 PM

Posting Permissions

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