Results 1 to 3 of 3
  1. #1
    loddog2002 is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default Cannot figure out min and max, without using arrays. if possible.

    here is my code. it is due at midnight tonight. i have been working on this final part for a long time PLEASE, PLEASE HELP

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;

    public class TestScores
    {
    public static void main(String args[])
    {
    //create an instance of the JFrame
    JFrame frame = new TestScoresFrame();

    //make the JFrame visible
    frame.setVisible(true);




    }//end main()
    }//end FutureValueFrameApp class



    class TestScoresFrame extends JFrame
    {


    //the FutureValueFrame() constructor sets the properties for the frame...must have the same name as the class and must be public and there is no rturn datatype
    public TestScoresFrame()
    {
    setTitle("Encore Movies");
    setSize(250, 210);
    setResizable(false);
    //another way to center the app
    //setLocationRelativeTo(null);
    centerWindow(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new TestScoresPanel();
    add(panel);
    }//end FutureValueFrame() constuctor


    private void centerWindow(Window w)
    {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    setLocation((d.width - w.getWidth()) / 2, (d.height - w.getHeight()) /2);
    }//end centerWindow()

    }// end FutureValueFrame class


    class TestScoresPanel extends JPanel implements ActionListener
    {
    //declare variables
    private JButton calculateButton, resetButton, exitButton;
    private JTextField scoreField, numberField, averageField, bestField, worstField;
    private JLabel scoreLabel, numberLabel, averageLabel, bestLabel, worstLabel;
    int i = 0;
    double total = 0;
    double scores = 0;
    double average = 0;

    public TestScoresPanel()
    {
    //set the latour for the panel
    setLayout(new BorderLayout());

    //display panel
    JPanel displayPanel = new JPanel();
    displayPanel.setLayout (new FlowLayout(FlowLayout.CENTER));

    scoreLabel = new JLabel("Enter Score: ");
    displayPanel.add(scoreLabel);

    scoreField = new JTextField(10);
    displayPanel.add(scoreField);

    numberLabel = new JLabel("Number of Scores: ");
    displayPanel.add(numberLabel);

    numberField = new JTextField(10);
    numberField.setEditable(false);
    numberField.setFocusable(false);
    displayPanel.add(numberField);

    averageLabel = new JLabel("Average Score: ");
    displayPanel.add(averageLabel);

    averageField = new JTextField(10);
    averageField.setEditable(false);
    averageField.setFocusable(false);
    displayPanel.add(averageField);

    bestLabel = new JLabel("Best Score: ");
    displayPanel.add(bestLabel);

    bestField = new JTextField(10);
    bestField.setEditable(false);
    bestField.setFocusable(false);
    displayPanel.add(bestField);

    worstLabel = new JLabel("Worst Score: ");
    displayPanel.add(worstLabel);

    worstField = new JTextField(10);
    worstField.setEditable(false);
    worstField.setFocusable(false);
    displayPanel.add(worstField);

    //button panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

    calculateButton = new JButton("Enter Score:");
    calculateButton.addActionListener(this);
    buttonPanel.add(calculateButton);

    resetButton = new JButton("Reset");
    resetButton.addActionListener(this);
    buttonPanel.add(resetButton);

    exitButton = new JButton("Exit");
    exitButton.addActionListener(this);
    buttonPanel.add(exitButton);

    //add panels to the main panel
    add(buttonPanel, BorderLayout.SOUTH);
    add(displayPanel,BorderLayout.CENTER);

    }//end FutureValuePanel() constructor

    //actionPerformed() is excecuted every time the user clicks one of the buttons,...this tells the buttons what to do
    public void actionPerformed(ActionEvent e)
    {


    //determined what was clicked
    Object source = e.getSource();
    if(source == exitButton)
    System.exit(0);

    else if(source == calculateButton)
    {
    int scores = Integer.parseInt(scoreField.getText());

    i += 1;
    total += scores;

    double average = total / i;

    String averageString = Double.toString(average);
    String iString = Integer.toString(i);


    averageField.setText(averageString);
    numberField.setText(iString);


    scoreField.requestFocus();
    scoreField.selectAll();


    }//end else if
    else if(source == resetButton)
    {
    double average = 0;
    i = 0;

    total = 0;
    scoreField.setText("");
    numberField.setText("");
    averageField.setText("");
    bestField.setText("");
    worstField.setText("");
    scoreField.requestFocus();

    }//end else if
    }//end actionPerformed()
    }//end FutureValuePanel class

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    1) Please post formatted code that is enclosed in code tags, else it isn't readable. To do this, place [code] above your formatted code and the tag [/code] below your code.
    2) Please ask a specific question. "Cannot figure out..." and "please, please help" are not very specific. Where exactly is your problem? What code is bombing? What have you tried? How has it failed?
    3) Regarding
    it is due at midnight tonight.
    Please understand that your urgency isn't our urgency. This will statement will not help you get help and may have the opposite effect.

    Good luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    To do a best and best and worst score, you need bestScore and worstScore variables and need to set these equal to the first score entered. Then whenever a score is entered, compare the newly entered score with these variables and act accordingly. The trick of course is you have to know when the first score is being entered. A boolean state variable "firstScore" would help here. It is true to start with (or when reset is pressed) and then set to false after the first score has been entered and the hi score and low score have been initialized to this first score. Good luck.

Similar Threads

  1. [SOLVED] Can't figure out what's wrong
    By roach_van in forum New To Java
    Replies: 10
    Last Post: 09-05-2008, 07:09 AM
  2. Replies: 2
    Last Post: 07-11-2008, 09:41 AM
  3. Replies: 3
    Last Post: 12-25-2007, 04:10 AM
  4. Seems so simple yet I can't figure it out!
    By adamhaviland in forum New To Java
    Replies: 1
    Last Post: 11-03-2007, 06:26 PM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 04:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •