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

  • Home
  • SEARCH
  • 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 6631031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:29:27+00:00 2026-05-25T22:29:27+00:00

this is my first post on this web site, so please be patience :)

  • 0

this is my first post on this web site, so please be patience 🙂
I’m studying java and I’m trying to create a small program that storage in two arrays the name of player and the attendance of them. I’m using JOptionPane for the ‘user interface’. I would like, when the user ask for, to show the names and the respective attendance of them.
Here it’s my code(it’s not completed):

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

public class Pelada{
    public static void main(String []args){
        String[] players = new String[10];
    int[] attendance = new int[10];
    int x = 0, z = 0, control = 0, posPlayer = 0;
    String test;

    while(control != 4){
        control = Integer.parseInt(JOptionPane.showInputDialog(null,"1- Add       new players \n 2- List \n 3- Increment attendance \n 4- Delete player \n 4- Exit", "Choose an option below", JOptionPane.INFORMATION_MESSAGE));
            if(control == 1){
                players[x] = JOptionPane.showInputDialog(null, "New player: ", "Add New Player", JOptionPane.INFORMATION_MESSAGE);
                attendance[x] = Integer.parseInt(JOptionPane.showInputDialog(null, "How many matchs have he played so far? ", "Attendance", JOptionPane.INFORMATION_MESSAGE));
                x++;
            }   
            else if(control == 2)
                    for (int i=0; i < players.length; i++){
                    JOptionPane.showMessageDialog(null, "Attendance = " + attendance[i], "N: " + i + "- " + players[i], JOptionPane.WARNING_MESSAGE);       
                    }
                else if(control == 3){
                        posPlayer = Integer.parseInt(JOptionPane.showInputDialog(null, "Choose the player id: ", "Player Id", JOptionPane.INFORMATION_MESSAGE));
                        attendance[posPlayer] = Integer.parseInt(JOptionPane.showInputDialog(null, "Increment ", "Attendance", JOptionPane.INFORMATION_MESSAGE));
                    }                   
    }

}

}

  • 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-05-25T22:29:28+00:00Added an answer on May 25, 2026 at 10:29 pm

    Instead of having two arrays; one for players and one for attendance, make your code more object-oriented by creating a Player class encapsulating the name and attendance of a player:

    public class Player {
        private final String name;
        private final int attendance;
    
        public Player(String name, int attendance) {
            this.name = name;
            this.attendance = attendance;
        }
    
        public String getName() {
            return name;
        }
    
        public int getAttendance() {
            return attendance;
        }
    }
    

    Then create Player objects and store them in an ArrayList. Don’t use an array unless you know how many players are going to be added.

    List<Player> players = new ArrayList<Player>();
    
    if (control == 1) {
         String name = JOptionPane.showInputDialog(null, "New player: ", "Add New Player",
                 JOptionPane.INFORMATION_MESSAGE);
         int attendance = Integer.parseInt(JOptionPane.showInputDialog(null,
                 "How many matchs have he played so far? ", "Attendance", JOptionPane.INFORMATION_MESSAGE));
         Player player = new Player(name, attendance);
         players.add(player);
    
    } else if (control == 2) {
        for (int i = 0; i < players.size(); i++) {
            Player player = players.get(i);
            JOptionPane.showMessageDialog(null, "Attendance = " + player.getAttendance(), "N: " + i + "- " + player.getName(),
                    JOptionPane.WARNING_MESSAGE);
        }                
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post on Stack, so please bear with me if I
Well, this is my first post here and really enjoying the site. I have
I am trying to create a web page using php. The problem is that
For Starters, i would like to note, that this is my first post on
This is my first post after being a long-time lurker - so please be
this is my first post on this website, but I'm all the time getting
This is my first post here and I wanted to get some input from
This is my first post and I'm quite a novice on C++ and compiling
This is my first post on Stack Overflow and I'm just wondering on the
This is my first post here. I have a problem. I need to take

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.