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.

Recommended Answers

All 2 Replies

Date was badly designed in version 1 of Java because it didn't cope with multiple time zones or calendars. For most purposes it was replaced by the abstract Calendar class. That was designed to have concrete subclasses for different calendars (eg Jewish), but you will probably want the subclass GregorianCalendar that handles western European-type dates. So if you want to deal with days/weeks/months etc use GregorianCalendar.

ps: More than a decade later people have collected quite long list of things they don't like about Calendar either, so Java 8 (released earlier this week!) has a completely new API for dates and times that is quite brilliant. However, for your purposes it's probably too soon to jump to a Java 8 solution.

and the library has major flaws in that it's very hard to use, and has no way to rapidly (if at all) convert to and from the old Date logic.

It's simply Joda time bolted on to the core libraries, and just changing the package names and license statements in the sources took them years...
Used it in the past, it needs dozens of lines of code to simply convert a java.util.Date into a joda Date or back, and in any real application you need to do that all the time because you're interfacing with existing libraries, databases, etc. etc. etc.

IOW just another "me2" "feature" added for little other reason than to provide someone with the right to say he wrote a JSR.

For a while I was part of the team, they refused to even consider adding methods to convert to and from the existing API, not because it can't be done (it would have been easy), but because they "didn't want to pollute the API with code dealing with it", in other words for religious/political reasons.

And for some reason they explicitly added Muslim and Chinese calendar support, but not Jewish calendar support...
More political/religious bigotry at work where none should exist.

No, it's a massively bloated monstrosity that has no place in a well defined API.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.