import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Student_use
{
	public static void main (String[] args)
	{
		String name="";
		int id=0;
		double grade=0;
		int credit=0;
		int numClasses=0;


		Student s = new Student (name, id); 	//*************** create the Student object


        	//--------------------------------import data

		name = JOptionPane.showInputDialog (
			null, "Enter name");

		id = Integer.parseInt(JOptionPane.showInputDialog(
			null, "Enter student ID"));


		//---------------------------------input numClasses

		numClasses = Integer.parseInt(JOptionPane.showInputDialog(
			null, "Number of classes"));

		while (numClasses < 1)
		{
			JOptionPane.showMessageDialog(
				null, "You must enter at least one class",
				"Invalid entry", JOptionPane.ERROR_MESSAGE);

			numClasses = Integer.parseInt(JOptionPane.showInputDialog(
				null, "Number of classes: "));
		}


		//---------------------------------input grade and credit

		for (int i=1; i<=numClasses; i++)
		{
			grade = Double.parseDouble(JOptionPane.showInputDialog(
				null, "Grade for class " + i));

			while (grade<0 || grade >4)
			{
				JOptionPane.showMessageDialog(
					null, "Grade must be between 0.0 and 4.0",
					"Invalid entry", JOptionPane.ERROR_MESSAGE);

				grade = Double.parseDouble(JOptionPane.showInputDialog(
					null, "Grade for class " + i));
			}

			//---------------------------------

			credit = (int)Double.parseDouble(JOptionPane.showInputDialog(
				null, "Credits for class " + i));

			while (credit<1)
			{
				JOptionPane.showMessageDialog(
					null, "You must enter at least one credit",
					"Invalid entry", JOptionPane.ERROR_MESSAGE);

				credit = (int)Double.parseDouble(JOptionPane.showInputDialog(
					null, "Credits for class " + i));
			}
			s.assignGrade(credit, grade);
		}


		//---------------------------------display

		DecimalFormat rounding = new DecimalFormat ("0.##");

		JOptionPane.showMessageDialog(
			null, "Name: " + s.getName() +
			"\nGPA: " + rounding.format(s.getGPA()) +
			"\nLetter grade: " + s.getGrade() +
			"\nPass/Fail status: " + s.getStatus(),
			"Report for Student " +s.getStud_id(),
			JOptionPane.PLAIN_MESSAGE);

		System.exit(0);
	}
}
