Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lala Bevard
Please HELPP
1 Answer(s)      3 years ago
Posted in : Java Beginners


The University wants to make a basic graphical display to show how many people received different grades for a piece of work on a module. You are required to write a program in Java that achieves this. The program is in a number of parts.

  1. The program should allow the tutor to enter in the various marks which the students have been awarded, until the tutor enters in a mark exceeding 100. At this point the program should display a histogram. Each star represents a student who achieved a module mark in the range shown. This is an example of the output. The example below shows the distribution of marks for 20 students. Your program should work with any number of student marks entered.

0-29 *

30-39 *

40-69 **

70-100 **

20 students in total.

‚?Ę As the tutor enters each mark, a counter should count the number of student‚??s marks which have been entered. ‚?Ę Use the same 4 category ranges shown here. ‚?Ę Make sure the display is neatly formatted as above. ‚?Ę Your program should make use of ‚??loops‚?? for the display of each category.

Extras: 2. After the histogram, a variety of statistics should be displayed (e.g. average mark awarded, number of students passing, highest mark, and lowest mark) 3. The histogram shows each category horizontally across the screen. Copy your original solution and make changes to the copy to display the histogram vertically (the stars in a category should go downwards and not across the screen). 4. An extra for the very brave!


Advertisement
View Answers

December 13, 2011 at 3:25 PM


Here is the answer for this question. I have done it for 20 students you can make it for any number of students by removing the condition i>=20 from the statement if((marks[i]>100)||(i>=20)). The java file is as follows

    import java.awt.Color;

    import java.awt.Container;

    import java.awt.FlowLayout;

    import java.awt.event.*;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.awt.*;

    import javax.swing.*;

    import javax.swing.BorderFactory;

    import javax.swing.JApplet;

    import javax.swing.JLabel;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JTextField;

    import javax.swing.border.Border;

    public class ClassStatistics1 extends JApplet implements ActionListener

    {

    float marks[]=new float[20];

    int i=0,ctr=0,ctr1=0,ctr2=0,ctr3=0,passed=0,num=0;

    float highest=0, lowest=101,sum=0,avg=0;

    JFrame f1=new JFrame();

    JLabel label1=new JLabel("Enter marks");

    JTextField tf1=new JTextField(10);

    private JButton b = new JButton("Add");

    public void init() 

    {

        Container cp = getContentPane();

    tf1.setEditable(true);

    b.setEnabled(true);

    cp.setLayout(new FlowLayout());

        // Create Borders for components:

        Border brd = BorderFactory.createMatteBorder(1, 1, 2, 2, Color.BLACK);

        tf1.setBorder(brd);

    cp.add(label1);

    cp.add(tf1);

    cp.add(b);

    b.addActionListener(this);


    }

    public void actionPerformed(ActionEvent e)

    {

    marks[i]=Float.parseFloat(tf1.getText());


    if(marks[i]>=0&&marks[i]<=29)

    ctr++;

    else if(marks[i]>=30&&marks[i]<=39)

    ctr1++;

    else if(marks[i]>=40&&marks[i]<=69)

    ctr2++;

    else if(marks[i]>=70&&marks[i]<=100)

    ctr3++;

    if((marks[i]>100)||(i>=20))

    {

    f1.getContentPane();

    f1.setSize(250, 375);

    JPanel p=new JPanel();

    p.setSize(250,375);

    p.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();

    int k=0,m=6;

    JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12;

    JLabel []lab=new JLabel[20];

    l1=new JLabel("0-29 ");

    c.fill=GridBagConstraints.HORIZONTAL;

    c.gridx=0;

    c.gridy=0;

    p.add(l1,c);

    while(ctr!=0)

    {

    m=m+3;

    lab[k]=new JLabel("");

    lab[k].setText("*");

    c.gridx=m;

    c.gridy=0;

    p.add(lab[k],c);

    k++;

    ctr--;

    }

    m=6;

    l2=new JLabel("30-39 ");

    c.gridx=0;

    c.gridy=5;

    p.add(l2,c);

    while(ctr1!=0)

    {

    m=m+3;

    lab[k]=new JLabel("*");

    c.gridx=m;

    c.gridy=5;

    p.add(lab[k],c);

    k++;

    ctr1--;

    }

    m=6;

    l3=new JLabel("40-69 ");

    c.gridx=0;

    c.gridy=10;

    p.add(l3,c);

    while(ctr2!=0)

    {

    m=m+3;

    lab[k]=new JLabel("*");

    c.gridx=m;

    c.gridy=10;

    p.add(lab[k],c);

    k++;

    ctr2--;

    }


    m=6;


    l4=new JLabel("70-100 ");

    c.gridx=0;

    c.gridy=15;

    p.add(l4,c);

    while(ctr3!=0)

    {

    m=m+3;

    lab[k]=new JLabel("*");

    c.gridx=m;

    c.gridy=15;

    p.add(lab[k],c);

    ctr3--;

    }


    avg=sum/num;

    l11=new JLabel("Average marks awarded: ");

    c.gridx=0;

    c.gridy=20;

    p.add(l11,c);

    l12=new JLabel("");

    l12.setText(Float.toString(avg));

    c.gridx=28;

    c.gridy=20;

    p.add(l12,c);


    l8=new JLabel("Passed: ");

    c.gridx=0;

    c.gridy=25;

    p.add(l8,c);

    l5=new JLabel("");

    l5.setText(Integer.toString(passed));

    c.gridx=28;

    c.gridy=25;

    p.add(l5,c);


    l9=new JLabel("Highest: ");

    c.gridx=0;

    c.gridy=30;

    p.add(l9,c);

    l6=new JLabel("");

    l6.setText(Float.toString(highest));

    c.gridx=28;

    c.gridy=30;

    p.add(l6,c);


    l10=new JLabel("Lowest: ");

    c.gridx=0;

    c.gridy=35;

    p.add(l10,c);


    l7=new JLabel("");

    l7.setText(Float.toString(lowest));

    c.gridx=28;

    c.gridy=35;

    p.add(l7,c);


    f1.add(p);

    f1.setVisible(true);

    }

    sum=sum+marks[i];

    if(marks[i]>=50)

    passed++;

    if(marks[i]>=highest)

    highest=marks[i];

    if(marks[i]<=lowest)

    lowest=marks[i];

    i++;

    tf1.setText("");

    num++;

    }
    }

    The html file is as follows

    <html>
    <applet code="ClassStatistics1.class" width="350" height="350">
    </applet> 
    </html>


