質問

How can I call this to be displayed almost at the end of my code

 /**
 * 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 + ".");

  }

I am displaying it at the end after getting the information from the setData method but the thing is how do I call it later it keeps saying: error cannot be applied to given types; require:StudenteReport1, double, double; found:no arguments; reason: actual and formal argument lists differ in length

This is my whole code

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);

  }
  }
役に立ちましたか?

解決

In main method, when you're calling getData(StudentReport1, average, gpa);, the first argument you're sending is the name of the class, which doesn't make any sense at all. Instead, you need to send an instance of StudentReport1 class, which you can retrieve from the call to setData().

Update the code inside main to:

StudentReport1 studentReport = setData();
//rest of the current code...
getData(studentReport , average, gpa);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top