Student in Java need help with "cannot be applied error
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Student in Java need help with "cannot be applied error
I have set my constructors without agruments and I am seeing this error, which is pertaining to those arguments. Why.
Must have constructor with arguments and without in class
import java.util.Scanner;
public class Player
{
/***************************************instance variables*/
private int id;
private String playerName;
private String team;
private String position;
private double salary, commissionRate;
/******************************************utility variables*/
Scanner input = new Scanner(System.in);
/***************************************constructors*/
public Player()
{
setID();
setPlayerName();
setTeam();
setPosition();
setSalary();
setCommissionRate();
}
public Player(int id, String playerName, String team, String position, double salary, double commissionRate)
{
this.id = id;
this.playerName = playerName;
this.team = team;
this.position = position;
this.salary= salary;
this.commissionRate = commissionRate;
}
/***************************************mutators*/
public void SetId()
{
System.out.print("Please enter id: ");
id = input.nextInt();
input.nextLine();
}
public void setId(int id)
{ this.id = id;}
public void SetPlayerName()
{
System.out.print("Please enter name of player: ");
playerName = input.nextLine();
}
public void setName(String playerName)
{ this.playerName = playerName; }
public void SetTeam()
{
System.out.print("Please enter team: ");
team = input.nextLine();
}
public void setTeam(String team)
{ this.team = team; }
public void SetPosition()
{
System.out.print("Please enter player's position: ");
position = input.nextLine();
}
public void setPosition(String position)
{ this.position = position; }
public void SetSalary()
{
System.out.print("Please enter player's salary: ");
salary = input.nextDouble();
input.nextLine();
}
public void setSalary(double salary)
{ this.salary = salary; }
public void SetCommissionRate()
{
System.out.print("Please enter commission rate of player: ");
commissionRate = input.nextDouble();
input.nextLine();
}
public void setCommissionRate(double commissionRate)
{ this.commissionRate = commissionRate; }
/***************************************accessors*/
public int getId()
{ return id; }
public String getPlayerName()
{ return playerName; }
public String getTeam()
{ return team; }
public String getPosition()
{ return position; }
public double getSalary()
{ return salary; }
public double getCommissionRate()
{ return commissionRate; }
/***************************************effectors*/
public double calcCommission()
{
double commission = salary * commissionRate;
return commission;
}
}//end of Player class
//6 errors on compile, this class will be extended to 3 other classes. I am a new to java, were I have set constructors with no arguments is where i get 6 errors. Says SetID() cannot be applied to () SetID(); and so on for each one. My other question is my assignment says to overload the mutators to include methods with and without prompts, can't I apply these to my child classes or do I need include them in this for this class is the parent.
public class Player
{
/***************************************instance variables*/
private int id;
private String playerName;
private String team;
private String position;
private double salary, commissionRate;
/******************************************utility variables*/
Scanner input = new Scanner(System.in);
/***************************************constructors*/
public Player()
{
setID();
setPlayerName();
setTeam();
setPosition();
setSalary();
setCommissionRate();
}
public Player(int id, String playerName, String team, String position, double salary, double commissionRate)
{
this.id = id;
this.playerName = playerName;
this.team = team;
this.position = position;
this.salary= salary;
this.commissionRate = commissionRate;
}
/***************************************mutators*/
public void SetId()
{
System.out.print("Please enter id: ");
id = input.nextInt();
input.nextLine();
}
public void setId(int id)
{ this.id = id;}
public void SetPlayerName()
{
System.out.print("Please enter name of player: ");
playerName = input.nextLine();
}
public void setName(String playerName)
{ this.playerName = playerName; }
public void SetTeam()
{
System.out.print("Please enter team: ");
team = input.nextLine();
}
public void setTeam(String team)
{ this.team = team; }
public void SetPosition()
{
System.out.print("Please enter player's position: ");
position = input.nextLine();
}
public void setPosition(String position)
{ this.position = position; }
public void SetSalary()
{
System.out.print("Please enter player's salary: ");
salary = input.nextDouble();
input.nextLine();
}
public void setSalary(double salary)
{ this.salary = salary; }
public void SetCommissionRate()
{
System.out.print("Please enter commission rate of player: ");
commissionRate = input.nextDouble();
input.nextLine();
}
public void setCommissionRate(double commissionRate)
{ this.commissionRate = commissionRate; }
/***************************************accessors*/
public int getId()
{ return id; }
public String getPlayerName()
{ return playerName; }
public String getTeam()
{ return team; }
public String getPosition()
{ return position; }
public double getSalary()
{ return salary; }
public double getCommissionRate()
{ return commissionRate; }
/***************************************effectors*/
public double calcCommission()
{
double commission = salary * commissionRate;
return commission;
}
}//end of Player class
//6 errors on compile, this class will be extended to 3 other classes. I am a new to java, were I have set constructors with no arguments is where i get 6 errors. Says SetID() cannot be applied to () SetID(); and so on for each one. My other question is my assignment says to overload the mutators to include methods with and without prompts, can't I apply these to my child classes or do I need include them in this for this class is the parent.
- Nicholas Jordan
- Posts: 124
- Joined: Mon Dec 20, 2004 12:33 am
- Location: Central Texas ISO Latin-1
- Contact:
looking at your header: Must have constructor with arguments and without in class and explanatory remark about constructors - taken in conjunction with using some high-level interface ( those are notorious for generating errors for beginners ) - you have a default constructor (which is what a constructors with no arguments is usually called - thought you can call it a constructor taking no arguments) ~ and Scanner does not show a SetID() in the docs: there is void remove() then it goes to skip(Pattern pattern)
Void is another name for argument list that has no arguments, also commonly called a Void datatype, which Javists will likely tell you there is no such thing as a void type in Java while they talk about void parameter lists. Perhaps they have had too much coffee.
You are obviously using some high-level tool or development kit; what is it and does it have a button or command marked 'clean' - if it does, try that once. Scanner is a class that will read files one line at a time. Do you mean by "I am a new to java" that you have no prior programming ? Where is this set ID coming from ? Is this a Bean development kit ?
Void is another name for argument list that has no arguments, also commonly called a Void datatype, which Javists will likely tell you there is no such thing as a void type in Java while they talk about void parameter lists. Perhaps they have had too much coffee.
You are obviously using some high-level tool or development kit; what is it and does it have a button or command marked 'clean' - if it does, try that once. Scanner is a class that will read files one line at a time. Do you mean by "I am a new to java" that you have no prior programming ? Where is this set ID coming from ? Is this a Bean development kit ?