Exercises OOP EN
Exercises OOP EN
Exercises OOP EN
Guideline: The output method of the student object prints information on a format
line.
- Using System.out.printf(“Format String”, param 1, param 2, ....);
- Format String is the same C++
Example:
“%-30s”: String, 30 characters, the minus sign is left-aligned.
“%5.2f” : real numbers, 5 characters, include 2 odd digits.
Format characters:
s : String
d: Integer number (byte, short, int, long)
f: real number (float, double)
b: boolean
Note: Each operation must check whether the amount of deposit, withdrawal and
transfer is valid or not? (For example: the money entered <0, the money
withdrawn more than the money in the account, the notice is invalid and requires
re-entry)
Lesson 7.
a. Writing a Student object development program includes the following
attributes:
+ Student code: an integer
+ Full name: a string
+ Address: a string
+ Phone number: a string contains 10 characters
- Private declaration attributes, define get / set methods for each attribute.
- Write constructors to initialize objects (default constructor, constructor with
parameters).
- Override the toString method of Object class.
b. Build class that allows to import N students (using array/arraylist). Export the
list to the screen in ascending order of student code.
Lesson 8.
a. Write a CD object builder program that includes the following properties:
+ CD code is integer number,
+ Title CD: string,
+ Singer: string,
+ Song number: integer (> 0)
+ Cost: real number (> 0)
- Private declaration attributes, define get / set methods for each attribute.
- Write constructors to initialize CD objects.
- Override the toString method of Object class.
b. Build class to save the list of CDs (using array).
- Method of adding a CD to the list.
- The total cost of CDs.
- The method of arranging lists decreases with price.
- The method of arranging the list gradually increases according to CD.
- Method of exporting the entire list.
c. Write class for testing.
Lesson 2. Library X manages the list of books. Information about book types:
* Textbook: Book code, date of entry (day, month, year), unit price, quantity,
publisher, status (new, old).
If the book status is new: then money = quantity * unit price.
If the book status is old, then money: = quantity * unit price * 50%
* Reference book: Book code, date of entry (day, month, year), unit price,
quantity, publisher, tax. Amount = quantity * unit price + tax
Perform the following requirements:
- Build classes with inheritance functions.
- Import export list of book types.
- Calculate the sum of money for each type.
- Calculate the average of the unit price of the reference books.
- Export textbooks of publisher X.
Lesson 6. A XYZ hotel needs to manage the bills of rented guests. Invoice has
2 types: hourly bill, daily invoice. General information of invoice details is: Invoice
code, invoice date (date, month, year), Customer name, room code, unit price.
Individual information for each type of invoice includes:
Hourly bills also include the number of hours rented.
Amount = number of hours rent * unit price.
- If the number of hours is> 24 hours and <30 hours, it is only 24
hours.
- If the number of hours is> 30 hours, do not use an hourly invoice.
The daily invoice will have the number of days of hire. Money = number of
days of rent * unit price. If the number of days> 7, reduce 20% of the unit
price for the remaining days.
Management requirements:
- Information on each type of vehicle.
- Calculate the tax for each vehicle based on the vehicle value as follows:
+ Bicycle: No tax.
+ Motorbike: VAT = 10% and registration tax of 5%.
+ Passenger cars: Special consumption tax of 30% (number of seats>
= 5); 50% (number of seats <5), VAT = 10%, registration tax of 20%.
+ Truck: VAT = 10%, registration tax of 2%.
+ Other vehicles, VAT = 10%, no registration tax.
Request students:
- Using knowledge of data modeling in object-oriented programming to
build classes.
- Using a CASE tool (Computer Aided Software Engineering) to design
hierarchical tree model of classes. The relationship between classes and
interfaces.
- Generate source code from the above model into the Java programming
language.
- Realize the program.
Lesson 10. Human Information class: includes attributes, name and address
input methods, address entry.
- Classes of Students, Staff, Customers (described below) inherit the
Human Information class.
- Student class: includes the subjects of the subject 1, subject 2, and the
method:
+ Entering scores
+ Calculating the total points
+ The method of changing the information of students to pass
parameters as students (communication variable).
+ The method to choose the way to change:
- 0: change the subject points 1.
- 1: change the subject points 2.
(the points of the subjects are entered from the keyboard).
- Employee class: including attributes salary and position, and methods
+ Entering position, salary
+ Changing information of employees into parameters as employees,
+ Choosing the way change
- 0: change of salary
- 1: change of position
(information is entered from the keyboard).
- Customer class: includes sales model attributes, and billing methods.
* Define the upper classes and the Information Display class.
* The Information Display class allows declaring objects of the Private class,
expressing polymorphism by allowing the choice of entering information as
students, employees or customers.
Lesson 12.
- Create a class abstract with 3 abstract methods draw (), erase (), and move (int
x, int y).
- Create subclasses as listed in the table below and override (abstract) the
abstract methods, these methods print the message to the console.
Lesson 7. Write a phone book search program, using any collection structure to
match the information of your contacts and easily do the job:
- Search by address.
- Look up by phone number, 1 address can register many fixed phone numbers.
IV. I/O
Lesson 1. Write a program to enter a string and print the inverse string of the
input string (Using BufferedReade and InputStreamReader).
Lesson 2. Display the content of a file named test.txt saved at D: test.txt Use
BufferedInputStream to read the file.
Lesson 3. Copy the content of a text file to another text file. (Use
BufferedInputStream / BufferedOutputStream Or use FileInputStream /
FileOutputStream)
Lesson 5. List the subdirectories and files of a directory. If the folder, display
<DIR> in front of the name.
Lesson 9. Use BufferedReader to read the string from the Console. The program
that ends when the read string is encountered is the "stop" string.
Lesson 10. Define students' information storage layer. Allow to import student
data and store into data.dat file. Read data from file, put in array and display
result. Student information includes the code, full name, address, phone number
and GPA of the last school year.