Results 1 to 19 of 19

Thread: [RESOLVED]Printing...simple <<just newb

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    10

    [RESOLVED]Printing...simple <<just newb

    This is just a small project that I am working on for class, and for my own benefit. Basically, what I want to do is...when I "printHighandLow()" I want it to print out the name as well as the grade the person has rather then just the high and low grade. Did I explain this well enough, anyone know a solution?
    VB Code:
    1. import java.util.ArrayList;
    2.  
    3. public class course
    4. {
    5.     // instance variables
    6.       ArrayList students;
    7.       ArrayList grades;
    8.       private InputReader reader;
    9.       double sum;
    10.       double totalgrades;
    11.       double avg;
    12.       double highgrade;
    13.       double lowgrade;
    14.      
    15.     /**
    16.      * Constructor for objects of class course
    17.      */
    18.     public course()
    19.     {
    20.         //
    21.         students = new ArrayList();
    22.         grades = new ArrayList();
    23.         reader = new InputReader();
    24.         highgrade = highgrade;
    25.         lowgrade = 999999;
    26.              
    27.     }
    28.  
    29.     /**
    30.      * An example of a method - replace this comment with your own
    31.      *
    32.      * @param  y   a sample parameter for a method
    33.      * @return     the sum of x and y
    34.      */
    35.     public void addStudnet()
    36.     {
    37.        info newstudent;
    38.        String name;
    39.        boolean finished = false;
    40.        String gradeSt;
    41.        double grade;
    42.      
    43.        welcome();
    44.        while(!finished)
    45.        {    
    46.        System.out.println(" Enter the name of the student");
    47.        name = reader.getInput();    
    48.        if(name.startsWith("bye"))
    49.        {
    50.             finished = true;
    51.             System.out.println("Good Bye");    
    52.        }
    53.        else
    54.        {
    55.        
    56.        System.out.println(" Enter a grade");
    57.        gradeSt = reader.getInput();
    58.        System.out.println("Done");
    59.              
    60.        grade = Double.parseDouble(gradeSt);
    61.        newstudent = new info(name , grade);
    62.        students.add(newstudent);
    63.        // totals up the grades(used in the Average method)
    64.        sum = sum + grade;  
    65.      
    66.           if (grade > highgrade)
    67.             {    
    68.               highgrade = grade;
    69.             }
    70.            
    71.              if (grade < lowgrade)
    72.             {    
    73.              lowgrade = grade;
    74.             }
    75.            
    76.            
    77.           /*if (gradeSt.compareTo(lowgrade) < 0)
    78.             {
    79.               lowgrade.equals(newstudent);
    80.             }*/
    81.            
    82.            
    83.           // totals up the number of grades.
    84.             totalgrades++;
    85.        }
    86.        }
    87.  
    88.     }
    89.    
    90.     public void welcome()
    91.     {
    92.        
    93.         System.out.println("Type bye to leave");
    94.     }
    95.    
    96.     public void printStudents()
    97.     {
    98.         int ndx;
    99.         for (ndx =0; ndx< students.size(); ndx++)
    100.         System.out.println(students.get(ndx));
    101.        
    102.     }
    103.    
    104.     public void printHighandLow()
    105.     {
    106.         System.out.println(highgrade);
    107.         System.out.println(lowgrade);
    108.     }
    109.    
    110.    
    111.     public void getAverage()
    112.     {
    113.      avg = sum/totalgrades;
    114.      System.out.println(" Average = "+ avg );
    115.     }
    116.        
    117.        
    118.    
    119. }
    Last edited by stinkoman; Mar 4th, 2006 at 12:25 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
  •  



Click Here to Expand Forum to Full Width