Prompt Allow the User to input a Student Name Student Year a

Prompt.

Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.

On input, the User provides the Student Year as:
1 = Freshman, 2 = Sophomore, 3 = Junior, 4 = Senior.

The program should validate the Student Year, and allow re-entry.

The program will query the User to enter one test score after another.

Each test score should be validated to ensure it is valid (e.g., 0 - 100) and allow re-entry.

The program should prompt the User as to whether or not there is another score to enter.

For each student and series of scores, the program should display:
The Student Name
The Student Year in text (\"Freshman\", \"Sophomore\", etc.)
The Series of Grades Entered
The Average with one decimal point of precision
The Letter Grade for the above based on the following:
A = 90 - 100
B = 80 - 89
C = 70 - 79
D = 60 - 69
F = 0 - 59

A Java switch structure should be used to test the Student Year and map it to the appropriate String.

The User should also be able to indicate when all Students are completed and the program should exit accordingly.

I\'m not very familiar with GUI\'s yet.

Solution

Hello Please check below Classes

I didn\'t handle error cases and validation but everything is workinh fine

Student.Java

--------------------------

import java.util.ArrayList;
import java.util.List;

public class Student {
    String name;
    int year;
    List<Integer> grades = new ArrayList<Integer>();
  
    public String getYearString(){
       switch(this.year){
       //1 = Freshman, 2 = Sophomore, 3 = Junior, 4 = Senior.
       case 1 :
           return \"Freshman\";
       case 2 :
           return \"Sophomore\";
       case 3 :
           return \"Junior\";
       case 4 :
           return \"Senior\";
       default:
           return \"none\";
              
       }
    }
  
    public String gradeToString(int grade){
       if(grade < 60){
           return\"F\";
       }
       else if (grade > 59 && grade < 70){
           return \"D\";
       }
       else if (grade > 69 && grade < 80){
           return \"C\";
       }
       else if (grade > 79 && grade < 90){
           return \"B\";
       }
       else{
           return \"A\";
       }
    }
    public double averageGrade(){
       double avg = 0;
       for(int i = 0 ; i < grades.size() ; i++){
           avg += grades.get(i);
       }
       if(avg > 0)
            avg = avg/grades.size();
       return avg;
      
    }
  
    public void printStudent(){
       System.out.println(\"====== Printing Student ===========\");
       System.out.println(\"Student Name :\"+this.name);
       System.out.println(\"Student Year :\"+this.getYearString());
       System.out.println(\"Student Average :\"+this.averageGrade());
       System.out.println(\"====== Grades ===========\");
       for(int i = 0 ; i < grades.size() ; i++){
           System.out.println(gradeToString(grades.get(i)))   ;
       }
       System.out.println(\"====== End ========================\");
    }

}

StudentsEntryScreen.java :-

-----------------------------------------------------

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;
public class StudentsEntryScreen extends JFrame implements ActionListener{
   List<Student> students;
   Student curEntryStudent;
   JButton SUBMIT,ENTER;
   JLabel label1,label2;
      final JTextField text1,text2;
   JPanel panel;
  
   @Override
   public void actionPerformed(ActionEvent e) {
       // TODO Auto-generated method stub
       if(e.getSource() == SUBMIT){
         
           curEntryStudent.name = text1.getText();
           curEntryStudent.year = Integer.parseInt(text2.toString());
           students.add(curEntryStudent);
           curEntryStudent = null;
           StudentsEntryScreen.this.setVisible(false);
       }
       else{
           askForGrade();  
          
       }
   }
   public StudentsEntryScreen(List<Student> students){
       setSize(300, 300);
       curEntryStudent = new Student();
       this.students = students;
       SUBMIT=new JButton(\"SUBMIT\");
       ENTER=new JButton(\"Enter New Student Grade\");
           label1 = new JLabel();
           label1.setText(\"Student name:\");
           text1 = new JTextField(15);
      
           label2 = new JLabel();
           label2.setText(\"Year:\");
           text2 = new JTextField(10);
       panel=new JPanel(new GridLayout(3,2));
           panel.add(label1);
           panel.add(text1);
           panel.add(label2);
           panel.add(text2);
       panel.add(SUBMIT);
       panel.add(ENTER);
       SUBMIT.addActionListener(this);
       ENTER.addActionListener(this);
       add(panel,BorderLayout.CENTER);
      
   }
  
   public void askForGrade(){
       JFrame frame = new JFrame(\"InputDialog Example #2\");
        String code = JOptionPane.showInputDialog(
            frame,
            \"Enter Grade of Student\",
            \"Enter Grade\",
            JOptionPane.WARNING_MESSAGE
        );
        curEntryStudent.grades.add(Integer.parseInt(code));
        int response = JOptionPane.showConfirmDialog(null, \"Do you want to enter new Grade?\", \"Confirm\",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.NO_OPTION) {
            System.out.println(\"No button clicked\");
            curEntryStudent.name = text1.getText();
          
           curEntryStudent.year = Integer.parseInt(text2.getText());
            students.add(curEntryStudent);
           curEntryStudent = null;
           StudentsEntryScreen.this.setVisible(false);
          } else if (response == JOptionPane.YES_OPTION) {
              askForGrade();
          } else if (response == JOptionPane.CLOSED_OPTION) {
            System.out.println(\"JOptionPane closed\");
          }
      
   }

}

StudentDemo :-

--------------------------------

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class StudentDemo {
   List<Student> students = new ArrayList<Student>();
   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       final StudentDemo demo = new StudentDemo();
       JFrame frame = new JFrame(\"Students Entry\");
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());
       JButton submit = new JButton(\"Submit\");
       submit.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
               // TODO Auto-generated method stub
               for(int i = 0 ; i < demo.students.size() ; i++){
                   demo.students.get(i).printStudent();
                  }
           }
       });
       JButton add = new JButton(\"Add Student\");
         add.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
               StudentsEntryScreen frame=new StudentsEntryScreen(demo.students);
                   frame.setSize(300,100);
                   frame.setVisible(true);
           }
       });

         panel.add(add);
         panel.add(submit);
         frame.add(panel);
         frame.setSize(300, 300);
        frame.setVisible(true);
      
      
      
   }

  

}

Prompt. Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.
Prompt. Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.
Prompt. Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.
Prompt. Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.
Prompt. Allow the User to input a Student Name, Student Year, and a varying number of grades for each student. Use Java input dialog windows to query the User.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site