-1

I'm a student in java and have a question on how to create an object with attributes in an array. so this is my empty constructor and constructor with variables to set the attributes

public class Punt {
    private int x;
    private int y;

    public void Punt(){

    }

    public void Punt(int x, int y){
        this.x = x;
        this.y = y;
    }     
}

Then i need to make an array of creating objects with x,y and i got this

public class Punten {
    private int[] punten = {new Punt(3, 4),
        new Punt(5, 12),
        new Punt(7, 24),
        new Punt(9, 40),
        new Punt(11, 60),
        new Punt(13, 84)
};

The error is Punt() in Punt cannot be applied to ( int, int) The red line is under the two ints

Thanks in advance for your time

Johan
  • 3,577
  • 1
  • 14
  • 28

1 Answers1

0
  1. A constructor does not have a return type, so remove void from your 2 constructors

    public Punt(){
    }
    public void Punt(int x, int y){
        this.x = x;
        this.y = y;
    } 
    
  2. You are instanciating an array of Punt element, not of ints so

    private Punt[]
    
azro
  • 53,056
  • 7
  • 34
  • 70