HElp with compiler error

import javax.swing.*;

public class CyMember
{
private String name;
private long phone;
private int courses[]; //Data Attributes

public CyMember() //The empty Constructor
{
name= "Cymember name";
phone=0;
courses= new int [5];
}

public CyMember(String n,long p,int [] toSet)
{
setName(n);
setPhone(p);
setCourses(toSet[]);
}

public CyMember(String n,long p,int a, int b, int c,int d,int e)
{
setName(n);
setPhone(p);
setCourses(toSet[a+b+c+d+e]);
}

public void setCourses(int toSet [])
{
for (int i=0; iExit code: 1

Comments

  • Syntax errors:

    [code]
    public CyMember(String n, long p, int[] toSet) {
    setName(n);
    setPhone(p);
    setCourses(toSet); //was setCourses(toSet[]);
    }
    [/code]

    [code]
    public CyMember(String n, long p, int a, int b, int c, int d, int e) {
    int[] toSet = new int[] {
    a, b, c, d, e
    };
    setName(n);
    setPhone(p);
    setCourses(toSet); //was setCourses(toSet[a + b + c + d + e]);
    }
    [/code]

    Also, you're going to get a NullPointerException when you try to use setCourses(int[]) - the member reference variable courses is only initialized in the no-args constructor, which may not be called.

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion