Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:26:01+00:00 2026-06-04T21:26:01+00:00

I have to make a marks program that displays a set of marks that

  • 0

I have to make a marks program that displays a set of marks that a user enters and some calculations (average, maximum, minimum, range, etc.). It should also be able to sort the marks in ascending order. I managed (with help) to display the marks and sort them but I cannot get the program to do the calculations and display them. This is all the code I have so far:

 ArrayList <Integer> marks = new ArrayList();

 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
    Collections.addAll(marks, (Integer.parseInt(markInput.getText())));

    StringBuilder text = new StringBuilder();
    for (Integer mark: marks) {
    text.append(mark.toString()).append('\n');
    }

    markdisplayTextArea.setText(text.toString());
    }

 private void sortButtonActionPerformed(java.awt.event.ActionEvent evt) {
    Collections.sort(marks);

    StringBuilder text = new StringBuilder();
    for (Integer mark: marks) {
    text.append(mark.toString()).append('\n');
    }

    markdisplayTextArea.setText(text.toString());
    }

 private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {

    analyzeTextArea.setText("Class average:" +);
    analyzeTextArea.setText("Maximum mark:" +);
    analyzeTextArea.setText("Minimum mark:" +);
    analyzeTextArea.setText("Range of marks:" +);
    }

The calculations must be displayed in a TextArea when the "analyze" button is pressed. I currently have no idea of how to go about doing the calculations or displaying them. Any guidance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:26:02+00:00Added an answer on June 4, 2026 at 9:26 pm

    Here is my suggested code for your problem…

    ArrayList<Integer> marks = new ArrayList<Integer>();
    
    // Called when the user clicks a button
    public void actionPerformed(ActionEvent e) {
        Object clickedButton = e.getSource();
        if(clickedButton == addButton) {
            addButtonActionPerformed();
        }
        else if(clickedButton == sortButton) {
            sortButtonActionPerformed();
        }
        else if(clickedButton == analyzeButton) {
            analyzeButtonActionPerformed();
        }
    }
    
     private void addButtonActionPerformed() {
        Collections.addAll(marks, (Integer.parseInt(markInput.getText())));
    
        StringBuilder text = new StringBuilder();
        for (Integer mark: marks) {
            text.append(mark.toString()).append('\n');
        }
    
        markdisplayTextArea.setText(text.toString());
    }
    
     private void sortButtonActionPerformed() {
        Collections.sort(marks);
    
        StringBuilder text = new StringBuilder();
        for (Integer mark: marks) {
            text.append(mark.toString()).append('\n');
        }
    
        markdisplayTextArea.setText(text.toString());
    }
    
    private void analyzeButtonActionPerformed() {
    
        String output = "Class average:" + calculateAverage() + "\n" +
                        "Maximum mark:" + calculateMaximum() + "\n" +
                        "Minimum mark:" + calcualteMinimum() + "\n" +
                        "Range of marks:" + calculateRange();
    
        analyzeTextArea.setText(output);
    }
    
    private int calculateAverage(){
        // calculate and return the answer
    }
    
    private int calculateMaximum(){
        // calculate and return the answer
        int maximum = 0;
        for (Integer currentMark: marks){
            if (currentMark > maximum){
                maximum = currentMark;
            }
        }
        return maximum;
    }
    
    private int calcualteMinimum(){
        // calculate and return the answer
    }
    
    private int calculateRange(){
        // calculate and return the answer
    }
    

    Now, these are my main changes, and why I made them…

    1. I added a actionPerformed() method. If you don’t have this already, it allows you to listen for button clicks. You need to add a line myButton.addActionListener(this); for each of your buttons. You’ll probably also need to change your public class MyClass line to say public class MyClass implements ActionListener, and add a line import java.awt.event.*
    2. I changed your analyzeButtonActionPerformed() method so that it outputs the values you requested. Now you need to implement the calculate() methods at the end – I have done one of them for you to give you the general idea. When you click the analyze button, it should do all the 4 calculations and put the answers in the textarea.

    Why don’t you have a bit of a look at my changes, and see whether you can see what they’re supposed to be doing. Have a go at implementing some of the changes, and the calculate methods, and see if you can get it working. Don’t just copy-paste my answer – make some changes bit-by-bit to see how it all works, and fix any compilation errors as they appear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have make a messaging system in which user can send messages to each
Using this sample : I have make my own Fragment that holds tabhost and
I have to make a graphical user interface application using the language of my
To make my program a bit more user friendly and easy to update, when
I have a bit of a problem where my check marks that i apply
For an assignment at school, we have to use structs to make matrices that
I have a program that generates a plain text file. The structure (layout) is
Hey there, I have dynamic question marks on my landing page that scroll with
I have some code that iterates through files in a directory and does useful
I have the following lines in my ~/.emacs.d/init.el (custom-set-variables '(flymake-allowed-file-name-masks (quote ( (\\.cc\\' flymake-simple-make-init)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.