I'm finishing this demo using get(whatever) in order to test a class
/** * 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 { public static void main(String [] args) { // declare variables private int numOfClasses; //number of classes of the student private double grades; //grades received in each class private average; //average= sum of all grades / number of classes private gpa; //average converted to scale 1-4 double total=0; //total of the grades String trash; //to convert string to double // Get the number of classes of the student numOfClasses = getNumOfClasses(); // Get the grades of the student grades = getGrades(); //Get total tota= getTotal(grades); // Get the average average = getAverage(numOfGrades, total); // Get the gpa gpa = getGpa(average); // Display the Data displayData(average, gpa); System.exit(0); } public static double getNumOfClasses() { String input; // To hold keyboard input input = JOptionPane.showInputDialog( "Number of classes: "); return Double.parseDouble(input); for (int i = 1; i <=numOfGrades; i++) { trash=JOptionPane.showInputDialog("Test " + i + " : " ); grades=Integer.parseInt(trash); total+=grades; public static double getGrades() { String input; // To hold keyboard input input = JOptionPane.showInputDialog( "Grades received: "); return Double.parseDouble(input); } public static double getTotal(double grades) { return =+grades; } public static double getAverage(double total, double numOfClasses) { return total / numOfClasses; } public static double getGpa(double average) { return (average*4)/100; } public static void displayData(double average, double gpa, double area) { JOptionPane.showMessageDialog(null, "Name :" + getName() + "\nGrade" + getSGrade() + "\nSchool: " + getSName + "\nAverage: " + average + "n\GPA: " + gpa + "."); } } }
This is my class to test:
/** * The StudentReport1 class has fields for name, grade, school, of a student * * @author Luis Fierro * @version 4/05/2014 */ public class StudentReport1 { // instance variables - replace the example below with your own private String name; private String sGrade; private String sName; /** * Constructor for objects of class StudentReport1 * @param n The student's name * @param sg The student's grade in school * @param sn The student's school name * */ public StudentReport1(String n, String sg, String sn) { // initialise instance variables name = n; sGrade = sg; sName = sn; } /** * setName method * * @param n The student's name */ public void setName(String n) { name = n; } /** * setSGrade method * * @param sg The student's grade in school */ public void setSGrade(String sg) { sGrade = sg; } /** * setSName method * * @param sn The student's school name */ public void setSName(String sn) { sName = sn; } /** * getName method * @return n Return the name of the student */ public String getName() { return name; } /** * getSGrade method * @return sg Return the student's grade in school * */ public String getSGrade() { return sGrade; } /** * getSName method * @return sn Return the student's school name */ public String getSName() { return sName; } public String toString() { return "Name: " + name + "\nGrade: " + sGrade + "\nSchool" + sName; } }