How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?

How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?

import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MarkStudent { double totalMarks; String grade;

public void setTotalMarks(double totalMarks) {
    this.totalMarks = totalMarks;
    }

public double getTotalMarks() {
    return totalMarks;
}

public void setGrade(String grade) {
    this.grade = grade;
    }

public String getGrade() {
    return grade;
}

public static void main(String[] args) {
    JLabel lab=new JLabel("Enter number of students in class: ");
    final JTextField text=new JTextField(20);

    JButton b=new JButton("Find");
    lab.setBounds(10,10,150,20);
    text.setBounds(180,10,100,20);
    b.setBounds(180,40,100,20);

    JFrame f=new JFrame();
    f.setLayout(null);
    f.add(lab);
    f.add(text);
    f.add(b);
    f.setSize(300,100);
    f.setVisible(true);
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){

    int num = Integer.parseInt(text.getText());
    MarkStudent data[] = new MarkStudent[num];
    for(int a = 0; a < data.length; a++) {
       String input=JOptionPane.showInputDialog(null,"Please insert student marks: ");

        double marks = Double.parseDouble(input);
        data[a] = new MarkStudent();
        data[a].setTotalMarks(marks);

        if (marks < 40){
            data[a].setGrade("E");
        }

        if (marks >= 40 && marks <= 44) {
            data[a].setGrade("D");
        }

        if (marks >= 45 && marks <= 49) {
            data[a].setGrade("D+");
        }

        if (marks >= 50 && marks <= 54) {
            data[a].setGrade("C-");
        }

        if (marks >= 55 && marks <= 59) {
            data[a].setGrade("C");
        }

        if (marks >= 60 && marks <= 64) {
            data[a].setGrade("C+");
        }

        if (marks >= 65 && marks <= 69) {
            data[a].setGrade("B-");
        }

        if (marks >= 70 && marks <= 74) {
            data[a].setGrade("B");
        }

        if (marks >= 75 && marks <= 79) {
            data[a].setGrade("B+");
        }

        if (marks >= 80 && marks <= 84) {
            data[a].setGrade("A");
        }

        if (marks >= 85 && marks <= 100) {
            data[a].setGrade("A+");
        }
        if (marks < -100 && marks >= 100) {
           data[a].setGrade("Not in the list of the table");
    }
    }

int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int count5 = 0; int count6 = 0; int count7 = 0; int count8 = 0; int count9 = 0; int count10 = 0; int count11 = 0; int count12 = 0;

        for (int i = 0; i < num; i++) {
            MarkStudent show = data[i];
            String g = show.getGrade();
            if (g.equals("A+")) {
                count1++;
            }
            if (g.equals("A")) {
                count2++;
            }
            if (g.equals("B+")) {
                count3++;
            }
            if (g.equals("B")) {
                count4++;
            }
            if (g.equals("B-")){
                count5++;
            }
            if (g.equals("C+")){
                count6++;
            }
            if (g.equals("C")){
                count7++;
            }
            if (g.equals("C-")){
                count8++;
            }
            if (g.equals("D+")){
                count9++;
            }
            if (g.equals("D")){
                count10++;
            }
            if (g.equals("E")){
                count11++;
            }
            if (g.equals("Not in the list of the table")){
                count12++;
            }

        }
        JOptionPane.showMessageDialog(null,"Number of student getting A+ and A grade: "
                + (count1 + count2));
        JOptionPane.showMessageDialog(null,"Number of student getting B+ and B grade: "
                + (count3 + count4));
        JOptionPane.showMessageDialog(null,"Number of student getting A and B+ grade: "
                + (count2 + count3));
        JOptionPane.showMessageDialog(null,"Number of student getting B and B- grade: "
                + (count4 + count5));
        JOptionPane.showMessageDialog(null,"Number of student getting B- and C+ grade: "
                + (count5 + count6));
        JOptionPane.showMessageDialog(null,"Number of student getting C+ and C grade: "
                + (count6 + count7));
        JOptionPane.showMessageDialog(null,"Number of student getting C and C- grade: "
                + (count7 + count8));
        JOptionPane.showMessageDialog(null,"Number of student getting C- and D grade: "
                + (count8 + count9));
        JOptionPane.showMessageDialog(null,"Number of student getting D and D- grade: "
                + (count9 + count10));
        JOptionPane.showMessageDialog(null,"Number of student getting D- and E grade: "
                + (count10 + count11));
        JOptionPane.showMessageDialog(null, "The result cannot be display because the marks is not in the list of the table."
                + (count12));


                }
        });
    }
}`
View Answers

November 11, 2011 at 4:19 PM

import java.awt.*; 
import javax.swing.*;
import java.awt.event.*;
public class MarkStudent{ 
    double totalMarks;
    String grade;

public void setTotalMarks(double totalMarks) {
    this.totalMarks = totalMarks;
    }

public double getTotalMarks() {
    return totalMarks;
 }

public void setGrade(String grade) {
    this.grade = grade;
    }

public String getGrade(){
    return grade;
}

public static void main(String[] args) {
    JLabel lab=new JLabel("Enter number of students in class: ");
    final JTextField text=new JTextField(20);

    JButton b=new JButton("Find");
    lab.setBounds(10,10,150,20);
    text.setBounds(180,10,100,20);
    b.setBounds(180,40,100,20);

    JFrame f=new JFrame();
    f.setLayout(null);
    f.add(lab);
    f.add(text);
    f.add(b);
    f.setSize(300,100);
    f.setVisible(true);
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){

    int num = Integer.parseInt(text.getText());
    MarkStudent data[] = new MarkStudent[num];
    for(int a = 0; a < data.length; a++) {
       String input=JOptionPane.showInputDialog(null,"Please insert student marks: ");

        double marks = Double.parseDouble(input);
        while(marks>100||marks<0){
        String  st=JOptionPane.showInputDialog(null,"Invalid marks! Marks should be in between 0 to 100!");
            marks=Double.parseDouble(st);
        }
        data[a] = new MarkStudent();
        data[a].setTotalMarks(marks);

        if(marks < 40){
            data[a].setGrade("E");
        }
        if(marks >= 40 && marks <= 44) {
            data[a].setGrade("D");
        }
        if (marks >= 45 && marks <= 49) {
            data[a].setGrade("D+");
        }
        if (marks >= 50 && marks <= 54) {
            data[a].setGrade("C-");
        }
        if (marks >= 55 && marks <= 59) {
            data[a].setGrade("C");
        }
        if (marks >= 60 && marks <= 64) {
            data[a].setGrade("C+");
        }
        if (marks >= 65 && marks <= 69) {
            data[a].setGrade("B-");
        }
        if (marks >= 70 && marks <= 74) {
            data[a].setGrade("B");
        }
        if (marks >= 75 && marks <= 79) {
            data[a].setGrade("B+");
        }
        if (marks >= 80 && marks <= 84) {
            data[a].setGrade("A");
        }
        if (marks >= 85 && marks <= 100) {
            data[a].setGrade("A+");
        }
        if (marks < -100 && marks >= 100) {
           data[a].setGrade("Not in the list of the table");
       }
    }

November 11, 2011 at 4:19 PM

continue.....

int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int count5 = 0; int count6 = 0; int count7 = 0; int count8 = 0; int count9 = 0; int count10 = 0; int count11 = 0; int count12 = 0;

        for (int i = 0; i < num; i++) {
            MarkStudent show = data[i];
            String g = show.getGrade();
            if (g.equals("A+")) {
                count1++;
            }
            if (g.equals("A")) {
                count2++;
            }
            if (g.equals("B+")) {
                count3++;
            }
            if (g.equals("B")) {
                count4++;
            }
            if (g.equals("B-")){
                count5++;
            }
            if (g.equals("C+")){
                count6++;
            }
            if (g.equals("C")){
                count7++;
            }
            if (g.equals("C-")){
                count8++;
            }
            if (g.equals("D+")){
                count9++;
            }
            if (g.equals("D")){
                count10++;
            }
            if (g.equals("E")){
                count11++;
            }
            if (g.equals("Not in the list of the table")){
                count12++;
            }

        }
        JOptionPane.showMessageDialog(null,"Number of student getting A+ and A grade: "
                + (count1 + count2));
        JOptionPane.showMessageDialog(null,"Number of student getting B+ and B grade: "
                + (count3 + count4));
        JOptionPane.showMessageDialog(null,"Number of student getting A and B+ grade: "
                + (count2 + count3));
        JOptionPane.showMessageDialog(null,"Number of student getting B and B- grade: "
                + (count4 + count5));
        JOptionPane.showMessageDialog(null,"Number of student getting B- and C+ grade: "
                + (count5 + count6));
        JOptionPane.showMessageDialog(null,"Number of student getting C+ and C grade: "
                + (count6 + count7));
        JOptionPane.showMessageDialog(null,"Number of student getting C and C- grade: "
                + (count7 + count8));
        JOptionPane.showMessageDialog(null,"Number of student getting C- and D grade: "
                + (count8 + count9));
        JOptionPane.showMessageDialog(null,"Number of student getting D and D- grade: "
                + (count9 + count10));
        JOptionPane.showMessageDialog(null,"Number of student getting D- and E grade: "
                + (count10 + count11));
        JOptionPane.showMessageDialog(null, "The result cannot be display because the marks is not in the list of the table."
                + (count12));


                }
        });
    }
}









Related Tutorials/Questions & Answers:
Student Marks
Student Marks
Advertisements
Example code of adding placeholder in UItextFeild
array of students with marks list
how to upload a student time table excelsheet
How to create a Student data base using Linked List in java
student marks sheet genaration in struts frame work
MySQLselect into new table Example code
Small Bug How to solve in my code
Version of com.dragome>dragome-guia dependency
MySQL take backup of a table - example code needed
marks - Java Beginners
ModuleNotFoundError: No module named 'guio'
Write a JSP program to display the grade of a student by accepting the marks of five subjects.
Java table & list
using list iterator create student details - JavaMail
Version of com.dragome>dragome-guia-web dependency
html code for student information?
How to Solve the Syntax Error in java??
ModuleNotFoundError: No module named 'guiu-english'
Adding a flex table in another flex table column
Adding checkbox in table using that delete table rows
Adding A Primary Key to an Existing Table
Example Code - Java Beginners
how to solve
Adding a Reports tap in table pool
ModuleNotFoundError: No module named 'FarPy-GUIE'
ModuleNotFoundError: No module named 'FarPy-GUIE'
ModuleNotFoundError: No module named 'upt-guix'
Adding a New Column Name in Database Table
how to return to main menu after adding all the info. - Java Beginners
How to convert this Java code into GUI?
How to solve button problem - Java Beginners
student registration example
Adding button to each row for the table and adding row to another table
how to display data in List Or grid or in table in Jsp
ModuleNotFoundError: No module named 'guid'
Solve my code
solve this
adding the delete code
Adding checkbox to List as item
how to insert value in dynamic table
ModuleNotFoundError: No module named 'guix-import-debian'
Delete row and column from table through java code
how to send email list of email address through in database table list
how to solve the nullPointer Exception in main - Java Beginners
How to Extract row from table view using JSP Code - Java Beginners
How to add dropdown list in a row of a sort table applet?
Core java linked list example
ajax code please help to solve this........

Ads