Ex 3
Ex 3
Ex 3
- Create a new folder that is named with the following format: studentID-studentname-
workshopNumber. The folder contains 4 projects: Q1,Q2,Q3,Q4,….
Example: se18123-nguyenvana-WS01 or SE12123-nguyen van a-WS01
- Use jdk 1.8
- The result must be formated like the given tesstcase
- Submit your result to the LMS page( example : se18123-nguyenvana-WS01.zip)
1. Create a class Book. It includes some fields: Code, Title and some methods: constructors,
getter,setter and the method output().
2. Create a class DetectiveBook ( This class is derived/extends from Book class).
It extends some fileds: price,year of publication.
And some methods: constructors, getter, setter and the method outputDetectiveBook()
3. Create a class ScienceBook ( This class is derived from Book class).
It extends some fileds: type, (physical, mathematic, chemistry)
And some methods: constructors, getter,setter and the method outputScienceBook()
4. A class Tester which contains the main method(). When the program runs, it displays a menu:
1. Create and display a Detective Book
2. Create and display a Science Book
TC1:
Enter option: 1
enter code: 123
enter title: han va yeu
enter price: 100
enter year:2000
OUTPUT:
123-han va yeu-100-2000
TC2:
Enter option: 1
enter code: 123
enter title: han va yeu
enter type: physical
OUTPUT:
123-han va yeu-physical
Q2: Create a new project named “Q2”. Write a class Rectangle, and Square that extends the Rectangle
class(in the default package) with the following information:
Rectangle
- length:int
- width:int
+ Rectangle()
+ setLength(length: int):void
+ setWidth(width:int):void
+ getLength():int
+ getWidth():int
Square Where:
Square (side): assign the given side to two fields (length, width), assign
- unit: String the default value is ’cm’ to the unit field.
+ Square (side: int) setSquare(side): if the given side is the positive number then assign it to
+ setSquare(side: int):void the length, width fields
+ getPerimeter(): int getPerimeter(): return the perimeter of the square
+ output(): void output(): display the content with format :
the side of the square=length(unit)
the perimeter of the square=(length+width)*2(unit)
for example:
Enter the side of the square:5 Enter the side of the square:-1
OUTPUT: OUTPUT: