0% found this document useful (0 votes)
10 views3 pages

Extra Inheritance

Uploaded by

ht79247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Extra Inheritance

Uploaded by

ht79247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise 1:

Create a package called “PkgBasic” to contains all classes

1. Create a class Book. It includes some fields:


Private String Code;
Private String Title and some methods:
And some methods: constructors , getter,setter, inputBook, outputBook
Validate: Code has format: Bx , x belong to[0-9]
2. Create a class DetectiveBook ( This class is derived from Book class).
It extends some fileds: private int price,
Private int yearofpublication.
Validation: price>=0, yearofpublication>=’1/1/2000’ and <= current Date
And some methods: constructors, getter,setter , inputDetective, outputDetective

Create other package called PkgView. It contains two classes:

1. Create a class AnimeBook(This class is derived from Book class)

It extends a fleld: private String publisher.

Validation: publisher matches a format: only contains letters and spaces, publisher’s length from 1
to 20 chars.

And some methods: constructors,getters,setters, inputAnimeBook, outputAnimeBook.

2. Create a class called KidBook (This class is derived from Detective class)
It extends some fields: private int age, private String gender
Validation: age >=3 and age <=16; gender is “female” or “male”
3. Create a class BookStore. It contains the main method.
When the program runs, it shows a menu:
1. Create a new book
2. Display the book
3. Update the book
4. Exit
When user choosea the option 1. The program displays a submenu:
1. Create a Detective book
2. Create a Anime Book
3. Create a Kid Book
4. Back the main menu

When user chooses the option 2. The program will display the accepted book

When user chooses the option 3. User can update the book’s fields. If user accepts a empty
string for the field the the program keeps the old value of it.
For example:

1. Create a new book


2. Display the book
3. Update the book
4. Exit

Please accept a choice: 1

1. Create a Detective book


2. Create a Anime Book
3. Create a Kid Book
4. Back the main menu
Please accept a choice: 2
Code?: B1
Title?: Harry Poster
Publisher?: VietNam

1. Create a Detective book


2. Create a Anime Book
3. Create a Kid Book
4. Back the main menu
Please accept a choice: 4

1. Create a new book


2. Display the book
3. Update the book
4. Exit
Please accept a choice: 2
Code?: B2
Title?: “Chu Cuoi”
Publisher?: // type enter, user does not input

1. Create a new book


2. Display the book
3. Update the book
4. Exit
Please accept a choice: 3
Code: B2
Title: chu cuoi
Publish: VietNam

You might also like