FE1.2 Lab

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

//tester

public class BookTester {

// main method
public static void main(String[] args) {

// create a object of Book class and print it


Book b1 = new Book("Clark Den","C# object oriented programming
Language",24,8,2015,"Apress",23,"California","USA");

System.out.println("\nBook 1 : \n"+b1);

Book b2 = new Book("Abhinav Bindra","DSA in JAVA",23,2,2016,"Cpress",13,"Los


Angles","USA");

System.out.println("\nBook 2 : \n"+b2);

}
}

// class named Date


class Date{

// instance variables

private int day;


private int month;
private int year;

// constructor

public Date(int day, int month, int year) {

// initialize instance variables


this.day = day;
this.month = month;
this.year = year;

// get year that returns year


public int getyear() {

return year;

// return monthname

public String convertMonth() {

String months[] =
{"","January","February","March","April","May","June","July","August","September","
October","November","December"};

return months[month];
}

// return details of Date

public String toString() {

return convertMonth().substring(0, 3)+" "+year;

//class named Address


class Address{

// instance variables

private int num;


private String city;
private String country;

// constructor

public Address(int num,String city, String country){

// initialize instance variables


this.city = city;
this.country = country;

// return details of Address

public String toString() {

return city+", "+country+".";

// class named Publisher


class Publisher{

// instance variables

private String name;


private Address address;

// constructor

public Publisher(String name, Address address) {

// initialize instance variables

this.name = name;
this.address = address;

// return details of Publisher

public String toString() {

return name+", "+address;

// class named BOOK


class Book{

// instance variables

private String author;


private String title;
private Date pubDate;
private Publisher publisher;

// constructor

public Book(String author, String title, int day, int month, int year, String
pubname, int number, String city, String country ){

// initialize instance variables

this.author = author;

this.title = title;

Date date = new Date(day,month,year);

this.pubDate = date;

Address add = new Address(number,city,country);

Publisher pub = new Publisher(pubname, add);


this.publisher = pub;

// return details of Book

public String toString() {

return author+", "+title+", "+publisher+" "+pubDate;

// check checkBookAge
public int checkBookAge() {

// if book is 3 years old then return 1

if(pubDate.getyear() < 2019) {

return 1;

// else return 0

else {

return 0;

You might also like