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

 
 

Share on Google+Share on Google+

apiz
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?
2 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners

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


                }
        });
    }
}`
Ads
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









Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads