我怎么称呼吸气剂?

时间:2014-05-05 22:34:00

标签: java static-methods getter-setter

如何将此调用显示在我的代码末尾

 /**
 * getData method shows the data stored in  
 * the  StudentReport1 object
 * 
 * @param data The data to show 
 */

 public static void getData(StudentReport1 data, double average, double gpa)    

 {
  JOptionPane.showMessageDialog(null, "Name :" + data.getName() + "\nGrade" 
                                + data.getSGrade() + "\nSchool: "
                                + data.getSName()
                                + "\nAverage: " + average + 
                                "\nGPA: " + gpa + ".");

  }

我在从setData方法获取信息后最后显示它,但事情是我如何在以后调用它时不断说:错误不能应用于给定的类型; require:StudenteReport1,double,double;发现:没有争论;原因:实际和正式的参数列表长度不同

这是我的全部代码

import javax.swing.*;
/**
* The  ReportGenerator class uses the StudentReport1 class to simulate the report 
* of a student. Holds fields for number of classes,grades received, average, and gpa.
* 
* @author Luis Fierro
* @version 4/16/2014
*/
public class ReportGenerator
{

/**
 * getData method creates a StudentReport1 object
 * pobulated with data from the user
 * 
 * @return A reference to StudentReport1
 */
 public static StudentReport1 setData()
{
    //variables to hold  the information
     String name;
     String sGrade;
     String sName;

    //read the information
    name=JOptionPane.showInputDialog("Enter your name: ");
    sGrade=JOptionPane.showInputDialog("Enter your grade in school: ");
    sName=JOptionPane.showInputDialog("Enter the name of your school: ");

    //create a StudentReport entry
    StudentReport1 data = new StudentReport1(name, sGrade, sName);

    //return a reference to the object
    return data;

   }



   public static double getAverage(double total, int numOfClasses)
   {
   return total / numOfClasses;

   }

   public static double getGpa(double average)
   {
   return (average*4)/100;

   }


   /**
    * getData method shows the data stored in  
   * the  StudentReport1 object
   * 
   * @param data The data to show 
   */

   public static void getData(StudentReport1 data, double average, double gpa)    

   {
   JOptionPane.showMessageDialog(null, "Name :" + data.getName() + "\nGrade" 
                                + data.getSGrade() + "\nSchool: "
                                + data.getSName()
                                + "\nAverage: " + average + 
                                "\nGPA: " + gpa + ".");

    }

    public static void main(String [] args)
   {

   // declare variables
   int numOfGrades=0;       //number of classes of the student
   int grades;               //grades received in each class
   double average;                //average= sum of all grades / number of classes
   double gpa;                    //average converted to scale 1-4
   int total=0;                    //total of the grades 
   String trash;                   //to convert s  tring to double

     setData();



    //ask number of grades
    trash=JOptionPane.showInputDialog("Number of grades:");             
    numOfGrades=Integer.parseInt(trash);                                                                                                     

   //get the grades added together in order to calculate the average
    for (int i = 1; i <=numOfGrades; i++) 
            {

        trash=JOptionPane.showInputDialog("Test " + i + " : " );
        grades=Integer.parseInt(trash);


            total+=grades;  

            }

    // Get the average
  average = getAverage(total, numOfGrades);

  // Get the gpa
  gpa = getGpa(average);

 //display all of the information
  getData(StudentReport1, average, gpa);

  JOptionPane.showMessageDialog(null, "The students average is: " + average + "\nThe 
  student's GPA is: " + gpa);

  }
  }

1 个答案:

答案 0 :(得分:2)

main方法中,当您调用getData(StudentReport1, average, gpa);时,您发送的第一个参数是该类的名称,这根本没有任何意义。相反,您需要发送StudentReport1类的实例,您可以通过调用setData()来检索该实例。

main内的代码更新为:

StudentReport1 studentReport = setData();
//rest of the current code...
getData(studentReport , average, gpa);