Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Creating an array of objects

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Thanked 0 Times in 0 Posts

    Cool Creating an array of objects

    Hi, for a homework assignment I need to create a program that keeps track of the bowling scores of a number of players. I have the user enter the number of players, and then an array of objects is created with enough indexes for each player. Then I have the user enter a name for each player in a for loop, where I want to create an object for each player name. From what I've seen on other websites what I'm doing should work...but it's not! any help would be greatly appreciated, thanks.

    package chap7ex7;
    import java.util.Scanner;
    public class Chap7ex7 {
    public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          System.out.println("-- Bowling Scorekeeper --\n");
          System.out.println("How many players are playing?");
          int players = input.nextInt();
          bowlingclass names[] = new bowlingclass[players];
          System.out.println("Enter the name of each player.");
          String name;
          for (int i = 0; i < players; i++){
              name = input.nextLine();               //enter player name
              names[i] = new bowlingclass(name);   //I get an error: constructor bowling calss in class bowlingclass cannot be applied to given types
                                                   //required: no arguments  found:String reason: actual and formal arugments lists differ in length

    in my class I have:
    package chap7ex7;
    public class bowlingclass {
       String name;
        public void bowlingclass(String name){
            this.name = name;

  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    My Mood
    Thanked 93 Times in 86 Posts

    Default Re: Creating an array of objects

    public void bowlingclass(String name) is not a constructor. Remove the void.

  3. The Following User Says Thank You to PhHein For This Useful Post:

    Benner (March 22nd, 2013)

Similar Threads

  1. Creating Objects at specified indexes
    By dougie1809 in forum Object Oriented Programming
    Replies: 4
    Last Post: March 1st, 2013, 08:20 PM
  2. creating Frame objects in an Applet
    By vk2goh in forum AWT / Java Swing
    Replies: 1
    Last Post: May 30th, 2012, 07:04 AM
  3. Creating random objects
    By JackCannon15 in forum Object Oriented Programming
    Replies: 2
    Last Post: November 18th, 2011, 08:50 AM
  4. Creating array from generic type objects?
    By AndrewMiller in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 13th, 2010, 09:22 PM
  5. Loop not creating objects
    By xecure in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 30th, 2010, 10:48 PM