fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. MiniDate birthDate = new MiniDate( 1967 , 1 , 23 );
  13. MiniDate hireDate = new MiniDate( 2016 , 2 , 28 );
  14. Employee e1 = new Employee( "Wendy" , "Melvoin" , birthDate , hireDate );
  15. System.out.println( e1 );
  16.  
  17. Employee e2 = new Employee( "Lisa" , "Coleman" , 1968 , 2 , 24 , 2016 , 4 , 14 );
  18. System.out.println( e2 );
  19.  
  20. // FYI: In real work, use the existing `LocalDate` class rather than invent your own date-time class.
  21. // LocalDate birthDate = LocalDate.of( 1967 , 1 , 23 );
  22. }
  23. }
  24.  
  25. class Employee {
  26. private String firstName , lastName ;
  27. private MiniDate birthDate , hireDate ;
  28.  
  29. public Employee( String firstNameArg , String lastNameArg , MiniDate birthDateArg , MiniDate hireDateArg ) {
  30. this.firstName = firstNameArg;
  31. this.lastName = lastNameArg;
  32. this.birthDate = birthDateArg;
  33. this.hireDate = hireDateArg;
  34. }
  35.  
  36. public Employee( String firstNameArg , String lastNameArg , int birthYearArg , int birthMonthArg , int birthDayOfMonthArg , int hireYearArg , int hireMonthArg , int hireDayOfMonthArg ) {
  37. this.firstName = firstNameArg;
  38. this.lastName = lastNameArg;
  39. this.birthDate = new MiniDate( birthYearArg , birthMonthArg , birthDayOfMonthArg );
  40. this.hireDate = new MiniDate( hireYearArg , hireMonthArg , hireDayOfMonthArg );
  41. }
  42.  
  43. @Override
  44. public String toString() {
  45. String s = "Employee{ name: " + this.firstName + " " + this.lastName + " | birthDate: " + this.birthDate + " | hireDate: " + hireDate + " }" ;
  46. return s;
  47. }
  48. }
  49.  
  50. class MiniDate {
  51. // For teaching purposes only. In real work, use `LocalDate` class bundled with Java.
  52. private int year , month , dayOfMonth ;
  53.  
  54. public MiniDate( int yearArg , int monthArg , int dayOfMonthArg ) {
  55. this.year = yearArg;
  56. this.month = monthArg;
  57. this.dayOfMonth = dayOfMonthArg;
  58. }
  59.  
  60. @Override
  61. public String toString() {
  62. // Generate string in standard ISO 8601 format, padding with zeros as needed.
  63. String s = this.year + "-" + String.format( "%02d", this.month ) + "-" + String.format( "%02d", this.dayOfMonth ) ;
  64. return s ;
  65. }
  66. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Employee{ name: Wendy Melvoin | birthDate: 1967-01-23 | hireDate: 2016-02-28 }
Employee{ name: Lisa Coleman | birthDate: 1968-02-24 | hireDate: 2016-04-14 }