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?

Ads
 

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));


                }
        });
    }
}

Ads









Related Tutorials/Questions & Answers:
Student Marks
Student Marks
Advertisements
Example code of adding placeholder in UItextFeild
How to create a Student data base using Linked List in java
how to upload a student time table excelsheet
array of students with marks list
Small Bug How to solve in my code
MySQLselect into new table Example code
student marks sheet genaration in struts frame work
Java table & list
How to convert this Java code into GUI?
MySQL take backup of a table - example code needed
Adding a flex table in another flex table column
Adding checkbox in table using that delete table rows
how to solve
Adding A Primary Key to an Existing Table
html code for student information?
Adding a Reports tap in table pool
Write a JSP program to display the grade of a student by accepting the marks of five subjects.
How to delete file in Java code?
how to display data in List Or grid or in table in Jsp
how to insert value in dynamic table
Core java linked list example
Adding button to each row for the table and adding row to another table
How to add dynamic table in java
Version of com.dragome>dragome-guia dependency
solve this
Solve my code
adding the delete code
How to add dropdown list in a row of a sort table applet?
ModuleNotFoundError: No module named 'guio'

Ads