[Đề TH]Bài tập về ThreadCollection

saint

Member
19/3/12
113
3
18
Anh em gắng đọc hiểu nhé, dễ mà, không khó đâu:

Practice [15]
A. Create Class Book . [1]
a. Class Book has a String field named bookCd a double field price.
b. Build get/set properties and contructor has parameter corresponding to the field above.
c. Overriding toString() method to display information of current student in form : "Book has code is :… price is:….."

B. Create a multi Threads java application using wait–notify mechanism to do the following task:
- Thread1 :
o Using Scanner to input some Book [2]
§ The first you must input Book code
§ Book code valid has form below:
· abbbb
· Wherein : [1]
o a is a charater
o b is a number in range 0-9
· Example:
o C1009 is valid
o T0812 valid
o C10030 is not valid
o CC1103 is not valid
§ A valid book code will be used to create a new book object (using contructor has tow parameter and using Math.random to create a price for this book) and then add this book to a collection named validCode using generic type is Book type, and then switch immediately to do tasks in Thread2. [1]


§ An invalid book code will be added continuously into another collection named invalidCode using generic type is java.lang.String type, and then switch immediately to do tasks in Thread3. [1]
§ validCode and invalidCode collections were defined in DataShare class which is used for multi threads can manipulate simultaneously on it’s data. [3]

- Thread2 :
Immediately after one book was added into the validCode collection.
o Thread2 get this book and using toString() method to display information of this book. [3]

- Thread3:
Immediately after one element was added into the invalidCode collection.
o Thread3 get it and display to screen a message like :
§ "Invalid code is :…" [3]