Hi all
I am writing a java program to display the dob of sportsperson, now I have use the java.util.Date to display the date on to the consloe. But since it is deprecated I wish to use some other method to get and display the date from the user. Here is my code.
package com.MyExampleProject;
import java.util.Date;
class playerDetails{
String name;
Date dob;
int totalMatchesPlayed;
/*int highestRunsScored;
int noOfTons;
int noOfFifties;*/
String position;
String country;
playerDetails (String name, Date dob, int totalMatchesPlayed,String position,String country){
this.name = name;
this.dob = dob;
this.totalMatchesPlayed = totalMatchesPlayed;
/*this.highestRunsScored = highestRunsScored;
this.noOfTons = noOfTons;
this.noOfFifties = noOfFifties;*/
this.position = position;
this.country = country;
}
public void displayPlayerDetails(){
System.out.println("Player's name: "+name+"\nPlayer's DOB: "+dob+"\nTotal Matches Played: "+totalMatchesPlayed+"\nPosition : "+position+"\nFrom : "+country);
System.out.println("--------------------------------------");
}
}
class cricketPlayer extends playerDetails {
int totalRunsScored;
int noOfFifties;
int noOfTons;
int noOfWickets
cricketPlayer(String name, Date DOB, int totalMatchesPlayed,String position, int totalRunsScored,int noOfFifties, int noOfTons, int noOfWickets,String country){
super(name,DOB,totalMatchesPlayed,position,country);
this.totalRunsScored = totalRunsScored;
this.noOfFifties = noOfFifties;
this.noOfTons = noOfTons;
this.noOfWickets = noOfWickets;
}
public void displayPlayerDetails(){
// super(displayPlayerDetails);
super.displayPlayerDetails();
System.out.println("Cricket player's details is listed below");
System.out.println("--------------------------------------");
System.out.println("Total Runs Scored: "+totalRunsScored+"\nTotal No of Fifites Scored: "+noOfFifties+"\nTotal number of hundreds: "+noOfTons+"\nTotal Wickets: "+noOfWickets);
System.out.println("--------------------------------------");
}
}
class footBallPlayer extends playerDetails {
int totalNoOfGoals;
int totalLeagues;
String team;
footBallPlayer(String name, Date dob, int totalMatchesPlayed,String position,int totalNoOfGoals, int totalLeagues,String country,String team ){
super(name,dob,totalMatchesPlayed,position,country);
this.totalNoOfGoals = totalNoOfGoals;
this.totalLeagues = totalLeagues;
this.team = team;
}
public void displayPlayerDetails(){
super.displayPlayerDetails();
System.out.println("Football player's details is listed below");
System.out.println("--------------------------------------");
System.out.println("Total No of goals: "+totalNoOfGoals+"\nTotal Leagues: "+totalLeagues+"\nBelongs to the team: "+team);
System.out.println("--------------------------------------");
}
}
class hockeyPlayer extends playerDetails {
int noOfGoals;
String team;
hockeyPlayer(String name, Date dob, int totalMatchesPlayed,String position,String country,int noOfGoals,String team){
super(name,dob,totalMatchesPlayed,position,country);
this.noOfGoals = noOfGoals;
this.team = team;
}
public void displayPlayerDetails(){
super.displayPlayerDetails();
System.out.println("Hockey Player's details is listed below:");
System.out.println("--------------------------------------");
System.out.println("Total Number of Goals: "+noOfGoals+"\nPlays for the team: "+team);
System.out.println("--------------------------------------");
}
}
public class Team {
public static void main(String args[]){
cricketPlayer cricketPlayer = new cricketPlayer("Sachin Tendulkar",new Date(88,01,03),1000,"Batsman",5000,100,100,50,"India");
footBallPlayer footBallPlayer = new footBallPlayer("Ronaldo", new Date(88,01,02),150,"Striker",150,10,"Brazil","Data Not Available");
hockeyPlayer hockeyPlayer = new hockeyPlayer("Someone",new Date(88,01,03),10,"Goal Keeper","India",0,"WB");//WB - West Bengal
cricketPlayer.displayPlayerDetails();
footBallPlayer.displayPlayerDetails();
hockeyPlayer.displayPlayerDetails();
}
}
Can someone please help me? Please refer to the lines 86-88.