Question

Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here is an example of the screenshot when ru
Tony Parker T. Splitter T. Duncan M. Gineb Player Kame: M Ginobil Player Age 2 Add A Player Ce An example of the JFrame subcl
JLabel ll-new JLabel(Player Name:): tutName new JTextField(); tutName.setPreferredSize(new Dimension(12024) JLabel 12-new J
frame.setSize(800, 400): frame.setVisible(true
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi. I have answered this question before. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Only attached NBATeam.java and NBAcourtPanel.java files. The driver file NBAPlayoff.java is not modified, hence not attached to save space.

// NBATeam.java

import java.util.ArrayList;

public class NBATeam {

      //team name

      private String teamName;

      //lists to store names and ages

      private ArrayList<String> names;

      private ArrayList<Integer> ages;

     

      //constructor

      public NBATeam(String teamName) {

            this.teamName = teamName;

            //initializing lists

            names = new ArrayList<String>();

            ages = new ArrayList<Integer>();

      }

     

      //adds a player to the team

      public void addAPlayer(String name, int age) {

            if (names.size() == 5) {

                  return; // not allowing more than 5 people at a time.

            }

            names.add(name);

            ages.add(age);

      }

     

      //returns the maximum age

      public int getMaxAge() {

            int max = 0;

            for (int i = 0; i < ages.size(); i++) {

                  //first value or value > max

                  if (i == 0 || ages.get(i) > max) {

                        //setting current age as max

                        max = ages.get(i);

                  }

            }

            return max;

      }

     

      //returns the minimum age

      public int getMinAge() {

            int min = 0;

            for (int i = 0; i < ages.size(); i++) {

                  if (i == 0 || ages.get(i) < min) {

                        min = ages.get(i);

                  }

            }

            return min;

      }

     

      //returns the average age as an integer

      public int getAvgAge() {

            int sum = 0;

            //finding sum of ages

            for (int i = 0; i < ages.size(); i++) {

                  sum += ages.get(i);

            }

            //finding and returning the average

            int avg = sum / ages.size();

            return avg;

      }

     

      //returns the number of players

      public int getNumOfPlayer() {

            return names.size();

      }

     

      //returns the list containing player names

      public ArrayList<String> getNames() {

            return names;

      }

}

// NBAcourtPanel.java

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import javax.swing.JPanel;

public class NBAcourtPanel extends JPanel {

      private NBATeam team;

      // constuctor taking an NBATeam parameter

      public NBAcourtPanel(NBATeam team) {

            this.team = team;

      }

      @Override

      protected void paintComponent(Graphics g) {

            super.paintComponent(g);

            // using yellowish orange color

            g.setColor(new Color(255, 200, 0));

            // filling the entire panel

            g.fillRect(0, 0, getWidth(), getHeight());

            // finding radius of center red circle

            int radius = getWidth() / 8;

            g.setColor(Color.RED); // using red color

            // filling the circle at the center

            g.fillOval(getWidth() / 2 - radius, getHeight() / 2 - radius,

                        radius * 2, radius * 2);

            // using white color

            g.setColor(Color.WHITE);

            // finding x radius and y radius of the semi ellipses in left and right

            // sides

            int radiusX = getWidth() / 4;

            int radiusY = getHeight() / 3;

            // drawing ellipse on the left

            g.drawOval(-radiusX, getHeight() / 2 - radiusY, radiusX * 2,

                        radiusY * 2);

            // drawing ellipse on the right

            g.drawOval(getWidth() - radiusX, getHeight() / 2 - radiusY,

                        radiusX * 2, radiusY * 2);

            // drawing line passing through center

            g.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight());

            // using black color

            g.setColor(Color.black);

            g.setFont(new Font("default", Font.BOLD, 16));

            // finding the starting x,y position of first name

            // note: you may adjust the coordinates as you see fit according to your

            // system.

            int x = getWidth() - radiusX + radiusX / 4;

            int y = getHeight() / 2 - radiusY + radiusY / 2;

            // looping through each player name and drawing them

            for (String name : team.getNames()) {

                  g.drawString(name, x, y);

                  y += 20;

            }

      }

}

/*OUTPUT*/


- O X Number of Players: Max Age: 29 Tony Parker William M. James T Kevin Robert Barry O.R Min Age: 21 Average Age: 25 Player

Add a comment
Know the answer?
Add Answer to:
Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • With the Code below, how would i add a "Back" Button to the bottom of the...

    With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...

  • tart from the following code, and add Action Listener to make it functional to do the...

    tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) {     JFrame frame = new temperatureConverter();     frame.setTitle("Temp");     frame.setSize(200, 100);     frame.setLocationRelativeTo(null);     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setVisible(true); }    public temperatureConverter() {     JLabel lblC = new...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show...

    In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...

  • Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10...

    Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off.   Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...

  • Please design a Java GUI application with two JTextField for user to enter the first name...

    Please design a Java GUI application with two JTextField for user to enter the first name and last name. Add two JButtons with action events so when user click on one button to generate a full name message from the user input and put it in a third JTextField which is not editable; and click on the other button to clear all three JTextField boxes. Please run the attached nameFrame.class file (Note: because there is an actionhandler inner class in...

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT