-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4a9abc
commit fd0c68e
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import java.util.Date; | ||
import java.util.Scanner; | ||
import java.text.*; | ||
import java.util.Calendar; | ||
|
||
public class Book | ||
{ | ||
private int id; | ||
private String title; | ||
private String author; | ||
private Date dateOfPublication; | ||
|
||
public static final String DATE_FORMAT = "dd.MM.yyyy"; | ||
|
||
|
||
public int age() | ||
{ | ||
Calendar cal = Calendar.getInstance(); | ||
Date today = cal.getTime(); | ||
|
||
|
||
//publishing date | ||
Date bookdate = cal.getTime(); | ||
|
||
long dateSubstract = today.getTime() - bookdate.getTime(); | ||
long time = 1000 * 60 * 60 * 24; | ||
|
||
long ageDays = dateSubstract/time; | ||
System.out.println(ageDays); | ||
|
||
|
||
//make long to int | ||
int ageDaysInt = (int) ageDays; | ||
|
||
return ageDaysInt; | ||
|
||
|
||
} | ||
|
||
/////////////////////////////////////////////////////////////////////// | ||
|
||
public void setId(int id) | ||
{this.id = id;} | ||
public int getId() | ||
{return id;} | ||
|
||
public void setTitle(String title) | ||
{this.title = title;} | ||
public String getTitle() | ||
{return title;} | ||
|
||
public void setAuthor(String author) | ||
{this.author = author;} | ||
public String getAuthor() | ||
{return author;} | ||
|
||
public void setDateOfPublication(Date dateOfPublication) | ||
{this.dateOfPublication = dateOfPublication;} | ||
public Date getDateOfPublication() | ||
{return dateOfPublication;} | ||
|
||
|
||
|
||
|
||
////////////////////////////////////////////////////////////////////////// | ||
public String toString() | ||
{ | ||
//convert id to string and put everything together | ||
|
||
|
||
String newDate = dateToString(DateOfPublication); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
public void input() | ||
{ | ||
Scanner scn = new Scanner( System.in ); | ||
System.out.print( "Please enter id: " ); | ||
//int | ||
|
||
System.out.println("Please enter title: "); | ||
//string | ||
|
||
System.out.println("Please enter author: "); | ||
//string | ||
|
||
System.out.println("Please enter date of publication: "); | ||
//date | ||
} | ||
|
||
public static String dateToString( Date d ) //done | ||
{ | ||
SimpleDateFormat fmt = new SimpleDateFormat( DATE_FORMAT ); | ||
return fmt.format( d ); | ||
} | ||
|
||
|
||
|
||
public static Date stringToDate( String s ) //done | ||
{ | ||
Date r = null; | ||
try { | ||
SimpleDateFormat fmt = new SimpleDateFormat( DATE_FORMAT ); | ||
r = fmt.parse( s ); | ||
} catch ( ParseException e ){ | ||
System.err.println( e ); | ||
System.exit(1); | ||
} | ||
return r; | ||
} | ||
|
||
|
||
|
||
|
||
} |