Related Tutorials/Questions & Answers:
Please HELPP
Please HELPP  The University wants to make a basic graphical display to show how many people received different grades for a piece of work on a module. You are required to write a program in Java that achieves this. The program
java please please help
java please please help  Dear Friends plz help me to complete this program import java.util.*; public class StringDemo { static String a="{a=100;b=200;c=300}"; public static void main(String args
Advertisements
please help
please help  please send me the code of dynamic stack in java without using the built in functions
Define please!?!
Define please!?!  What is tree map sort
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
Please Help
Please Help  How do I create an attribute that represents the following: A grayscale ‚??color‚?? value, that is, an integer between 0 and 255 inclusive, where 0 corresponds to the darkest black and 255 to the brightest white
Please Help
Please Help  How do I create an attribute that represents the following: A grayscale 'color' value, that is, an integer between 0 and 255 inclusive, where 0 corresponds to the darkest black and 255 to the brightest white
Please help
Please help  Problem: Write a program that does addition, subtraction, multiplication and division operation on real numbers. The operation started with a user entered 2 numbers and click one of the operation buttons
Please help
Please help  Problem: Write a program that does addition, subtraction, multiplication and division operation on real numbers. The operation started with a user entered 2 numbers and click one of the operation buttons
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 ‚?? this is the ouput..;;; i
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 ‚?? this is the ouput..;;; i
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 ‚?? this is the ouput..;;; i
please help
please help  public class AllContact extends javax.swing.JFrame { /** Creates new form AllContact */ public AllContact() { initComponents(); try{ Connection1 con =new Connection1(); Connection conobj
help please?
help please?  Define a class named Circle with the following properties: ‚?Ę An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
help please?
help please?  Define a class named Circle with the following properties: List item ‚?Ę An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: ? An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
please help me.
please help me.  How to read a properties file in java with a suitable example. Please send me. Thanks Trinath   Please visit the following link: Java read properties file
please provide the code
please provide the code   Develop a multi-client chat application
please tell me
please tell me  why we are using http protocol in servlets
please help me.
please help me.  Please send me a code of template in opencms and its procedure.so i can implement the code. Thanks trinath
please tell me
please tell me  what are the topics in core and advaced java....   Hi Friend, Please visit the following links: http://www.roseindia.net/ http://www.roseindia.net/java/ Thanks   Hi Friend, Please visit
please help me.
please help me.  Please send me the validation of this below link. the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html Thanks Trinath
please tell me
please tell me  i have created one table,when i close and again login, table name will be there, but its content not displayed, showing as no rows selected, please tell me the reason
please explain this program
please explain this program  public class MainClass { public static void main(String[] args) { System.out.println("Java
Please provide the code
Please provide the code   Write a program to recursively download the web pages available in the given site URL
please tell me
please tell me  which cmd we use to clear the screen in sql prompt
please tell me
please tell me  why we use public static main(String ar){} in java instead of main
help me please
help me please   Hello I want helping for this question , Please Write a program that reads some friends√Ę‚?¨‚?Ę names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
Advertisements
 

 

 

DMCA.com