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 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!

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
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
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: 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
ModuleNotFoundError: No module named 'PLEASE'
ModuleNotFoundError: No module named 'PLEASE'  Hi, My Python... 'PLEASE' How to remove the ModuleNotFoundError: No module named 'PLEASE'... to install padas library. You can install PLEASE python with following command
ModuleNotFoundError: No module named 'PLEASE'
ModuleNotFoundError: No module named 'PLEASE'  Hi, My Python... 'PLEASE' How to remove the ModuleNotFoundError: No module named 'PLEASE'... to install padas library. You can install PLEASE python with following command
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 tell me
please tell me  why we are using http protocol in servlets
please provide the code
please provide the code   Develop a multi-client chat application
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 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
Please provide the code
Please provide the code   Write a program to recursively download the web pages available in the given site URL
please explain this program
please explain this program  public class MainClass { public static void main(String[] args) { System.out.println("Java
Confusion on Functions. Help Please?!
Confusion on Functions. Help Please?!  Write a program which has a number of functions for getting the area i.e. area of circle, area of square, area... not getting anywhere with it really :( Some help please
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
please tell me
please tell me  select * from emp order by 5 desc; in the above what is the meaning of 5, and what its functionality
please help me.
please help me.  How to move the edits.jsp in below link? http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
Please provide the code
Please provide the code   Program to find depth of the file in a directory and list all files those are having more number of parent directories
Please help me
Please help me  program for when a user enter his card number, it has to create default security pin in the database
PLEASE HELP WITH MY JAVA
PLEASE HELP WITH MY JAVA  Hey my name is Gavin and im a student... please help!!!!!!!! it is a for-loop question: Display the first 5 multiples... and average If u can please help...   
java programming please - Spring
java programming please  please i want your help :-( using... information Please Enter Your Name Please Enter your current balance Please Enter the amount you want to deposit Please Enter the amount you want to withdraw
help please!!! T_T
help please!!! T_T  what is wrong in this?: import java.io.*; class...("please enter your name:"); name1= input.readline(); System.out.println("please... { String name1; String name2; System.out.println("please enter
please help me.
please help me.  I have a jsp page under that i add a list box under i get the countries through my database. so how can i do
Please Send - Java Beginners
Please Send  Hi, this is perfect ur sending code I want java script coding Steps:-If user click on refresh button then page iage will be refresh Thanks  Hi friend, Thanks vineet
please tell me
please tell me  Actually i am working on a Project tiitle is JavaMail System, 1)How to configure java mail API and a Demo Program for Sending mail and Receiving using JSP and Servlet
please help me
please help me  interface Test1 { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new Test1() { public String toString() { return "test
Please provide the code
Please provide the code   Create a file system: We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only
please answer me
please answer me  iam using html in select tag.in this one option i selected and that option data will be display in table.And use servlet with html and how to retrieve the data from data base
Please Help Now
Please Help Now  i want to put this map in ajax oriented codeigniter website thanks in advance plz help me now plz very urgent
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please guide me - EJB
please guide me  Hi I am Pradeep singh ,done SCJP 5.0 and SCWCD 5.0 .Now i want to learn further .So please tell me whether should i learn EJB 3.0 or should learn Spring and Hibernate.I am confused what should i do next.Please

Ads