Connecting Tech Pros Worldwide Forums | Help | Site Map

Java problem... subclass to superclass

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
Hi guys, i'm stuck on this problem. only just recently started coding java using blue J. Can you guys help me.
import java.util.*;
------------------------------------------------------------------------------------------
public class Player
{
// the Player class has four fields
private int goals;
private int height;
private String name;
private int dateofbirth;
private int yob;
private int mob;
private int d;


// the Bicycle class has one constructor
public Player (String fullname, int playerheight, int date, int dd, int mm, int yyyy ) {
height = playerheight;
goals = 0;
name = fullname;
dateofbirth= date;
d= dd;
mob= mm;
yob= yyyy;



}

// the Bicycle class has four methods
public void addgoals(int addgoals) {
goals += addgoals;
}




public int getheight() {

return height;
}

public String getname() {
return name;
}
public int getgoals()
{
return goals;
}
public float getdob() {
return dateofbirth;
}

//private String paddedName(){
//if(name.length()>20){
//return name.substring (0,19);
//}
//else{
//int spaceregd= 20 - name.length ();
//for (int i =0, i < spaceregd; i++)

//paddedname=Paddedname +"";

//}
public String getAge()
{

Calendar now = Calendar.getInstance();
int year=now.get(Calendar.YEAR);
int mon = now.get(Calendar.MONTH);
int day = now.get(Calendar.DAY_OF_MONTH);

now.set(year,mon,day);

long nowinday = now.getTimeInMillis()/86400000;

Calendar DOB = Calendar.getInstance();

DOB.set(yob,d,mob);
long dobinday = DOB.getTimeInMillis()/86400000;


long spanofday = nowinday - dobinday;

int years = (int)(spanofday / 365);
int rem = (int)(spanofday % 365);

int month = (rem / 30);
rem = (rem % 30);

// float age= + years + + month + + rem +;
//return age;


String age = "The age is " + years + " years " + month + " months and " + rem + " days";
return age;
}
}
------------------------------------------------------------------------------------
second class -


public class Keeper extends Player {

// the MountainBike subclass adds one field
public int cleansheets;

// the MountainBike subclass has one constructor
public Keeper(int numberofcleansheets,String fullname, int playerheight, float date) {
super (fullname, playerheight, date);
cleansheets = numberofcleansheets;
}

// the MountainBike subclass adds one method
public void addcleansheets(int addcleansheets) {
cleansheets += addcleansheets;
}

public int getcleansheets(){
return cleansheets;

}
}
-----------------------------------------------------------------------------
the problem is, the subclass (keeper) won't compile coz it says it cant find the Player Class. I think its something wrong with the player class but i'm not sure!. the exact error says- Cannot find sysmbol- Contructor Player (java.lang.String, int, float). any one have any suggestions? deadline is 2mro! lol THANKS!! ignore the comments by the way!!! the ones where it says bicycle etc
best answer - posted by pbrockway2
It's the signature of the constructor that the compiler is telling you about. You say

Expand|Select|Wrap|Line Numbers
  1. super (fullname, playerheight, date);
  2.  
so the compiler goes looking for a constructor in the Player class that has three arguments. But it can't find one! The only constructor needs 6 arguments.

Newbie
 
Join Date: Nov 2007
Posts: 31
#2: 4 Weeks Ago

re: Java problem... subclass to superclass


It's the signature of the constructor that the compiler is telling you about. You say

Expand|Select|Wrap|Line Numbers
  1. super (fullname, playerheight, date);
  2.  
so the compiler goes looking for a constructor in the Player class that has three arguments. But it can't find one! The only constructor needs 6 arguments.
Reply