Hi guys, im new to the forums and was wondering if anyone could help me. Ive been working on this project for a few hours now and im starting to pull my hair out. Basically its the program that uses methods to calculate GPA. I dont know how to pass values from my main method into my other methods. any help would be appreciated!
import javax.swing.JOptionPane; public class proj2a{ public static void main(String[] args){ int totalQualityPoints = 0, totalCredits = 0; int credits, gradeNumber; String Name, semester, course, Exit, grade; double GPA; PrintExplanation(); Name(); semesterName(); do{ String courseName = courseName(); String courseGrade = courseGrade(); GetValidNumberInput("How many credit Hours is the class Worth?" ,1,4); ConvertGradeToPoints(grade); CalculateGPA(); JOptionPane.showInputDialog("Do you want to exit? 'yes/no'"); }while (!Exit.equals("yes")); GenerateGPAReport(); } public static void PrintExplanation(){ JOptionPane.showMessageDialog(null,"This Program will help you calculate your GPA"+"\n"+"In order for this program to work correctly, you need to follow exactly what the pop up dialogs say."); } public static String Name(){ String Name; Name = JOptionPane.showInputDialog("So, What is your name?"); return Name; } public static String semesterName(){ String semester; semester = JOptionPane.showInputDialog("What semester are you currently in?"); return semester; } public static String courseName(){ String course; course = JOptionPane.showInputDialog("What class are you currently in?"); return course; } public static String courseGrade(){ String grade; grade = JOptionPane.showInputDialog(",What grade did you get int this class?"); return grade; } public static int GetValidNumberInput(String promptstr, int lowerNum, int upperNum){ int credits; do{ credits = Integer.parseInt(JOptionPane.showInputDialog(promptstr)); }while(credits < lowerNum || credits > upperNum); return credits; } public static int ConvertGradeToPoints(String grade){ int gradenumber; if (grade.equalsIgnoreCase("A")){ gradeNumber = 4 ; } else if (grade.equalsIgnoreCase("B")){ gradeNumber = 3; } else if (grade.equalsIgnoreCase("C")) { gradeNumber = 2; } else if (grade.equalsIgnoreCase("D")){ gradeNumber = 1; } else{ gradeNumber = 0; } return gradeNumber; } public static double CalculateGPA (int totalCredits, int totalQualityPoints){ totalQualityPoints = credits * gradeNumber; GPA = totalQualityPoints / totalCredits; return GPA; } public static void GenerateGPAReport(int totalcredits, int totalQualityPoints, String Name, String semester){ System.out.println("Name:"+Name); System.out.println("Semester:"+semester); System.out.println("\n"); } }